Class PodTemplateUtils
java.lang.Object
org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic io.fabric8.kubernetes.api.model.Containercombine(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.Podcombine(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.PodCombines all given pods together in order.static ContainerTemplatecombine(ContainerTemplate parent, ContainerTemplate template) Combines aContainerTemplatewith its parent.static PodTemplatecombine(PodTemplate parent, PodTemplate template) Combines aPodTemplatewith its parent.static StringemptyToNull(String string) static PodTemplategetTemplateByLabel(Label label, Collection<PodTemplate> templates) Gets thePodTemplatebyLabel.static PodTemplategetTemplateByName(String name, Collection<PodTemplate> templates) Gets thePodTemplateby name.static booleanisNullOrEmpty(String string) static booleanisNullOrEmpty(List<?> list) static io.fabric8.kubernetes.api.model.PodparseFromYaml(String yaml) static StringsanitizeLabel(String input) Sanitizes the input string to create a valid Kubernetes label.splitCommandLine(String commandLine) Split a command in the parts that Docker needstatic Stringsubstitute(String s, Map<String, String> properties) Deprecated.static StringDeprecated.check if it is null or empty in the caller method, then usesubstitute(String,Map)static StringDeprecated.Potentially insecure; a no-op by default.static booleanvalidateContainerName(String name) static booleanvalidateImage(String image) TODO perhaps enforce https://docs.docker.com/engine/reference/commandline/tag/#extended-descriptionstatic booleanvalidateLabel(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 aContainerTemplatewith 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 aPodTemplatewith 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 thePodTemplatebyLabel.- 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 thePodTemplateby 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 -
splitCommandLine
Split a command in the parts that Docker need- Parameters:
commandLine- docker command to parse- Returns:
- command split by arguments,
nullifcommandLineisnullor empty
-
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)