Class PodTemplateUtils
- java.lang.Object
-
- org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils
-
public class PodTemplateUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DISABLE_OCTAL_MODES
If true, all modes permissions provided to pods are expected to be provided in decimal notation.static boolean
SUBSTITUTE_ENV
-
Constructor Summary
Constructors Constructor Description PodTemplateUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static io.fabric8.kubernetes.api.model.Container
combine(io.fabric8.kubernetes.api.model.Container parent, io.fabric8.kubernetes.api.model.Container template)
Combines a Container with its parent.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.static io.fabric8.kubernetes.api.model.Pod
combine(List<io.fabric8.kubernetes.api.model.Pod> pods)
Combines all given pods together in order.static ContainerTemplate
combine(ContainerTemplate parent, ContainerTemplate template)
Combines aContainerTemplate
with its parent.static PodTemplate
combine(PodTemplate parent, PodTemplate template)
Combines aPodTemplate
with its parent.static String
emptyToNull(String string)
static PodTemplate
getTemplateByLabel(Label label, Collection<PodTemplate> templates)
Gets thePodTemplate
byLabel
.static PodTemplate
getTemplateByName(String name, Collection<PodTemplate> templates)
Gets thePodTemplate
by name.static boolean
isNullOrEmpty(String string)
static io.fabric8.kubernetes.api.model.Pod
parseFromYaml(String yaml)
static String
substitute(String s, Map<String,String> properties)
Deprecated.static String
substitute(String s, Map<String,String> properties, String defaultValue)
Deprecated.check if it is null or empty in the caller method, then usesubstitute(String,Map)
static String
substituteEnv(String s)
Deprecated.Potentially insecure; a no-op by default.static boolean
validateContainerName(String name)
static boolean
validateImage(String image)
TODO perhaps enforce https://docs.docker.com/engine/reference/commandline/tag/#extended-descriptionstatic boolean
validateLabel(String label)
static Collection<String>
validateYamlContainerNames(String yaml)
static Collection<String>
validateYamlContainerNames(List<String> yamls)
-
-
-
Method Detail
-
combine
public static ContainerTemplate combine(@CheckForNull ContainerTemplate parent, @NonNull ContainerTemplate template)
Combines aContainerTemplate
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 aPodTemplate
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 thePodTemplate
byLabel
.- 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 thePodTemplate
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)
Deprecated.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 usesubstitute(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
-
isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
-
-