Class KubernetesUtils

java.lang.Object
io.micronaut.kubernetes.util.KubernetesUtils

public class KubernetesUtils extends Object
Utility class with methods to help with ConfigMaps and Secrets.
Since:
1.0.0
Author:
Álvaro Sánchez-Mariscal
  • Field Details

  • Constructor Details

    • KubernetesUtils

      public KubernetesUtils()
  • Method Details

    • configMapAsPropertySource

      public static io.micronaut.context.env.PropertySource configMapAsPropertySource(io.kubernetes.client.openapi.models.V1ConfigMap configMap)
      Converts a V1ConfigMap into a PropertySource.
      Parameters:
      configMap - the ConfigMap
      Returns:
      A PropertySource
    • configMapAsPropertySource

      public static List<io.micronaut.context.env.PropertySource> configMapAsPropertySource(String mountPoint, Map<String,String> data)
      Converts config map mounted as volume into property sources.
      Parameters:
      mountPoint - the mount point
      data - the configmaps data in the mounted volume where keys are file names and values is the file content
      Returns:
      list of property sources
    • computeLabelSelector

      public static String computeLabelSelector(Map<String,String> labels)
      Determines the value of a Kubernetes labelSelector filter based on the passed labels.
      Parameters:
      labels - the labels
      Returns:
      the value of the labelSelector filter
    • secretAsPropertySource

      public static io.micronaut.context.env.PropertySource secretAsPropertySource(io.kubernetes.client.openapi.models.V1Secret secret)
      Parameters:
      secret - The V1Secret to transform
      Returns:
      The converted PropertySource.
    • getIncludesFilter

      public static Predicate<io.kubernetes.client.common.KubernetesObject> getIncludesFilter(Collection<String> includes)
      Parameters:
      includes - the objects to include
      Returns:
      a Predicate based 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 Predicate based on a collection of object names to excludes
    • getLabelsFilter

      public static Predicate<io.kubernetes.client.common.KubernetesObject> getLabelsFilter(Map<String,String> labels)
      Parameters:
      labels - the labels to include
      Returns:
      a Predicate based on labels the kubernetes objects has to match to return true
    • 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)
      Parameters:
      client - the CoreV1ApiReactorClient
      podLabelKeys - the list of labels inside a pod
      namespace - in the configuration
      labels - the labels
      exceptionOnPodLabelsMissing - should and exception be thrown if configured pod label is not found
      Returns:
      the filtered labels of the current pod