Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-49707] If a KubernetesComputer disconnects, remove the KubernetesSlave #461

Merged
merged 23 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
99ad1f2
[JENKINS-49707] If a KubernetesComputer disconnects, remove the Kuber…
jglick Apr 30, 2019
cae2572
workflow-step-api-plugin.version
jglick Apr 30, 2019
eed014f
Updated to https://github.com/jenkinsci/workflow-durable-task-step-pl…
jglick Apr 30, 2019
c3c98a1
Incremental deployment.
jglick Apr 30, 2019
4510310
JDK 11 Javadoc failure.
jglick Apr 30, 2019
8569e83
Setting surefire.rerunFailingTestsCount to 0 not 1.
jglick May 1, 2019
f11a182
Copy-pasta.
jglick May 1, 2019
ce032c6
Redesigned fix to remove agents when a pod is deleted, rather than me…
jglick May 1, 2019
61307bf
We will not in general be permitted to watch pods at cluster scope, s…
jglick May 1, 2019
6da8cf6
Merge branch 'master' into removingAgentIsFatal-JENKINS-49707
jglick Jun 5, 2019
2c3b39e
Bump.
jglick Jun 5, 2019
5b30251
RequireUpperBoundDeps
jglick Jun 5, 2019
3f00eb1
Need to update workflow-cps to interpret DynamicContext.
jglick Jun 5, 2019
6f60c9e
Merge branch 'master' into removingAgentIsFatal-JENKINS-49707
jglick Jun 11, 2019
b9b5f9c
Merge branch 'master' into removingAgentIsFatal-JENKINS-49707
jglick Jun 11, 2019
210e0f7
Test flake pending #496.
jglick Jun 11, 2019
a25d24f
Bump.
jglick Jun 11, 2019
e71a5c5
Senseless to even try to build against _older_ LTS lines than our min…
jglick Jun 11, 2019
3c49b62
Merge branch 'master' into removingAgentIsFatal-JENKINS-49707
jglick Jun 13, 2019
a5269d3
Merge branch 'master' into removingAgentIsFatal-JENKINS-49707
jglick Jul 2, 2019
70153a9
workflow-durable-task-step 2.32
jglick Jul 5, 2019
a4cccb7
Merge branch 'master' into removingAgentIsFatal-JENKINS-49707
jglick Jul 5, 2019
bb4e297
Using improved assertion after #496.
jglick Jul 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
<connectorHost />
<jenkins.host.address />
<java.level>8</java.level>
<jenkins.version>2.138.4</jenkins.version>
<jenkins.version>2.150.1</jenkins.version>
<no-test-jar>false</no-test-jar>
<surefire.rerunFailingTestsCount>1</surefire.rerunFailingTestsCount>
<pipeline-model-definition.version>1.3.7</pipeline-model-definition.version>
<workflow-support-plugin.version>3.1</workflow-support-plugin.version>
<workflow-step-api-plugin.version>2.18</workflow-step-api-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -94,7 +96,7 @@
<dependency> <!-- OnceRetentionStrategy -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>durable-task</artifactId>
<version>1.28</version>
<version>1.29</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -104,7 +106,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.17</version>
<version>${workflow-step-api-plugin.version}</version>
</dependency>
<dependency> <!-- DeclarativeAgent -->
<groupId>org.jenkinsci.plugins</groupId>
Expand All @@ -129,26 +131,26 @@
<dependency> <!-- StepConfigTester -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.17</version>
<version>${workflow-step-api-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>3.0</version>
<version>${workflow-support-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.27</version>
<version>2.31-SNAPSHOT</version> <!-- https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/104 -->
<scope>test</scope>
</dependency>
<dependency> <!-- SemaphoreStep -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>3.0</version>
<version>${workflow-support-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
import org.kohsuke.stapler.DataBoundConstructor;

import com.google.common.base.Throwables;
import hudson.model.Slave;

import hudson.model.TaskListener;
import hudson.slaves.JNLPLauncher;
import hudson.slaves.SlaveComputer;

import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.KubernetesClient;
import jenkins.model.Jenkins;

/**
* Launches on Kubernetes the specified {@link KubernetesComputer} instance.
Expand Down Expand Up @@ -159,4 +161,20 @@ public AllContainersRunningPodWatcher getWatcher() {
return watcher;
}

@Override
public void afterDisconnect(SlaveComputer computer, TaskListener listener) {
// TODO can this be done only if the pod is dead?
Slave node = computer.getNode();
if (node != null) {
try {
Jenkins.get().removeNode(node);
LOGGER.info(() -> "Removed disconnected agent " + node.getNodeName());
} catch (IOException x) {
LOGGER.log(Level.WARNING, x, () -> "Unable to remove Jenkins node " + node.getNodeName());
}
} else {
LOGGER.fine(() -> "Could not find disconnected agent " + computer.getName() + " to remove");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.jvnet.hudson.test.JenkinsRuleNonLocalhost;

import hudson.model.Result;
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution;
import org.jvnet.hudson.test.Issue;

/**
* @author Carlos Sanchez
Expand Down Expand Up @@ -334,4 +336,14 @@ public void runInPodWithRetention() throws Exception {
r.assertBuildStatusSuccess(r.waitForCompletion(b));
assertTrue(deletePods(cloud.connect(), getLabels(this, name), true));
}

@Issue("JENKINS-49707")
@Test
public void terminatedPod() throws Exception {
r.waitForMessage("+ sleep", b);
deletePods(cloud.connect(), getLabels(this, name), false);
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
r.waitForMessage(new ExecutorStepExecution.RemovedNodeCause().getShortDescription(), b);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
podTemplate(label: 'runInPod', containers: [
containerTemplate(name: 'busybox', image: 'busybox', ttyEnabled: true, command: '/bin/cat'),
]) {
node ('runInPod') {
container('busybox') {
sh 'sleep 9999999'
}
}
}