Class PodTemplateUtils
java.lang.Object
org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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 boolean
isNullOrEmpty
(List<?> list) static io.fabric8.kubernetes.api.model.Pod
parseFromYaml
(String yaml) static String
sanitizeLabel
(String input) Sanitizes the input string to create a valid Kubernetes label.static String
substitute
(String s, Map<String, String> properties) Deprecated.static String
Deprecated.check if it is null or empty in the caller method, then usesubstitute(String,Map)
static String
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>
static Collection<String>
validateYamlContainerNames
(List<String> yamls)
-
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 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
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.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.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
-
validateYamlContainerNames
-
validateYamlContainerNames
-
validateContainerName
-
validateLabel
-
validateImage
TODO perhaps enforce https://docs.docker.com/engine/reference/commandline/tag/#extended-description -
sanitizeLabel
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
-
isNullOrEmpty
-
emptyToNull
-
Util.replaceMacro(String, Map)