Skip to content

Commit

Permalink
Remove containers grace period (#686)
Browse files Browse the repository at this point in the history
Remove containers grace period
  • Loading branch information
Vlatombe authored Jan 20, 2020
2 parents 3679292 + 3fb121d commit cfcc2e5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements

private PodTemplateToolLocation nodeProperties;

private Long terminationGracePeriodSeconds;

/**
* Persisted yaml fragment
*/
Expand Down Expand Up @@ -733,6 +735,14 @@ public void setPodRetention(PodRetention podRetention) {
this.podRetention = podRetention;
}

public Long getTerminationGracePeriodSeconds() {
return terminationGracePeriodSeconds;
}

public void setTerminationGracePeriodSeconds(Long terminationGracePeriodSeconds) {
this.terminationGracePeriodSeconds = terminationGracePeriodSeconds;
}

protected Object readResolve() {
if (containers == null) {
// upgrading from 0.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ public Pod build() {
builder.withNodeSelector(nodeSelector);
}

if (template.getTerminationGracePeriodSeconds() != null) {
builder.withTerminationGracePeriodSeconds(template.getTerminationGracePeriodSeconds());
}
builder.withContainers(containers.values().toArray(new Container[containers.size()]));

Long runAsUser = template.getRunAsUserAsLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud;
import org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil;
import org.csanchez.jenkins.plugins.kubernetes.PodTemplate;
import org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder;
import org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar;
import org.csanchez.jenkins.plugins.kubernetes.model.SecretEnvVar;
import org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar;
Expand Down Expand Up @@ -160,6 +161,7 @@ private PodTemplate buildBusyboxTemplate(String label) {
// Create a busybox template
PodTemplate podTemplate = new PodTemplate();
podTemplate.setLabel(label);
podTemplate.setTerminationGracePeriodSeconds(0L);

ContainerTemplate containerTemplate = new ContainerTemplate("busybox", "busybox", "cat", "");
containerTemplate.setTtyEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private PodTemplate buildBusyboxTemplate(String label) {
// Create a busybox template
PodTemplate podTemplate = new PodTemplate();
podTemplate.setLabel(label);
podTemplate.setTerminationGracePeriodSeconds(0L);

ContainerTemplate containerTemplate = new ContainerTemplate("busybox", "busybox", "cat", "");
containerTemplate.setTtyEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ spec:
labels:
app: cascading-delete
spec:
terminationGracePeriodSeconds: 0
containers:
- name: ubuntu
image: ubuntu
Expand Down

0 comments on commit cfcc2e5

Please sign in to comment.