Skip to content

Commit

Permalink
Merge pull request #209 from bajacondor/patch-1
Browse files Browse the repository at this point in the history
Add podAnnotations to combined pod template
  • Loading branch information
carlossg authored Sep 3, 2017
2 parents e730162 + aa731c1 commit 18854f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume;
import org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.WorkspaceVolume;


import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

Expand Down Expand Up @@ -88,7 +89,11 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
String nodeSelector = Strings.isNullOrEmpty(template.getNodeSelector()) ? parent.getNodeSelector() : template.getNodeSelector();
String serviceAccount = Strings.isNullOrEmpty(template.getServiceAccount()) ? parent.getServiceAccount() : template.getServiceAccount();
Node.Mode nodeUsageMode = template.getNodeUsageMode() == null ? parent.getNodeUsageMode() : template.getNodeUsageMode();


Set<PodAnnotation> podAnnotations = new LinkedHashSet<>();
podAnnotations.addAll(parent.getAnnotations());
podAnnotations.addAll(template.getAnnotations());

Set<PodImagePullSecret> imagePullSecrets = new LinkedHashSet<>();
imagePullSecrets.addAll(parent.getImagePullSecrets());
imagePullSecrets.addAll(template.getImagePullSecrets());
Expand Down Expand Up @@ -124,6 +129,7 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
podTemplate.setWorkspaceVolume(workspaceVolume);
podTemplate.setVolumes(new ArrayList<>(combinedVolumes.values()));
podTemplate.setImagePullSecrets(new ArrayList<>(imagePullSecrets));
podTemplate.setAnnotations(new ArrayList<>(podAnnotations));
podTemplate.setNodeProperties(toolLocationNodeProperties);
podTemplate.setNodeUsageMode(nodeUsageMode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class PodTemplateUtilsTest {
private static final PodImagePullSecret SECRET_2 = new PodImagePullSecret("secret2");
private static final PodImagePullSecret SECRET_3 = new PodImagePullSecret("secret3");

private static final PodAnnotation ANNOTATION_1 = new PodAnnotation("key1", "value1");
private static final PodAnnotation ANNOTATION_2 = new PodAnnotation("key2", "value2");

private static final ContainerTemplate JNLP_1 = new ContainerTemplate("jnlp", "jnlp:1");
private static final ContainerTemplate JNLP_2 = new ContainerTemplate("jnlp", "jnlp:2");

Expand Down Expand Up @@ -144,6 +147,22 @@ public void shouldCombineAllImagePullSecrets() {
}


@Test
public void shouldCombineAllAnnotations() {
PodTemplate parent = new PodTemplate();
parent.setName("parent");
parent.setNodeSelector("key:value");
parent.setAnnotations(asList(ANNOTATION_1));

PodTemplate template1 = new PodTemplate();
template1.setName("template");
template1.setAnnotations(asList(ANNOTATION_2));

PodTemplate result = combine(parent, template1);
assertEquals(2, result.getAnnotations().size());
}


@Test
public void shouldUnwrapParent() {
PodTemplate parent = new PodTemplate();
Expand Down

0 comments on commit 18854f2

Please sign in to comment.