From 1dd44f5b1cf9c938c23a65c9c19e6b92b2a8e3af Mon Sep 17 00:00:00 2001 From: Pavel Soloviev <66182149+Moleus@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:07:00 +0300 Subject: [PATCH] [JENKINS-72886] fix `command` & `args` are lost when combining container templates (#1525) --- .../jenkins/plugins/kubernetes/PodTemplateUtils.java | 8 ++++++-- .../plugins/kubernetes/PodTemplateUtilsTest.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java index a94472fc62..39d802c6bc 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java @@ -203,8 +203,12 @@ public static Container combine(@CheckForNull Container parent, @NonNull Contain String workingDir = isNullOrEmpty(template.getWorkingDir()) ? (isNullOrEmpty(parent.getWorkingDir()) ? DEFAULT_WORKING_DIR : parent.getWorkingDir()) : template.getWorkingDir(); - List command = template.getCommand() == null ? parent.getCommand() : template.getCommand(); - List args = template.getArgs() == null ? parent.getArgs() : template.getArgs(); + List command = + template.getCommand() == null || template.getCommand().isEmpty() + ? parent.getCommand() + : template.getCommand(); + List args = + template.getArgs() == null || template.getArgs().isEmpty() ? parent.getArgs() : template.getArgs(); Boolean tty = template.getTty() != null ? template.getTty() : parent.getTty(); Map requests = combineResources(parent, template, ResourceRequirements::getRequests); Map limits = combineResources(parent, template, ResourceRequirements::getLimits); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java index eee3c262b1..7d7a6fc7b5 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java @@ -937,4 +937,16 @@ private static void checkParsed(Pod pod) { .get(0) .getMode()); } + + @Test + @Issue("JENKINS-72886") + public void shouldIgnoreContainerEmptyArgs() { + Container parent = new Container(); + parent.setArgs(List.of("arg1", "arg2")); + parent.setCommand(List.of("parent command")); + Container child = new Container(); + Container result = combine(parent, child); + assertEquals(List.of("arg1", "arg2"), result.getArgs()); + assertEquals(List.of("parent command"), result.getCommand()); + } }