From e5faa7f39ad15fe8acfdbbf691b9b6b10bb478e9 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Fri, 17 Jan 2020 14:32:03 +0100 Subject: [PATCH] Set terminationGracePeriodSeconds to 0 to avoid waiting 30 seconds for pod termination. --- .../csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java | 1 + .../plugins/kubernetes/pipeline/ContainerExecDecoratorTest.java | 2 +- .../jenkins/plugins/kubernetes/pipeline/cascadingDelete.groovy | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java index bc5f96ef82..661617679e 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java @@ -198,6 +198,7 @@ public Pod build() { builder.withNodeSelector(nodeSelector); } + builder.withTerminationGracePeriodSeconds(0L); builder.withContainers(containers.values().toArray(new Container[containers.size()])); Long runAsUser = template.getRunAsUserAsLong(); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorTest.java index 35866eb5f1..9389e35380 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecoratorTest.java @@ -116,7 +116,7 @@ public void configureCloud() throws Exception { .withCommand("cat").withTty(true).withWorkingDir("/home/jenkins/agent1").build(); String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789"); pod = client.pods().create(new PodBuilder().withNewMetadata().withName(podName) - .withLabels(getLabels(this, name)).endMetadata().withNewSpec().withContainers(c, d).withNodeSelector(Collections.singletonMap("kubernetes.io/os", "linux")).endSpec().build()); + .withLabels(getLabels(this, name)).endMetadata().withNewSpec().withContainers(c, d).withNodeSelector(Collections.singletonMap("kubernetes.io/os", "linux")).withTerminationGracePeriodSeconds(0L).endSpec().build()); System.out.println("Created pod: " + pod.getMetadata().getName()); diff --git a/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/cascadingDelete.groovy b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/cascadingDelete.groovy index 6b291996ac..acf81a760e 100644 --- a/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/cascadingDelete.groovy +++ b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/cascadingDelete.groovy @@ -62,6 +62,7 @@ spec: labels: app: cascading-delete spec: + terminationGracePeriodSeconds: 0 containers: - name: ubuntu image: ubuntu