Class PodTemplateUtils

java.lang.Object
org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils

public class PodTemplateUtils extends Object
  • Field Details

    • SUBSTITUTE_ENV

      public static boolean SUBSTITUTE_ENV
  • Constructor Details

    • PodTemplateUtils

      public PodTemplateUtils()
  • Method Details

    • combine

      public static ContainerTemplate combine(@CheckForNull ContainerTemplate parent, @NonNull ContainerTemplate template)
      Combines a ContainerTemplate with its parent.
      Parameters:
      parent - The parent container template (nullable).
      template - The actual container template
      Returns:
      The combined container template.
    • combine

      public static io.fabric8.kubernetes.api.model.Container combine(@CheckForNull io.fabric8.kubernetes.api.model.Container parent, @NonNull io.fabric8.kubernetes.api.model.Container template)
      Combines a Container with its parent.
      Parameters:
      parent - The parent container (nullable).
      template - The actual container
      Returns:
      The combined container.
    • combine

      public static io.fabric8.kubernetes.api.model.Pod combine(List<io.fabric8.kubernetes.api.model.Pod> pods)
      Combines all given pods together in order.
      Parameters:
      pods - the pods to combine
    • combine

      public static io.fabric8.kubernetes.api.model.Pod combine(io.fabric8.kubernetes.api.model.Pod parent, io.fabric8.kubernetes.api.model.Pod template)
      Combines a Pod with its parent.
      Parameters:
      parent - The parent Pod (nullable).
      template - The child Pod
    • combine

      public static PodTemplate combine(PodTemplate parent, PodTemplate template)
      Combines a PodTemplate with its parent.
      Parameters:
      parent - The parent container template (nullable).
      template - The actual container template
      Returns:
      The combined container template.
    • getTemplateByLabel

      @CheckForNull public static PodTemplate getTemplateByLabel(@CheckForNull Label label, Collection<PodTemplate> templates)
      Gets the PodTemplate by Label.
      Parameters:
      label - The label.
      templates - The list of all templates.
      Returns:
      The first pod template from the collection that has a matching label.
    • getTemplateByName

      public static PodTemplate getTemplateByName(@CheckForNull String name, Collection<PodTemplate> templates)
      Gets the PodTemplate by name.
      Parameters:
      name - The name.
      templates - The list of all templates.
      Returns:
      The first pod template from the collection that has a matching name.
    • substituteEnv

      @Deprecated public static String substituteEnv(String s)
      Deprecated.
      Potentially insecure; a no-op by default.
      Substitutes a placeholder with a value found in the environment.
      Parameters:
      s - The placeholder. Should be use the format: ${placeholder}.
      Returns:
      The substituted value if found, or the input value otherwise.
    • substitute

      @Deprecated public static String substitute(String s, Map<String,String> properties)
      Substitutes a placeholder with a value found in the specified map.
      Parameters:
      s - The placeholder. Should be use the format: ${placeholder}.
      properties - The map with the key value pairs to use for substitution.
      Returns:
      The substituted value if found, or the input value otherwise.
    • substitute

      @Deprecated public static String substitute(String s, Map<String,String> properties, String defaultValue)
      Deprecated.
      check if it is null or empty in the caller method, then use substitute(String,Map)
      Substitutes a placeholder with a value found in the specified map.
      Parameters:
      s - The placeholder. Should be use the format: ${placeholder}.
      properties - The map with the key value pairs to use for substitution.
      defaultValue - The default value to return if no match is found.
      Returns:
      The substituted value if found, or the default value otherwise.
    • parseFromYaml

      public static io.fabric8.kubernetes.api.model.Pod parseFromYaml(String yaml)
    • validateYamlContainerNames

      public static Collection<String> validateYamlContainerNames(List<String> yamls)
    • validateYamlContainerNames

      public static Collection<String> validateYamlContainerNames(String yaml)
    • validateContainerName

      public static boolean validateContainerName(String name)
    • validateLabel

      public static boolean validateLabel(String label)
    • validateImage

      public static boolean validateImage(String image)
      TODO perhaps enforce https://docs.docker.com/engine/reference/commandline/tag/#extended-description
    • sanitizeLabel

      public static String sanitizeLabel(@CheckForNull String input)

      Sanitizes the input string to create a valid Kubernetes label.

      The input string is truncated to a maximum length of 57 characters, and any characters that are not alphanumeric or hyphens are replaced with underscores. If the input string starts with a non-alphanumeric character, it is replaced with 'x'.

      Parameters:
      input - the input string to be sanitized
      Returns:
      the sanitized and validated label
      Throws:
      AssertionError - if the generated label is not valid
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable String string)
    • emptyToNull

      @Nullable public static String emptyToNull(@Nullable String string)