Class KubernetesResourceUtil
- java.lang.Object
-
- io.fabric8.kubernetes.client.utils.KubernetesResourceUtil
-
public class KubernetesResourceUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
KUBERNETES_DNS1123_LABEL_MAX_LENGTH
static Pattern
KUBERNETES_DNS1123_LABEL_REGEX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<io.fabric8.kubernetes.api.model.EnvVar>
convertMapToEnvVarList(Map<String,String> envVarMap)
protected static String
getAdditionalPropertyText(Map<String,Object> additionalProperties, String name)
Used to get additional properties from Object's metadatastatic Duration
getAge(io.fabric8.kubernetes.api.model.HasMetadata kubernetesResource)
Calculates age of a kubernetes resourcestatic io.fabric8.kubernetes.api.model.OwnerReference
getControllerUid(io.fabric8.kubernetes.api.model.HasMetadata resource)
static String
getKind(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns the kind of the entitystatic Map<String,String>
getLabels(io.fabric8.kubernetes.api.model.ObjectMeta metadata)
Returns the labels of the given metadata object or an empty map if the metadata or labels are nullstatic String
getName(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns name of the resource from it's Metadatastatic String
getName(io.fabric8.kubernetes.api.model.ObjectMeta entity)
Returns name of the resource from it's Metadatastatic String
getNamespace(io.fabric8.kubernetes.api.model.HasMetadata entity)
Getting namespace from Kubernetes Resourcestatic String
getNamespace(io.fabric8.kubernetes.api.model.ObjectMeta entity)
Null safe get operation for getting namespace from Kubernetes Resource's MetaDatastatic Map<String,String>
getOrCreateAnnotations(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe get for fetching annotations from MetaData of Kubernetes Resourcestatic Map<String,String>
getOrCreateLabels(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe get method for getting Labels of a Kubernetes Resourcestatic io.fabric8.kubernetes.api.model.ObjectMeta
getOrCreateMetadata(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe operation for getting Metadata of a Kubernetes resourcestatic String
getQualifiedName(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns Qualified name for the specified Kubernetes Resourcestatic String
getResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns the resource version for the entity or null if it does not have onestatic boolean
hasController(io.fabric8.kubernetes.api.model.HasMetadata resource)
Checks whether the resource has some controller(parent) or not.static boolean
hasResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns true if this entity has a valid non blank resourceVersion in its metadatastatic <T extends io.fabric8.kubernetes.api.model.HasMetadata>
Class<? extends io.fabric8.kubernetes.api.model.KubernetesResourceList>inferListType(Class<T> type)
static boolean
isResourceReady(io.fabric8.kubernetes.api.model.HasMetadata item)
Check whether a Kubernetes resource is Ready or not.static boolean
isValidLabelOrAnnotation(Map<String,String> map)
Validates labels/annotations of Kubernetes resourcesstatic boolean
isValidName(String name)
Validates name of Kubernetes Resource name, label or annotation based on Kubernetes regexstatic String
sanitizeName(String name)
Returns an identifier from the given string that can be used as resource name.static void
setResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity, String resourceVersion)
Set resource version of a kubernetes resourcestatic void
sortEventListBasedOnTimestamp(List<io.fabric8.kubernetes.api.model.Event> eventList)
-
-
-
Field Detail
-
KUBERNETES_DNS1123_LABEL_REGEX
public static final Pattern KUBERNETES_DNS1123_LABEL_REGEX
-
KUBERNETES_DNS1123_LABEL_MAX_LENGTH
public static final int KUBERNETES_DNS1123_LABEL_MAX_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
getResourceVersion
public static String getResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns the resource version for the entity or null if it does not have one- Parameters:
entity
- entity provided- Returns:
- returns resource version of provided entity
-
setResourceVersion
public static void setResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity, String resourceVersion)
Set resource version of a kubernetes resource- Parameters:
entity
- entity providedresourceVersion
- updated resource version
-
getKind
public static String getKind(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns the kind of the entity- Parameters:
entity
- provided entity- Returns:
- returns kind of entity provided
-
getQualifiedName
public static String getQualifiedName(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns Qualified name for the specified Kubernetes Resource- Parameters:
entity
- Kubernetes resource- Returns:
- returns qualified name
-
getName
public static String getName(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns name of the resource from it's Metadata- Parameters:
entity
- Kubernetes resource- Returns:
- returns name of resource
-
hasResourceVersion
public static boolean hasResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns true if this entity has a valid non blank resourceVersion in its metadata- Parameters:
entity
- entity provided- Returns:
- returns a boolean value indicating whether it has a valid non blank resourceVersion
-
getName
public static String getName(io.fabric8.kubernetes.api.model.ObjectMeta entity)
Returns name of the resource from it's Metadata- Parameters:
entity
- MetaData of kubernetes resource- Returns:
- returns name of resource
-
getAdditionalPropertyText
protected static String getAdditionalPropertyText(Map<String,Object> additionalProperties, String name)
Used to get additional properties from Object's metadata- Parameters:
additionalProperties
- additional propertiesname
- name of resource- Returns:
- returns additional property text
-
getNamespace
public static String getNamespace(io.fabric8.kubernetes.api.model.ObjectMeta entity)
Null safe get operation for getting namespace from Kubernetes Resource's MetaData- Parameters:
entity
- Kubernetes Resource- Returns:
- returns namespace as plain string
-
getNamespace
public static String getNamespace(io.fabric8.kubernetes.api.model.HasMetadata entity)
Getting namespace from Kubernetes Resource- Parameters:
entity
- Kubernetes Resource- Returns:
- returns namespace as plain string
-
getOrCreateAnnotations
public static Map<String,String> getOrCreateAnnotations(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe get for fetching annotations from MetaData of Kubernetes Resource- Parameters:
entity
- Kubernetes resource- Returns:
- returns a hashmap containing annotations
-
sanitizeName
public static String sanitizeName(String name)
Returns an identifier from the given string that can be used as resource name.- Parameters:
name
- which needs to be sanitized- Returns:
- sanitized name
-
getOrCreateLabels
public static Map<String,String> getOrCreateLabels(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe get method for getting Labels of a Kubernetes Resource- Parameters:
entity
- Kubernetes Resource- Returns:
- returns a hashmap containing labels
-
getLabels
public static Map<String,String> getLabels(io.fabric8.kubernetes.api.model.ObjectMeta metadata)
Returns the labels of the given metadata object or an empty map if the metadata or labels are null- Parameters:
metadata
- ObjectMeta for resource's metadata- Returns:
- returns labels as a hashmap
-
getOrCreateMetadata
public static io.fabric8.kubernetes.api.model.ObjectMeta getOrCreateMetadata(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe operation for getting Metadata of a Kubernetes resource- Parameters:
entity
- Kubernetes Resource- Returns:
- returns ObjectMeta as metadata
-
isValidName
public static boolean isValidName(String name)
Validates name of Kubernetes Resource name, label or annotation based on Kubernetes regex- Parameters:
name
- Name of resource/label/annotation- Returns:
- returns a boolean value indicating whether it's valid or not
-
isValidLabelOrAnnotation
public static boolean isValidLabelOrAnnotation(Map<String,String> map)
Validates labels/annotations of Kubernetes resources- Parameters:
map
- Label/Annotation of resource- Returns:
- returns a boolean value inidicating whether it's valid or not
-
hasController
public static boolean hasController(io.fabric8.kubernetes.api.model.HasMetadata resource)
Checks whether the resource has some controller(parent) or not.- Parameters:
resource
- resource- Returns:
- boolean value indicating whether it's a child or not.
-
getControllerUid
public static io.fabric8.kubernetes.api.model.OwnerReference getControllerUid(io.fabric8.kubernetes.api.model.HasMetadata resource)
-
sortEventListBasedOnTimestamp
public static void sortEventListBasedOnTimestamp(List<io.fabric8.kubernetes.api.model.Event> eventList)
-
convertMapToEnvVarList
public static List<io.fabric8.kubernetes.api.model.EnvVar> convertMapToEnvVarList(Map<String,String> envVarMap)
-
isResourceReady
public static boolean isResourceReady(io.fabric8.kubernetes.api.model.HasMetadata item)
Check whether a Kubernetes resource is Ready or not. Applicable only to Deployment, ReplicaSet, Pod, ReplicationController, Endpoints, Node and StatefulSet- Parameters:
item
- item which needs to be checked- Returns:
- boolean value indicating it's status
-
getAge
public static Duration getAge(io.fabric8.kubernetes.api.model.HasMetadata kubernetesResource)
Calculates age of a kubernetes resource- Parameters:
kubernetesResource
-- Returns:
- a positive duration indicating age of the kubernetes resource
-
-