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

Conversation

amuniz
Copy link
Member

@amuniz amuniz commented May 31, 2024

The existing test-in-k8s.sh script runs tests in Kind (mvn test in a pod). Sometimes it's convenient to have the controller running locally while still provisioning pods in Kind.

Just in case it's useful for others.

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

The existing `test-in-k8s.sh` script runs tests in Kind (`mvn test` in a
pod). Sometimes it's convenient to have the controller running locally
while still provisioning pods in Kind.
@amuniz amuniz requested a review from a team as a code owner May 31, 2024 11:58
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.

@jglick jglick added the chore Maintenance label May 31, 2024
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

An interesting trick, though kubectl tunnel is probably safer and more portable. What host env did you test this on—Linux with docker-ce-cli from e.g.

deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu   jammy stable

or some other packaging or Docker Desktop on Mac OS X etc.?

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.

@amuniz
Copy link
Member Author

amuniz commented May 31, 2024

What host env did you test this on

Ubuntu (deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu focal stable)

@amuniz
Copy link
Member Author

amuniz commented May 31, 2024

coffee shop

Coffee shops are not for work ;) But yeah...

@jglick
Copy link
Member

jglick commented Jul 25, 2024

Also see jenkinsci/jenkins-test-harness#289 (comment) & JENKINS-73138.

@jglick
Copy link
Member

jglick commented Jul 27, 2024

I successfully prototyped a different approach in #1593 which seems simpler, avoids a special JenkinsRule subclass (an obstacle for the Jetty upgrade effort), and avoids the need to think about low-level network configuration. Please try it out. It works in CI at least, and fine for me on Ubuntu with Kind.

@amuniz
Copy link
Member Author

amuniz commented Jul 30, 2024

Tested #1593 locally and it works as expected. Closing this.

@amuniz amuniz closed this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants