From bb8e3774993d03f8e35a69e6d435d356643fe841 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 23 Oct 2023 08:59:47 -0400 Subject: [PATCH 1/2] Added `DirectConnectionTest`, downgrading agent image --- .../jenkins/plugins/kubernetes/Dockerfile | 2 +- .../pipeline/DirectConnectionTest.java | 39 +++++++++++++++++++ .../pipeline/directConnectionAgent.groovy | 5 +++ test-in-k8s.sh | 2 + 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/DirectConnectionTest.java create mode 100644 src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/directConnectionAgent.groovy diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/Dockerfile b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/Dockerfile index 836fcd21e4..06366f8eba 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/Dockerfile +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/Dockerfile @@ -1 +1 @@ -FROM jenkins/inbound-agent:3180.v3dd999d24861-1 +FROM jenkins/inbound-agent:3174.v2c9e67f8f9df-1 diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/DirectConnectionTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/DirectConnectionTest.java new file mode 100644 index 0000000000..97a6cc2c32 --- /dev/null +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/DirectConnectionTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2023 CloudBees, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.csanchez.jenkins.plugins.kubernetes.pipeline; + +import java.util.logging.Level; +import org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil; +import org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder; +import org.junit.Before; +import org.junit.Test; + +public final class DirectConnectionTest extends AbstractKubernetesPipelineTest { + + @Before + public void setUp() throws Exception { + KubernetesTestUtil.deletePods(cloud.connect(), KubernetesTestUtil.getLabels(cloud, this, name), false); + cloud.setDirectConnection(true); + logs.record(PodTemplateBuilder.class, Level.FINEST); + } + + @Test + public void directConnectionAgent() throws Exception { + r.assertBuildStatusSuccess(r.waitForCompletion(createJobThenScheduleRun())); + } + +} diff --git a/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/directConnectionAgent.groovy b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/directConnectionAgent.groovy new file mode 100644 index 0000000000..6164958dff --- /dev/null +++ b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/directConnectionAgent.groovy @@ -0,0 +1,5 @@ +podTemplate { + node(POD_LABEL) { + sh 'echo OK running' + } +} diff --git a/test-in-k8s.sh b/test-in-k8s.sh index b3f22f74a4..1dbdb93599 100755 --- a/test-in-k8s.sh +++ b/test-in-k8s.sh @@ -31,6 +31,8 @@ kubectl exec jenkins -- \ -Dport=$http_port \ -DslaveAgentPort=$tcp_port \ -Djenkins.host.address=jenkins.kubernetes-plugin-test.svc.cluster.local \ + `# TODO perhaps PodTemplateBuilder should default host from KubernetesCloud.jenkinsUrl when this is unset? ` \ + -Dhudson.TcpSlaveAgentListener.hostName=jenkins.kubernetes-plugin-test.svc.cluster.local \ -Dmaven.test.failure.ignore \ verify \ "$@" From db069135f77967f554e98aea45e0ef9998b1efcf Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 23 Oct 2023 10:12:13 -0400 Subject: [PATCH 2/2] `PodTemplateBuilderTest` was assuming `localhost` for `JENKINS_DIRECT_CONNECTION` --- .../jenkins/plugins/kubernetes/PodTemplateBuilderTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java index 20a79cf43b..df9523d289 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java @@ -424,7 +424,9 @@ private void validateJnlpContainer(Container jnlp, KubernetesSlave slave, boolea assertThat(jnlp.getArgs(), empty()); if(directConnection) { envVars.add(new EnvVar("JENKINS_PROTOCOLS", JENKINS_PROTOCOLS, null)); - envVars.add(new EnvVar("JENKINS_DIRECT_CONNECTION", "localhost:" + Jenkins.get().getTcpSlaveAgentListener().getAdvertisedPort(), null)); + envVars.add(new EnvVar("JENKINS_DIRECT_CONNECTION", + System.getProperty("hudson.TcpSlaveAgentListener.hostName", "localhost") + ":" + + Jenkins.get().getTcpSlaveAgentListener().getAdvertisedPort(), null)); envVars.add(new EnvVar("JENKINS_INSTANCE_IDENTITY", Jenkins.get().getTcpSlaveAgentListener().getIdentityPublicKey(), null)); } else { envVars.add(new EnvVar("JENKINS_URL", JENKINS_URL, null));