Reputation: 1
I have the following code in groovy:
void call(Closure closure) {
pod_template_maven_image = ...
pod_template_maven_m2 = ...
pod_template_nodejs_image = ...
pod_template_sonar_image = ...
toleration_condition = true
def yaml_config = ""
if(toleration_condition){
yaml_config = """
spec:
tolerations:
- key: "my_toleration"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
"""
}
podTemplate(containers: ...,
volumes: ...,
etc...,
yaml: yaml_config,
yamlMergeStrategy: merge()) {
node(POD_LABEL) {
closure()
}
}
}
At the moment, when I run the job in jenking nothing happens, the pod is created whitout error. But the yaml is not added in pod.
We want to add the toleration (yaml_config) in podTemplate depending of toleration_condition value.
I'm new in this area and don't now if is possible. Its is? Whats the best way to do it?
Thanks.
Upvotes: 0
Views: 1329
Reputation: 1
The problem was solved by placing the complete manifest structure, which ended up being automatically merged.
It took less than a year to find out.
Upvotes: 0
Reputation: 365
Tip: I see you use the Kubernetes plugin. Have you seen the section of inheritance? Using the declarative pipeline syntax, with inheritFrom
, might provide a much cleaner way to achieve the wanted results. Here we also keep the yamlMergeStrategy
as default (override()
).
I have seen that the indents of the "delta yaml" (yaml_config
), provided to yaml:
, influences the final outcome (trailing and starting newlines could also have impact). So I would recommend testing with a yaml_config
like:
yaml_config = """
spec:
tolerations:
- key: "my_toleration"
operator: "Equal"
value: "value1"
effect: "NoSchedule" """
Upvotes: 0