-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-58405] Backward compatibility for yaml field merge (#542)
[JENKINS-58405] Backward compatibility for yaml field merge
- Loading branch information
Showing
17 changed files
with
212 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/org/csanchez/jenkins/plugins/kubernetes/pod/yaml/Merge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes.pod.yaml; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils; | ||
import org.jenkinsci.Symbol; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.combine; | ||
|
||
public class Merge extends YamlMergeStrategy { | ||
private static final long serialVersionUID = 6562610892063268131L; | ||
|
||
@DataBoundConstructor | ||
public Merge() { | ||
} | ||
|
||
@Override | ||
public Pod merge(List<String> yamls) { | ||
return combine(yamls.stream().map(PodTemplateUtils::parseFromYaml).collect(Collectors.toList())); | ||
} | ||
|
||
@Extension | ||
@Symbol("merge") | ||
public static class DescriptorImpl extends Descriptor<YamlMergeStrategy> { | ||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return "Merge"; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/csanchez/jenkins/plugins/kubernetes/pod/yaml/Overrides.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes.pod.yaml; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import org.jenkinsci.Symbol; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
|
||
import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.parseFromYaml; | ||
|
||
public class Overrides extends YamlMergeStrategy { | ||
private static final long serialVersionUID = 4510341864619338164L; | ||
|
||
@DataBoundConstructor | ||
public Overrides() { | ||
} | ||
|
||
@Override | ||
public Pod merge(List<String> yamls) { | ||
if (yamls.isEmpty()) { | ||
return null; | ||
} else { | ||
return parseFromYaml(yamls.get(yamls.size()-1)); | ||
} | ||
} | ||
|
||
@Extension | ||
@Symbol("override") | ||
public static class DescriptorImpl extends Descriptor<YamlMergeStrategy> { | ||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return "Override"; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/csanchez/jenkins/plugins/kubernetes/pod/yaml/YamlMergeStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes.pod.yaml; | ||
|
||
import hudson.ExtensionPoint; | ||
import hudson.model.AbstractDescribableImpl; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
public abstract class YamlMergeStrategy extends AbstractDescribableImpl<YamlMergeStrategy> implements ExtensionPoint, Serializable { | ||
public static YamlMergeStrategy defaultStrategy() { | ||
return new Overrides(); | ||
} | ||
|
||
public abstract Pod merge(@Nonnull List<String> yamls); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/help-yamlMergeStrategy.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Defines how the raw yaml field gets merged with yaml definitions from inherited pod templates. |
5 changes: 5 additions & 0 deletions
5
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pod/yaml/Merge/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<f:description>The yaml definitions from inherited pod templates are merged with the current template yaml fragment.</f:description> | ||
</j:jelly> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pod/yaml/Overrides/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<f:description>The yaml definitions from inherited pod templates are completely overridden by the current yaml field.</f:description> | ||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/mergeYaml.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
podTemplate(yaml: """ | ||
spec: | ||
containers: | ||
- name: jnlp | ||
env: | ||
- name: VAR1 | ||
value: 1 | ||
""") { | ||
podTemplate(yamlMergeStrategy: merge(), | ||
yaml: """ | ||
containers: | ||
- name: jnlp | ||
env: | ||
- name: VAR2 | ||
value: 1 | ||
""") { | ||
node(POD_LABEL){ | ||
sh '["$VAR1" == "$VAR2"]' | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/overrideYaml.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
podTemplate(yaml: """ | ||
spec: | ||
containers: | ||
- name: jnlp | ||
env: | ||
- name: VAR1 | ||
value: 1 | ||
""") { | ||
podTemplate(yaml: """ | ||
containers: | ||
- name: jnlp | ||
env: | ||
- name: VAR2 | ||
value: 1 | ||
""") { | ||
node(POD_LABEL){ | ||
sh '["$VAR1" != "$VAR2"]' | ||
} | ||
} | ||
} |