public class KubernetesResourceUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Pattern |
KUBERNETES_DNS1123_LABEL_REGEX |
static Pattern |
KUBERNETES_KEY_REGEX |
static Pattern |
KUBERNETES_SUBDOMAIN_REGEX |
Modifier and Type | Method and Description |
---|---|
static io.fabric8.kubernetes.api.model.ConfigMapBuilder |
addEntriesFromDirOrFileToConfigMap(io.fabric8.kubernetes.api.model.ConfigMapBuilder configMapBuilder,
String key,
Path dirOrFilePath) |
static boolean |
areAnnotationsValid(Map<String,String> map)
Checks the given map keys validity as annotations.
|
static boolean |
areLabelsValid(Map<String,String> map)
Checks the given map keys and values for validity as labels.
|
static List<io.fabric8.kubernetes.api.model.EnvVar> |
convertMapToEnvVarList(Map<String,String> envVarMap) |
static io.fabric8.kubernetes.api.model.ConfigMap |
createConfigMapFromDirOrFiles(String name,
Path... dirOrFilePaths)
Create new ConfigMap from files/directories
|
static io.fabric8.kubernetes.api.model.Secret |
createDockerRegistrySecret(String dockerServer,
String username,
String password)
Create Secret by using username and password.
|
static io.fabric8.kubernetes.api.model.Secret |
createDockerRegistrySecret(String dockerServer,
String username,
String password,
String secretName)
Create Secret by using username,password and secretName.
|
protected static String |
getAdditionalPropertyText(Map<String,Object> additionalProperties,
String name)
Used to get additional properties from Object's metadata
|
static Duration |
getAge(io.fabric8.kubernetes.api.model.HasMetadata kubernetesResource)
Calculates age of a kubernetes resource
|
static 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 entity
|
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
|
static String |
getName(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns name of the resource from it's Metadata
|
static String |
getName(io.fabric8.kubernetes.api.model.ObjectMeta entity)
Returns name of the resource from it's Metadata
|
static String |
getNamespace(io.fabric8.kubernetes.api.model.HasMetadata entity)
Getting namespace from Kubernetes Resource
|
static String |
getNamespace(io.fabric8.kubernetes.api.model.ObjectMeta entity)
Null safe get operation for getting namespace from Kubernetes Resource's MetaData
|
static Map<String,String> |
getOrCreateAnnotations(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe get for fetching annotations from MetaData of Kubernetes Resource
|
static Map<String,String> |
getOrCreateLabels(io.fabric8.kubernetes.api.model.HasMetadata entity)
Null safe get method for getting Labels of a Kubernetes Resource
|
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
|
static String |
getQualifiedName(io.fabric8.kubernetes.api.model.HasMetadata entity)
Returns Qualified name for the specified Kubernetes Resource
|
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
|
static 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 metadata
|
static <T extends io.fabric8.kubernetes.api.model.HasMetadata,V extends io.fabric8.kubernetes.api.builder.VisitableBuilder<T,V>> |
inferBuilderType(Class<T> type) |
static <T extends io.fabric8.kubernetes.api.model.HasMetadata> |
inferListType(Class<T> type) |
static boolean |
isResourceReady(io.fabric8.kubernetes.api.model.HasMetadata item)
Deprecated.
use client.resource(item).isReady() or Readiness.getInstance().isReady(item) instead
|
static boolean |
isValidKey(String key)
Validates annotation or label key.
|
static boolean |
isValidLabelOrAnnotation(Map<String,String> map)
Deprecated.
the rules are different for label and annotation values
|
static boolean |
isValidName(String name)
Validates name of a Kubernetes Resource name, label key/value or annotation key based on RFC 1123 Label Names.
|
static boolean |
isValidSubdomainName(String name)
Validates name of an resource according to DNS Subdomain rules.
|
static String |
sanitizeName(String name)
Returns an identifier from the given string that can be used as resource, label key/value, or annotation key
in accordance to RFC 1123 Label Names.
|
static void |
setNamespace(io.fabric8.kubernetes.api.model.HasMetadata entity,
String namespace)
Set namespace of a kubernetes resource if possible
|
static void |
setResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity,
String resourceVersion)
Set resource version of a kubernetes resource
|
static void |
sortEventListBasedOnTimestamp(List<io.fabric8.kubernetes.api.model.Event> eventList) |
public static final Pattern KUBERNETES_SUBDOMAIN_REGEX
public static final Pattern KUBERNETES_DNS1123_LABEL_REGEX
public static final Pattern KUBERNETES_KEY_REGEX
public static String getResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- entity providedpublic static void setResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity, String resourceVersion)
entity
- entity providedresourceVersion
- updated resource versionpublic static void setNamespace(io.fabric8.kubernetes.api.model.HasMetadata entity, String namespace)
entity
- entity providednamespace
- the new namesapcepublic static String getKind(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- provided entitypublic static String getQualifiedName(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- Kubernetes resourcepublic static String getName(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- Kubernetes resourcepublic static boolean hasResourceVersion(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- entity providedpublic static String getName(io.fabric8.kubernetes.api.model.ObjectMeta entity)
entity
- MetaData of kubernetes resourceprotected static String getAdditionalPropertyText(Map<String,Object> additionalProperties, String name)
additionalProperties
- additional propertiesname
- name of resourcepublic static String getNamespace(io.fabric8.kubernetes.api.model.ObjectMeta entity)
entity
- Kubernetes Resourcepublic static String getNamespace(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- Kubernetes Resourcepublic static Map<String,String> getOrCreateAnnotations(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- Kubernetes resourcepublic static String sanitizeName(String name)
Note that this is more restrictive than necessary for most resources and label/annotation keys. It will truncate the name if necessary, which may affect uniqueness.
name
- which needs to be sanitizedpublic static Map<String,String> getOrCreateLabels(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- Kubernetes Resourcepublic static Map<String,String> getLabels(io.fabric8.kubernetes.api.model.ObjectMeta metadata)
metadata
- ObjectMeta for resource's metadatapublic static io.fabric8.kubernetes.api.model.ObjectMeta getOrCreateMetadata(io.fabric8.kubernetes.api.model.HasMetadata entity)
entity
- Kubernetes Resourcepublic static boolean isValidName(String name)
Note: this is more restrictive than what is allowed for annotation names or most resource names, however some resource types have additional restrictions on their names.
Refer to Kubernetes Naming Conventions
See also isValidKey(String)
and isValidSubdomainName(String)
name
- Name of resource/label/annotationpublic static boolean isValidKey(String key)
key
- the annotation or label keypublic static boolean isValidSubdomainName(String name)
Refer to Kubernetes Naming Conventions
name
- Name of annotation@Deprecated public static boolean isValidLabelOrAnnotation(Map<String,String> map)
map
- Label/Annotation of resource{@link #areAnnotationsValid(Map)}
public static boolean areLabelsValid(Map<String,String> map)
map
- labelspublic static boolean areAnnotationsValid(Map<String,String> map)
map
- annotationspublic static boolean hasController(io.fabric8.kubernetes.api.model.HasMetadata resource)
resource
- resourcepublic static io.fabric8.kubernetes.api.model.OwnerReference getControllerUid(io.fabric8.kubernetes.api.model.HasMetadata resource)
public static void sortEventListBasedOnTimestamp(List<io.fabric8.kubernetes.api.model.Event> eventList)
public static List<io.fabric8.kubernetes.api.model.EnvVar> convertMapToEnvVarList(Map<String,String> envVarMap)
@Deprecated public static boolean isResourceReady(io.fabric8.kubernetes.api.model.HasMetadata item)
item
- item which needs to be checkedpublic static Duration getAge(io.fabric8.kubernetes.api.model.HasMetadata kubernetesResource)
kubernetesResource
- public static <T extends io.fabric8.kubernetes.api.model.HasMetadata> Class<? extends io.fabric8.kubernetes.api.model.KubernetesResourceList> inferListType(Class<T> type)
public static <T extends io.fabric8.kubernetes.api.model.HasMetadata,V extends io.fabric8.kubernetes.api.builder.VisitableBuilder<T,V>> Class<V> inferBuilderType(Class<T> type)
public static io.fabric8.kubernetes.api.model.Secret createDockerRegistrySecret(String dockerServer, String username, String password)
dockerServer
- User to store key value pair for auths mapusername
- username that needs to be used during secret creationpassword
- password that needs to be used during secret creation
secret's default name : "container-image-registry-secret" is the default name for secretpublic static io.fabric8.kubernetes.api.model.Secret createDockerRegistrySecret(String dockerServer, String username, String password, String secretName)
dockerServer
- User to store key value pair for auths mapusername
- username that needs to be used during secret creationpassword
- password that needs to be used during secret creationsecretName
- secretName that needs to be used during secret creationpublic static io.fabric8.kubernetes.api.model.ConfigMap createConfigMapFromDirOrFiles(String name, Path... dirOrFilePaths) throws IOException
name
- name of Configmap to createdirOrFilePaths
- a var-arg for directory of file paths.IOException
- in case of failure while reading filepublic static io.fabric8.kubernetes.api.model.ConfigMapBuilder addEntriesFromDirOrFileToConfigMap(io.fabric8.kubernetes.api.model.ConfigMapBuilder configMapBuilder, String key, Path dirOrFilePath) throws IOException
IOException
Copyright © 2015–2024 Red Hat. All rights reserved.