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

Run tests locally provisioning in Kind #1567

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions kind-local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This contains the setup to run `mvn test` locally and provisioning build pods in a locally running Kind cluster.

It's basically the same than `test-in-k8s.sh` but the Jenkins instance runs on the host instead of a Kind pod.

`dockerhost.yaml` is a trick to allow pods to contact the Jenkins instance which runs on the host.

Usage:
```shell
./test-local.sh KubernetesPipelineRJRTest#basicPipeline
```

Note that this requires a locally running Kind cluster (defaults are ok, just `kind create cluster`).
15 changes: 15 additions & 0 deletions kind-local/dockerhost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: Endpoints
metadata:
name: dockerhost
subsets:
- addresses:
- ip: @GATEWAY_IP@ # this is the gateway IP in the "kind" docker network
Copy link
Member Author

@amuniz amuniz May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the trick to let agents running in Kind to connect to the controller running in the host.

---
apiVersion: v1
kind: Service
metadata:
name: dockerhost
spec:
clusterIP: None
7 changes: 7 additions & 0 deletions kind-local/test-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euxo pipefail

gateway_ip=$(docker network inspect kind | jq '[.[].IPAM.Config[].Gateway][0]')
sed "s/@GATEWAY_IP@/$gateway_ip/g" < dockerhost.yaml | kubectl apply -f -

mvn -f ../pom.xml test -Dtest="$@" -Djenkins.host.address=dockerhost -Dhudson.TcpSlaveAgentListener.hostName=dockerhost -DconnectorHost=0.0.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 0.0.0.0 would allow connections from anywhere on the same LAN, so if you run tests that do not set up strong authn/authz then anyone in the same coffee shop or whatever could run a build on your controller that gets shell access to your laptop. See https://github.com/jenkinsci/kubernetes-plugin/blob/41b3ef14a5d89693b6ca6e4f85ca9451996fd95f/README.md#integration-tests-with-minikube for example. (Also this setup should be called out in the top-level README.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't the ip of something like docker0 network interface be used instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably.