driver/kubernetes: add ownerrefs driver option for owner references#3791
driver/kubernetes: add ownerrefs driver option for owner references#3791abhay1999 wants to merge 2 commits intodocker:masterfrom
Conversation
Add support for setting Kubernetes ownerReferences on the builder Deployment/StatefulSet via a new 'ownerrefs' driver option. This allows the builder to be automatically garbage-collected by Kubernetes when its owning resource (e.g. an ephemeral GitHub Actions runner) is deleted. Usage: docker buildx create --driver kubernetes --driver-opt ownerrefs=apiVersion=actions.github.com/v1alpha1,kind=EphemeralRunner,name=runner-xyz,uid=<uid>,controller=true,blockOwnerDeletion=false Multiple owner references can be specified by separating them with semicolons. Each owner reference supports the following fields: apiVersion, kind, name, uid, controller, blockOwnerDeletion closes docker#2626 Signed-off-by: abhay1999 <abhaychaurasiya19@gmail.com>
driver/kubernetes/factory.go
Outdated
|
|
||
| deploymentOpt.Tolerations = append(deploymentOpt.Tolerations, t) | ||
| } | ||
| case k == "ownerrefs": |
There was a problem hiding this comment.
To avoid inflation of the switch{}, can we rather support an arbitrary yq/jq expression to patch the manfiest?
There was a problem hiding this comment.
Good point. I dropped the bespoke ownerrefs parsing and switched this to a generic manifest-patch driver option instead, so the owner reference case is now just a patch expression applied after the Kubernetes manifests are generated.
That keeps us from growing the switch further and makes the mechanism reusable for other manifest tweaks too.
I also added coverage for the patch path and reran go test ./driver/kubernetes/....
Signed-off-by: abhay1999 <abhaychaurasiya19@gmail.com>
There was a problem hiding this comment.
Maybe use https://github.com/itchyny/gojq to avoid maintaining a new equivalent of jq by ourselves
There was a problem hiding this comment.
Also, please squash the commits and update the PR description
Fixes #2626
Add support for setting Kubernetes ownerReferences on the builder
Deployment/StatefulSet via a new ownerrefs driver option.
This allows the builder to be automatically garbage-collected by
Kubernetes when its owning resource (e.g. an ephemeral GitHub Actions
runner) is deleted, removing the need to manually patch the Deployment
after creation.
Usage:
Multiple owner references can be specified by separating them with
semicolons:
Each owner reference supports the following fields:
apiVersion, kind, name, uid, controller, blockOwnerDeletion
The implementation follows the same parsing pattern as the existing
tolerations driver option (semicolon-separated entries, each with
comma-separated key=value fields).
Changes:
to DeploymentOpt and set it on the Deployment/StatefulSet ObjectMeta
multiple owner refs, and invalid inputs
Signed-off-by: abhay1999 abhaychaurasiya19@gmail.com