diff --git a/Jenkinsfile b/Jenkinsfile index b3e15ce2fe..1429fcb0c4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,9 +27,7 @@ stage('Tests') { writeFile file: (split.includes ? "$WORKSPACE_TMP/includes.txt" : "$WORKSPACE_TMP/excludes.txt"), text: split.list.join("\n") writeFile file: (split.includes ? "$WORKSPACE_TMP/excludes.txt" : "$WORKSPACE_TMP/includes.txt"), text: '' sh './kind.sh -Dsurefire.includesFile="$WORKSPACE_TMP/includes.txt" -Dsurefire.excludesFile="$WORKSPACE_TMP/excludes.txt"' - dir(env.WORKSPACE_TMP) { - junit 'surefire-reports/*.xml' - } + junit 'target/surefire-reports/*.xml' } finally { dir(env.WORKSPACE_TMP) { if (fileExists('kindlogs/docker-info.txt')) { diff --git a/Jenkinsfile-release b/Jenkinsfile-release deleted file mode 100644 index e1d5fa7c6a..0000000000 --- a/Jenkinsfile-release +++ /dev/null @@ -1,25 +0,0 @@ -def label = "maven-${UUID.randomUUID().toString()}" // TODO use POD_LABEL when available -def mvnOpts = '-DskipTests -ntp -Darguments="-DskipTests -ntp"' - -podTemplate(label: label, containers: [ - containerTemplate(name: 'maven', image: 'maven:3.6.1-jdk-8', ttyEnabled: true, command: 'cat') - ], volumes: [ - persistentVolumeClaim(mountPath: '/root/.m2/repository', claimName: 'maven-repo', readOnly: false) - ]) { - - node(label) { - stage('Checkout') { - checkout scm - } - stage('Release prepare') { - container('maven') { - sh "mvn -B ${mvnOpts} release:clean release:prepare -DreleaseVersion=${releaseVersion} -DdevelopmentVersion=${developmentVersion}" - } - } - stage('Release perform') { - container('maven') { - sh "mvn -B ${mvnOpts} release:perform" - } - } - } -} diff --git a/README.md b/README.md index bc39ae7efe..89fa3e5b37 100644 --- a/README.md +++ b/README.md @@ -1006,72 +1006,31 @@ Run `mvn clean install` and copy `target/kubernetes.hpi` to Jenkins plugins fold ## Running Kubernetes Integration Tests -### Integration tests with Kind (recommended) +Set up your `$KUBECONFIG` however you like, for example ```bash -export MOUNT_M2=true -./kind-mount-m2.sh -./kind-preload.sh -./test-in-k8s.sh -Dtest=KubernetesPipelineTest#runInPod -kind delete cluster +kind create cluster ``` -### Integration tests in a remote cluster - -Set up your `$KUBECONFIG` as usual, then +then ```bash -./test-in-k8s.sh -Dtest=KubernetesPipelineTest#runInPod +kubectl krew install tunnel # as needed; install Krew first +kubectl tunnel expose jenkins 8000:8000 8001:8001 & +mvn test -Djenkins.host.address=jenkins.default -Dport=8000 -DslaveAgentPort=8001 -Dtest=KubernetesPipelineTest#runInPod ``` -### Integration tests with Minikube - -The system you run `mvn` on needs to be reachable from the cluster. -If you see the agents happen to connect to the wrong host, see you can use -`jenkins.host.address` as mentioned above. - -For integration tests install and start [minikube](https://github.com/kubernetes/minikube). -Tests will detect it and run a set of integration tests in a new namespace. - -Some integration tests run a local jenkins, so the host that runs them needs -to be accessible from the kubernetes cluster. -By default Jenkins will listen on `192.168.64.1` interface only, for security reasons. -If your minikube is not running in that network, pass `connectorHost` to maven, ie. - - mvn clean install -DconnectorHost=$(minikube ip | sed -e 's/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1.1/') - -If you don't mind others in your network being able to use your test jenkins you could just use this: - - mvn clean install -DconnectorHost=0.0.0.0 - -Then your test jenkins will listen on all ip addresses so that the build pods will be able to connect from the pods in your minikube VM to your host. - -If your minikube is running in a VM (e.g. on virtualbox) and the host running `mvn` -does not have a public hostname for the VM to access, you can set the `jenkins.host.address` -system property to the (host-only or NAT) IP of your host: - - mvn clean install -Djenkins.host.address=192.168.99.1 - -### Integration tests with Microk8s - -If [Microk8s](https://microk8s.io/) is running and is the default context in your `~/.kube/config`, -just run as - - mvn clean install -Pmicrok8s - -This assumes that from a pod, the host system is accessible as IP address `10.1.1.1`. -It might be some variant such as `10.1.37.1`, -in which case you would need to set `-DconnectorHost=… -Djenkins.host.address=…` instead. -To see the actual address, try: +Alternately, you can run everything like in CI: ```bash -ifdata -pa cni0 +export KIND_PRELOAD=true # optionally +./kind.sh -Dtest=KubernetesPipelineTest#runInPod ``` -Or to verify the networking inside a pod: +You can also run interactively after setting up the tunnel: ```bash -kubectl run --rm --image=praqma/network-multitool --restart=Never --attach sh ip route | fgrep 'default via' +mvn hpi:run -Djenkins.host.address=jenkins.default -Dport=8000 -Djenkins.model.Jenkins.slaveAgentPort=8001 ``` # Docker image diff --git a/kind-mount-m2.sh b/kind-mount-m2.sh deleted file mode 100755 index c1ba58b46a..0000000000 --- a/kind-mount-m2.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -set -euxo pipefail -cd $(dirname $0) - -m2=$(dirname $(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)) -cfg=$(mktemp --tmpdir kind-XXXXX.yaml) -trap "rm -f $cfg" EXIT -cat >"$cfg" <>"$cfg" < 999999-SNAPSHOT - - 2.426.3 @@ -296,8 +293,6 @@ 0 3000 60000 - - ${connectorHost} ${jenkins.host.address} ${slaveAgentPort} @@ -313,6 +308,7 @@ 50 0.85 ${jenkins.host.address} + ${port} true @@ -348,28 +344,4 @@ - - - docker - - 192.168.1.27 - 192.168.1.27 - - - - microk8s - - 10.1.1.1 - 10.1.1.1 - - - - docker-desktop - - 127.0.0.1 - host.docker.internal - - - - diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java index 51532fd502..0d592a4647 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java @@ -55,6 +55,7 @@ import jenkins.metrics.api.Metrics; import jenkins.model.Jenkins; import jenkins.model.JenkinsLocationConfiguration; +import jenkins.util.SystemProperties; import jenkins.websocket.WebSockets; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; @@ -1171,7 +1172,8 @@ public static void hpiRunInit() { if (hostAddress != null && jenkins.clouds.getAll(KubernetesCloud.class).isEmpty()) { KubernetesCloud cloud = new KubernetesCloud("kubernetes"); - cloud.setJenkinsUrl("http://" + hostAddress + ":8080/jenkins/"); + cloud.setJenkinsUrl( + "http://" + hostAddress + ":" + SystemProperties.getInteger("port", 8080) + "/jenkins/"); jenkins.clouds.add(cloud); } } diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesTestUtil.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesTestUtil.java index 037cfb44ad..c7b28803d6 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesTestUtil.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesTestUtil.java @@ -135,6 +135,7 @@ public static void setupHost(KubernetesCloud cloud) throws Exception { URL nonLocalhostUrl = new URL(url.getProtocol(), hostAddress, url.getPort(), url.getFile()); cloud.setJenkinsUrl(nonLocalhostUrl.toString()); + // TODO could just use standard jenkins.model.Jenkins.slaveAgentPort and skip this code (also in SetupCloud): Integer slaveAgentPort = Integer.getInteger("slaveAgentPort"); if (slaveAgentPort != null) { Jenkins.get().setSlaveAgentPort(slaveAgentPort); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineRJRTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineRJRTest.java index 9c16a66add..6a9d862a45 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineRJRTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineRJRTest.java @@ -23,11 +23,6 @@ public abstract class AbstractKubernetesPipelineRJRTest { { rjr = new RealJenkinsRule(); - String connectorHost = System.getProperty("connectorHost"); - if (StringUtils.isNotBlank(connectorHost)) { - System.err.println("Listening on host address: " + connectorHost); - rjr.withHttpListenAddress(connectorHost); - } String port = System.getProperty("port"); if (StringUtils.isNotBlank(port)) { System.err.println("Overriding port using system property: " + port); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineTest.java index 6fd47de6f6..3b9f698030 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractKubernetesPipelineTest.java @@ -62,7 +62,7 @@ import org.junit.Rule; import org.junit.rules.TestName; import org.jvnet.hudson.test.BuildWatcher; -import org.jvnet.hudson.test.JenkinsRuleNonLocalhost; +import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.LoggerRule; public abstract class AbstractKubernetesPipelineTest { @@ -76,7 +76,7 @@ public abstract class AbstractKubernetesPipelineTest { protected KubernetesCloud cloud; @Rule - public JenkinsRuleNonLocalhost r = new JenkinsRuleNonLocalhost(); + public JenkinsRule r = new JenkinsRule(); @Rule public LoggerRule logs = new LoggerRule() 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 index 52482fd569..9713823cf8 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/DirectConnectionTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/DirectConnectionTest.java @@ -16,6 +16,7 @@ package org.csanchez.jenkins.plugins.kubernetes.pipeline; +import hudson.TcpSlaveAgentListener; import java.util.logging.Level; import org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil; import org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder; @@ -24,6 +25,11 @@ public final class DirectConnectionTest extends AbstractKubernetesPipelineTest { + static { + System.setProperty( + TcpSlaveAgentListener.class.getName() + ".hostName", System.getProperty("jenkins.host.address")); + } + @Before public void setUp() throws Exception { KubernetesTestUtil.deletePods(cloud.connect(), KubernetesTestUtil.getLabels(cloud, this, name), false); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java index 30313bae04..6ac7f19ae9 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java @@ -105,7 +105,6 @@ import org.jvnet.hudson.test.FlagRule; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; -import org.jvnet.hudson.test.JenkinsRuleNonLocalhost; import org.jvnet.hudson.test.LoggerRule; import org.jvnet.hudson.test.MockAuthorizationStrategy; import org.jvnet.hudson.test.TestExtension; @@ -436,7 +435,7 @@ public void runWithEnvVariablesInContext() throws Exception { r.assertLogContains("The value of WILL.NOT is ", b); } - private void assertEnvVars(JenkinsRuleNonLocalhost r2, WorkflowRun b) throws Exception { + private void assertEnvVars(JenkinsRule r2, WorkflowRun b) throws Exception { r.assertLogNotContains(POD_ENV_VAR_FROM_SECRET_VALUE, b); r.assertLogNotContains(CONTAINER_ENV_VAR_FROM_SECRET_VALUE, b); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecutionTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecutionTest.java index f776a5b836..04187d72e8 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecutionTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecutionTest.java @@ -38,12 +38,12 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.jvnet.hudson.test.JenkinsRuleNonLocalhost; +import org.jvnet.hudson.test.JenkinsRule; public class PodTemplateStepExecutionTest { @Rule - public JenkinsRuleNonLocalhost r = new JenkinsRuleNonLocalhost(); + public JenkinsRule r = new JenkinsRule(); protected KubernetesCloud cloud; diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/RestartPipelineTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/RestartPipelineTest.java index 23f47c9fc9..d4c498aacc 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/RestartPipelineTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/RestartPipelineTest.java @@ -39,6 +39,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; +import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; import org.csanchez.jenkins.plugins.kubernetes.ContainerEnvVar; import org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate; @@ -62,8 +63,8 @@ import org.jvnet.hudson.test.BuildWatcher; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.JenkinsSessionRule; import org.jvnet.hudson.test.LoggerRule; -import org.jvnet.hudson.test.RestartableJenkinsNonLocalhostRule; public class RestartPipelineTest { protected static final String CONTAINER_ENV_VAR_VALUE = "container-env-var-value"; @@ -74,7 +75,7 @@ public class RestartPipelineTest { protected KubernetesCloud cloud; @Rule - public RestartableJenkinsNonLocalhostRule story = new RestartableJenkinsNonLocalhostRule(44000); + public JenkinsSessionRule story = new JenkinsSessionRule(); @Rule public TemporaryFolder tmp = new TemporaryFolder(); @@ -133,13 +134,13 @@ public void configureCloud() throws Exception { setupHost(cloud); - story.j.jenkins.clouds.add(cloud); + Jenkins.get().clouds.add(cloud); } public void configureAgentListener() throws IOException { // Take random port and fix it, to be the same after Jenkins restart - int fixedPort = story.j.jenkins.getTcpSlaveAgentListener().getAdvertisedPort(); - story.j.jenkins.setSlaveAgentPort(fixedPort); + int fixedPort = Jenkins.get().getTcpSlaveAgentListener().getAdvertisedPort(); + Jenkins.get().setSlaveAgentPort(fixedPort); } protected String loadPipelineScript(String name) { @@ -151,7 +152,7 @@ protected String loadPipelineScript(String name) { } @Test - public void nullLabelSupportsRestart() { + public void nullLabelSupportsRestart() throws Throwable { AtomicReference projectName = new AtomicReference<>(); story.then(r -> { configureAgentListener(); @@ -179,7 +180,7 @@ public void nullLabelSupportsRestart() { } @Test - public void runInPodWithRestartWithMultipleContainerCalls() throws Exception { + public void runInPodWithRestartWithMultipleContainerCalls() throws Exception, Throwable { AtomicReference projectName = new AtomicReference<>(); story.then(r -> { configureAgentListener(); @@ -200,7 +201,7 @@ public void runInPodWithRestartWithMultipleContainerCalls() throws Exception { } @Test - public void runInPodWithRestartWithLongSleep() throws Exception { + public void runInPodWithRestartWithLongSleep() throws Exception, Throwable { AtomicReference projectName = new AtomicReference<>(); story.then(r -> { configureAgentListener(); @@ -221,7 +222,7 @@ public void runInPodWithRestartWithLongSleep() throws Exception { } @Test - public void windowsRestart() throws Exception { + public void windowsRestart() throws Throwable { assumeWindows(WINDOWS_1809_BUILD); AtomicReference projectName = new AtomicReference<>(); story.then(r -> { @@ -243,7 +244,7 @@ public void windowsRestart() throws Exception { @Issue("JENKINS-49707") @Test - public void terminatedPodAfterRestart() throws Exception { + public void terminatedPodAfterRestart() throws Exception, Throwable { AtomicReference projectName = new AtomicReference<>(); story.then(r -> { configureAgentListener(); @@ -268,7 +269,7 @@ public void terminatedPodAfterRestart() throws Exception { } @Test - public void taskListenerAfterRestart() { + public void taskListenerAfterRestart() throws Throwable { AtomicReference projectName = new AtomicReference<>(); story.then(r -> { configureAgentListener(); @@ -295,7 +296,7 @@ public void taskListenerAfterRestart() { } @Test - public void taskListenerAfterRestart_multipleLabels() { + public void taskListenerAfterRestart_multipleLabels() throws Throwable { AtomicReference projectName = new AtomicReference<>(); story.then(r -> { configureAgentListener(); @@ -329,7 +330,7 @@ private PodTemplate waitForTemplate(KubernetesSlave node) throws InterruptedExce } @Test - public void getContainerLogWithRestart() throws Exception { + public void getContainerLogWithRestart() throws Exception, Throwable { AtomicReference projectName = new AtomicReference<>(); story.then(r -> { configureAgentListener(); diff --git a/src/test/java/org/jvnet/hudson/test/JenkinsRuleNonLocalhost.java b/src/test/java/org/jvnet/hudson/test/JenkinsRuleNonLocalhost.java deleted file mode 100644 index 115e090847..0000000000 --- a/src/test/java/org/jvnet/hudson/test/JenkinsRuleNonLocalhost.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2016, CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.jvnet.hudson.test; - -import java.net.BindException; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.ServletContext; -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jetty.http.HttpCompliance; -import org.eclipse.jetty.http.UriCompliance; -import org.eclipse.jetty.server.HttpConfiguration; -import org.eclipse.jetty.server.HttpConnectionFactory; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; - -/** - * @author Carlos Sanchez - * - */ -public class JenkinsRuleNonLocalhost extends JenkinsRule { - private static final Logger LOGGER = Logger.getLogger(JenkinsRuleNonLocalhost.class.getName()); - - private static final String HOST = System.getProperty("connectorHost"); - - private Integer port; - - public JenkinsRuleNonLocalhost(Integer port) { - this.port = port; - } - - public JenkinsRuleNonLocalhost() {} - - /** - * Prepares a webapp hosting environment to get {@link javax.servlet.ServletContext} implementation - * that we need for testing. - */ - protected ServletContext createWebServer() throws Exception { - server = new Server(new ThreadPoolImpl(new ThreadPoolExecutor( - 10, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() { - public Thread newThread(Runnable r) { - Thread t = new Thread(r); - t.setName("Jetty Thread Pool"); - return t; - } - }))); - - WebAppContext context = new WebAppContext(WarExploder.getExplodedDir().getPath(), contextPath); - context.setClassLoader(getClass().getClassLoader()); - context.setConfigurations(new Configuration[] {new WebXmlConfiguration()}); - context.addBean(new NoListenerConfiguration(context)); - JettyWebSocketServletContainerInitializer.configure(context, null); - server.setHandler(context); - context.getSecurityHandler().setLoginService(configureUserRealm()); - context.setResourceBase(WarExploder.getExplodedDir().getPath()); - - ServerConnector connector = new ServerConnector(server); - HttpConfiguration config = - connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration(); - // use a bigger buffer as Stapler traces can get pretty large on deeply nested URL - config.setRequestHeaderSize(12 * 1024); - config.setHttpCompliance(HttpCompliance.RFC7230); - config.setUriCompliance(UriCompliance.LEGACY); - System.err.println("Listening on host address: " + HOST); - connector.setHost(HOST); - - String customPort = System.getProperty("port"); - if (StringUtils.isNotBlank(customPort)) { - LOGGER.info("Overriding port using system property: " + customPort); - connector.setPort(Integer.parseInt(customPort)); - } else { - if (port != null) { - connector.setPort(port); - } - } - - server.addConnector(connector); - try { - server.start(); - } catch (BindException e) { - throw new BindException(String.format( - "Error binding to %s:%d %s", connector.getHost(), connector.getPort(), e.getMessage())); - } - - localPort = connector.getLocalPort(); - LOGGER.log(Level.INFO, "Running on {0}", getURL()); - - return context.getServletContext(); - } -} diff --git a/src/test/java/org/jvnet/hudson/test/RestartableJenkinsNonLocalhostRule.java b/src/test/java/org/jvnet/hudson/test/RestartableJenkinsNonLocalhostRule.java deleted file mode 100644 index 4ef027e214..0000000000 --- a/src/test/java/org/jvnet/hudson/test/RestartableJenkinsNonLocalhostRule.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2017, Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.jvnet.hudson.test; - -import org.junit.runner.Description; - -/** - * @author Scott Hebert - * - */ -public class RestartableJenkinsNonLocalhostRule extends RestartableJenkinsRule { - private final int port; - - public RestartableJenkinsNonLocalhostRule(int port) { - this.port = port; - } - - @Override - protected JenkinsRule createJenkinsRule(Description description) { - return new JenkinsRuleNonLocalhost(port); - } -} diff --git a/test-in-k8s-pvc.yaml b/test-in-k8s-pvc.yaml deleted file mode 100644 index 5f645561d2..0000000000 --- a/test-in-k8s-pvc.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: m2 -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 10Gi diff --git a/test-in-k8s.sh b/test-in-k8s.sh deleted file mode 100755 index eea1c48f5c..0000000000 --- a/test-in-k8s.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash -set -euxo pipefail -function cleanup() { - kubectl describe pod -} -trap cleanup EXIT - -kubectl get ns kubernetes-plugin-test || kubectl create ns kubernetes-plugin-test -kubectl get ns kubernetes-plugin-test-overridden-namespace || kubectl create ns kubernetes-plugin-test-overridden-namespace -kubectl config set-context --current --namespace=kubernetes-plugin-test -port_offset=$RANDOM -http_port=$((2000 + port_offset)) -tcp_port=$((2001 + port_offset)) -kubectl delete --ignore-not-found --now pod jenkins -if ${MOUNT_M2:-false} -then - m2_volume='hostPath: {"path": "/m2"}' -else - m2_volume='persistentVolumeClaim: {"claimName": "m2"}' - kubectl apply -f test-in-k8s-pvc.yaml -fi -sed "s/@HTTP_PORT@/$http_port/g; s/@TCP_PORT@/$tcp_port/g; s#@M2_VOLUME@#$m2_volume#g" < test-in-k8s.yaml | kubectl apply -f - -kubectl wait --for=condition=Ready --timeout=15m pod/jenkins -if [[ -v WORKSPACE_TMP ]] -then - # Copy temporary split files - tar cf - "$WORKSPACE_TMP" | kubectl exec -i jenkins -- tar xf - -fi -# Copy plugin files -kubectl exec jenkins -- mkdir /checkout -tar cf - pom.xml .mvn src | kubectl exec -i jenkins -- tar xf - -C /checkout -kubectl exec jenkins -- \ - mvn \ - -B \ - -ntp \ - -f /checkout \ - -DconnectorHost=0.0.0.0 \ - -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 \ - "$@" -kubectl exec jenkins -- sh -c 'fgrep skipped /checkout/target/surefire-reports/*.xml' || : diff --git a/test-in-k8s.yaml b/test-in-k8s.yaml deleted file mode 100644 index 8e63fc7843..0000000000 --- a/test-in-k8s.yaml +++ /dev/null @@ -1,106 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: jenkins ---- -apiVersion: v1 -kind: Pod -metadata: - name: jenkins - labels: - app: jenkins -spec: - serviceAccountName: jenkins - containers: - - name: jenkins - image: maven:3.9.8-eclipse-temurin-17 - command: - - sleep - args: - - infinity - ports: - - containerPort: @HTTP_PORT@ - - containerPort: @TCP_PORT@ - volumeMounts: - - name: m2 - mountPath: /root/.m2 - volumes: - - name: m2 - @M2_VOLUME@ - nodeSelector: - kubernetes.io/os: linux ---- -apiVersion: v1 -kind: Service -metadata: - name: jenkins -spec: - selector: - app: jenkins - ports: - - name: http - port: @HTTP_PORT@ - targetPort: @HTTP_PORT@ - protocol: TCP - - name: agent - port: @TCP_PORT@ - targetPort: @TCP_PORT@ - protocol: TCP ---- -kind: ClusterRole -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: jenkins -rules: -- apiGroups: [""] - resources: ["namespaces"] - verbs: ["create","delete","get","list","patch","update","watch"] -- apiGroups: [""] - resources: ["pods"] - verbs: ["create","delete","deletecollection","get","list","patch","update","watch"] -- apiGroups: [""] - resources: ["pods/exec"] - verbs: ["create","delete","get","list","patch","update","watch"] -- apiGroups: [""] - resources: ["pods/log"] - verbs: ["get","list","watch"] -- apiGroups: [""] - resources: ["pods/eviction"] - verbs: ["create"] -- apiGroups: [""] - resources: ["events"] - verbs: ["watch"] -- apiGroups: [""] - resources: ["nodes"] - verbs: ["list","get","patch","update"] # KubernetesPipelineRJRTest.restartDuringPodLaunch -- apiGroups: [""] - resources: ["secrets"] - verbs: ["create","delete","get","list","patch","update","watch"] -- apiGroups: [""] - resources: ["serviceaccounts"] - verbs: ["get"] -- apiGroups: ["apps"] - resources: ["deployments"] # KubernetesPipelineTest#cascadingDelete - verbs: ["create","delete","get","list","patch","update","watch"] -- apiGroups: ["extensions"] - resources: ["deployments"] # ditto - verbs: ["create","delete","get","list","patch","update","watch"] -- apiGroups: ["apps"] - resources: ["replicasets"] # ditto - verbs: ["create","delete","deletecollection","get","list","patch","update","watch"] -- apiGroups: [""] - resources: ["persistentvolumeclaims"] # KubernetesPipelineTest#dynamicPVC - verbs: ["create","delete","get","list","patch","update","watch"] ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: jenkins -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: jenkins -subjects: -- kind: ServiceAccount - name: jenkins - namespace: kubernetes-plugin-test