-
Bug
-
Resolution: Unresolved
-
Minor
-
None
Hi,
we see the problem, that Jenkins Slaves are not cleaned up properly when the Jenkins Master is removed from Kubernetes.
We thought about multiply solutions (like a cronjob to clean them up) but we think the best approach would be to allow Kubernetes to clean them up by itself:
https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/
To be able to do so, the ownerReference field for Jenkins Slaves need to point to the Jenkins Master.
In order to use the garbage collector, the master has to be aware of its own UID (or the UID of the stateful set it’s a part of) in the Kubernetes cluster in order to inject that value into the slave templates.
I’ve tried a few approaches in getting this value. As the master is aware of its own URL, you can try to use the ingress resource and follow that chain, but that proved slow and unreliable.
A more reliable way to get the value is to inject it as an environment variable at deployment-time, but that would make the plugin dependent on whatever method you use to deploy, which is not ideal.
We’ve implemented similar functionality through a helm delete hook, which we’d added to the Jenkins stable helm chart.