From 30a6feb63c3591a4a8a1797ee3c3db4fbdd41022 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 23 Nov 2023 15:50:43 +0100 Subject: [PATCH] [JENKINS-70217] Default ContainerTemplate command and arg to empty string when using casc When defining a container template using Casc and unspecified command and arg, it seems more natural that the default entrypoint and args are executed. So setting these to empty string when constructing a new instance seems more natural. This doesn't change the behaviour of creating a new container template using the UI, as the default value will come from jelly because the ContainerTemplate instance will be null when populating the jelly fragment. --- .../jenkins/plugins/kubernetes/ContainerTemplate.java | 4 ++-- .../csanchez/jenkins/plugins/kubernetes/casc/CasCTest.java | 5 ++++- .../plugins/kubernetes/casc/configuration-as-code.yaml | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/ContainerTemplate.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/ContainerTemplate.java index a34d5f6d9e..aeeecd0543 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/ContainerTemplate.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/ContainerTemplate.java @@ -46,9 +46,9 @@ public class ContainerTemplate extends AbstractDescribableImpl containers = podTemplate.getContainers(); assertNotNull(containers); - assertEquals(1, containers.size()); + assertEquals(2, containers.size()); ContainerTemplate container = containers.get(0); assertEquals("cat", container.getArgs()); assertEquals("/bin/sh -c", container.getCommand()); @@ -78,6 +78,9 @@ protected void assertConfiguredAsExpected(RestartableJenkinsRule r, String confi assertEquals("maven",container.getName()); assertTrue(container.isTtyEnabled()); assertEquals("/src", container.getWorkingDir()); + var containerTemplate = containers.get(1); + assertEquals("", containerTemplate.getCommand()); + assertEquals("", containerTemplate.getArgs()); } diff --git a/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/casc/configuration-as-code.yaml b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/casc/configuration-as-code.yaml index 85287342fb..9b9320dd01 100644 --- a/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/casc/configuration-as-code.yaml +++ b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/casc/configuration-as-code.yaml @@ -36,6 +36,8 @@ jenkins: name: "maven" ttyEnabled: true workingDir: "/src" + - name: "maven-with-default-entrypoint" + image: "maven:3.6.3-jdk-8" hostNetwork: false label: "test" name: "test"