Class KubernetesUtils
java.lang.Object
io.micronaut.kubernetes.util.KubernetesUtils
Utility class with methods to help with ConfigMaps and Secrets.
- Since:
- 1.0.0
- Author:
- Álvaro Sánchez-Mariscal
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcomputeLabelSelector(Map<String, String> labels) Creates a label selector filter based on the passed labels.computePodLabels(io.micronaut.kubernetes.client.reactor.CoreV1ApiReactorClient client, List<String> podLabelKeys, String namespace, Map<String, String> labels, boolean exceptionOnPodLabelsMissing) Creates a label map from pod and passed labels.static reactor.core.publisher.Mono<String> computePodLabelSelector(io.micronaut.kubernetes.client.reactor.CoreV1ApiReactorClient client, List<String> podLabelKeys, String namespace, Map<String, String> labels, boolean exceptionOnPodLabelsMissing) Creates a label selector filter from pod and passed labels.configMapAsMap(io.kubernetes.client.openapi.models.V1ConfigMap configMap, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders) Converts aV1ConfigMapinto aMap.static io.micronaut.context.env.PropertySourceconfigMapAsPropertySource(io.kubernetes.client.openapi.models.V1ConfigMap configMap, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders) Converts aV1ConfigMapinto aPropertySource.static List<io.micronaut.context.env.PropertySource> configMapAsPropertySource(String mountPoint, Map<String, String> data, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders) Converts config map mounted as volume into aPropertySource.static StringcreatePropertySourceName(String filePath, Class<? extends io.kubernetes.client.common.KubernetesObject> type) Creates a property source name from given file path.static StringcreateResVersionPropertyName(io.kubernetes.client.common.KubernetesObject kubernetesObject) Creates a property name for property which contains resource version of given kubernetes object.static Predicate<io.kubernetes.client.common.KubernetesObject> getExcludesFilter(Collection<String> excludes) static Predicate<io.kubernetes.client.common.KubernetesObject> getIncludesFilter(Collection<String> includes) static Predicate<io.kubernetes.client.common.KubernetesObject> getLabelsFilter(Map<String, String> labels) static StringobjectNameOrNull(io.kubernetes.client.common.KubernetesObject kubernetesObject) parseLabels(String labelsValue, String provider) secretAsMap(io.kubernetes.client.openapi.models.V1Secret secret) Converts aV1Secretinto aMap.static io.micronaut.context.env.PropertySourcesecretAsPropertySource(io.kubernetes.client.openapi.models.V1Secret secret) Converts aV1Secretinto aPropertySource.
-
Field Details
-
ENV_KUBERNETES_SERVICE_HOST
- See Also:
-
API_PROPERTY_SOURCE_PRIORITY
public static final int API_PROPERTY_SOURCE_PRIORITY- See Also:
-
-
Constructor Details
-
KubernetesUtils
public KubernetesUtils()
-
-
Method Details
-
createResVersionPropertyName
public static String createResVersionPropertyName(io.kubernetes.client.common.KubernetesObject kubernetesObject) Creates a property name for property which contains resource version of given kubernetes object.- Parameters:
kubernetesObject- the kubernetes object- Returns:
- property name
-
createPropertySourceName
-
configMapAsMap
public static Map<String,Object> configMapAsMap(io.kubernetes.client.openapi.models.V1ConfigMap configMap, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders) Converts aV1ConfigMapinto aMap.- Parameters:
configMap- theV1ConfigMapinstancepropertySourceLoaders- the collection of property source loaders- Returns:
Mapinstance
-
configMapAsPropertySource
public static io.micronaut.context.env.PropertySource configMapAsPropertySource(io.kubernetes.client.openapi.models.V1ConfigMap configMap, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders) Converts aV1ConfigMapinto aPropertySource.- Parameters:
configMap- theV1ConfigMapinstancepropertySourceLoaders- the collection of property source loaders- Returns:
PropertySourceinstance
-
configMapAsPropertySource
public static List<io.micronaut.context.env.PropertySource> configMapAsPropertySource(String mountPoint, Map<String, String> data, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders) Converts config map mounted as volume into aPropertySource.- Parameters:
mountPoint- the mount pointdata- the configmaps data in the mounted volume where keys are file names and values is the file contentpropertySourceLoaders- the collection of property source loaders- Returns:
- list of
PropertySourceinstances
-
secretAsMap
-
secretAsPropertySource
public static io.micronaut.context.env.PropertySource secretAsPropertySource(io.kubernetes.client.openapi.models.V1Secret secret) Converts aV1Secretinto aPropertySource.- Parameters:
secret- theV1Secretinstance- Returns:
PropertySourceinstance
-
getIncludesFilter
public static Predicate<io.kubernetes.client.common.KubernetesObject> getIncludesFilter(Collection<String> includes) - Parameters:
includes- the objects to include- Returns:
- a
Predicatebased on a collection of object names to include
-
getExcludesFilter
public static Predicate<io.kubernetes.client.common.KubernetesObject> getExcludesFilter(Collection<String> excludes) - Parameters:
excludes- the objects to excludes- Returns:
- a
Predicatebased on a collection of object names to excludes
-
getLabelsFilter
-
objectNameOrNull
public static String objectNameOrNull(io.kubernetes.client.common.KubernetesObject kubernetesObject) -
computePodLabelSelector
public static reactor.core.publisher.Mono<String> computePodLabelSelector(io.micronaut.kubernetes.client.reactor.CoreV1ApiReactorClient client, List<String> podLabelKeys, String namespace, Map<String, String> labels, boolean exceptionOnPodLabelsMissing) Creates a label selector filter from pod and passed labels.- Parameters:
client- the clientpodLabelKeys- the list of label keys inside a podnamespace- the namespacelabels- the additional labelsexceptionOnPodLabelsMissing- should an exception be thrown if configured pod label key is not found in pod labels- Returns:
- the label selector filter
-
computePodLabels
public static @NonNull reactor.core.publisher.Mono<Map<String,String>> computePodLabels(io.micronaut.kubernetes.client.reactor.CoreV1ApiReactorClient client, List<String> podLabelKeys, String namespace, Map<String, String> labels, boolean exceptionOnPodLabelsMissing) Creates a label map from pod and passed labels.- Parameters:
client- the clientpodLabelKeys- the list of label keys inside a podnamespace- the namespacelabels- the additional labelsexceptionOnPodLabelsMissing- should an exception be thrown if configured pod label key is not found in pod labels- Returns:
- the computed labels
-
parseLabels
-
computeLabelSelector
-