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

    • 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

      public static String createPropertySourceName(String filePath, Class<? extends io.kubernetes.client.common.KubernetesObject> type)
      Creates a property source name from given file path.
      Parameters:
      filePath - the file path
      type - the kubernetes type
      Returns:
      property source name
    • configMapAsMap

      public static Map<String,Object> configMapAsMap(io.kubernetes.client.openapi.models.V1ConfigMap configMap, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders)
      Converts a V1ConfigMap into a Map.
      Parameters:
      configMap - the V1ConfigMap instance
      propertySourceLoaders - the collection of property source loaders
      Returns:
      Map instance
    • configMapAsPropertySource

      public static io.micronaut.context.env.PropertySource configMapAsPropertySource(io.kubernetes.client.openapi.models.V1ConfigMap configMap, Collection<io.micronaut.context.env.PropertySourceLoader> propertySourceLoaders)
      Converts a V1ConfigMap into a PropertySource.
      Parameters:
      configMap - the V1ConfigMap instance
      propertySourceLoaders - the collection of property source loaders
      Returns:
      PropertySource instance
    • 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 a PropertySource.
      Parameters:
      mountPoint - the mount point
      data - the configmaps data in the mounted volume where keys are file names and values is the file content
      propertySourceLoaders - the collection of property source loaders
      Returns:
      list of PropertySource instances
    • secretAsMap

      public static Map<String,Object> secretAsMap(io.kubernetes.client.openapi.models.V1Secret secret)
      Converts a V1Secret into a Map.
      Parameters:
      secret - the V1Secret instance
      Returns:
      Map instance
    • secretAsPropertySource

      public static io.micronaut.context.env.PropertySource secretAsPropertySource(io.kubernetes.client.openapi.models.V1Secret secret)
      Converts a V1Secret into a PropertySource.
      Parameters:
      secret - the V1Secret instance
      Returns:
      PropertySource instance
    • 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)
      Creates a label selector filter from pod and passed labels.
      Parameters:
      client - the client
      podLabelKeys - the list of label keys inside a pod
      namespace - the namespace
      labels - the additional labels
      exceptionOnPodLabelsMissing - 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 client
      podLabelKeys - the list of label keys inside a pod
      namespace - the namespace
      labels - the additional labels
      exceptionOnPodLabelsMissing - should an exception be thrown if configured pod label key is not found in pod labels
      Returns:
      the computed labels
    • parseLabels

      public static @Nullable Map<String,String> parseLabels(String labelsValue, String provider)
    • computeLabelSelector

      public static String computeLabelSelector(Map<String,String> labels)
      Creates a label selector filter based on the passed labels.
      Parameters:
      labels - the map of labels
      Returns:
      the label selector filter