jenkinsci / docker-plugin

Jenkins cloud plugin that uses Docker
https://plugins.jenkins.io/docker-plugin/
MIT License
486 stars 322 forks source link

Support --cgroup-parent flag #1056

Closed rrjjvv closed 4 months ago

rrjjvv commented 4 months ago

Resolves #791

This is essentially the same implementation from #792, but adds the requested changes from that PR and other tweaks due to changes in code/links since that time.

Testing done

From my CI environment using this patched plugin...

Configure via groovy:

# cat /opt/jenkins/init.groovy.d/agents.groovy
jenkins = jenkins.model.Jenkins.get()
jenkins.clouds.getByName('LocalCloud').with {
  templates.each { t ->
    t.dockerTemplateBase.cgroupParent = 'jenkins-agents.slice'
  }
}
jenkins.save()

Running agent:

# docker ps --filter label=com.nirima.jenkins.plugins.docker.JenkinsTemplateName --no-trunc -q
57ba50b168d458275826cf364dcb3f8f7c1446dd5eef894fdb8edc19f8e8a528

Verify cgroup hierarchy (v2/systemd):

# find /sys/fs/cgroup/ -name '*57ba50b168d458275826cf364dcb3f8f7c1446dd5eef894fdb8edc19f8e8a528*' -type d
/sys/fs/cgroup/jenkins.slice/jenkins-agents.slice/docker-57ba50b168d458275826cf364dcb3f8f7c1446dd5eef894fdb8edc19f8e8a528.scope
# cat /proc/$(pgrep -f 'java.*remoting' | tail -n1)/cgroup
0::/jenkins.slice/jenkins-agents.slice/docker-57ba50b168d458275826cf364dcb3f8f7c1446dd5eef894fdb8edc19f8e8a528.scope

Submitter checklist

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

Code implementation looks consistent do what has been suggested in #792.