docker / docker/buildx

Feature Request - Add Support for Owner References in Kubernetes Driver

Open
#2,626 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/driver/kubernetes help wanted kind/enhancement
Dominant language
Go
Stars
4.5k
Forks
682
Avg merge
2d 14h
Merged PRs (30d)
29

Description

Description

Hello,

I would like to have the ability to specify Kubernetes Owner References via the Docker Buildx CLI when using the Kubernetes driver. This feature will enhance the integration between Docker Buildx and Kubernetes, allowing resources created during the build process (e.g., Pods, Deployments) to automatically adopt ownership lifecycle policies.

Currently, Docker Buildx allows specifying a variety of options and configurations when using the Kubernetes driver. However, a critical lifecycle management feature is missing: the ability to set ownerReferences on Kubernetes resources like Pods directly through the Buildx CLI.

CLI and Driver Enhancements:

  • Provide new --driver-opt options to specify ownerReferences.
  • Allow users to pass owner reference details (e.g., apiVersion, kind, name, uid, controller, blockOwnerDeletion).

Use Case:
This feature is particularly useful for integrating Docker Buildx with ephemeral GitHub Actions runners or other resources that have dynamic lifecycles. For instance, in CI/CD environments, deployments or Pods created as a part of the build process should be cleaned up automatically when the controlling resource is deleted.

Current Manual Process:
Currently, we are manually adding the owner reference to a Buildx builder deployment to a runner. See an example:

> kubectl patch deployment builder-2f073425-0441-48bc-8ed2-2d8a286158001 --type='json' -p='[{"op": "replace", "path": "/metadata/ownerReferences", "value":[{"apiVersion": "actions.github.com/v1alpha1", "kind": "EphemeralRunner", "name": "large-dind-spot-rjz82-runner-4w7sp", "uid": "b636330d-26b7-417a-8464-c2641438feed", "controller": true, "blockOwnerDeletion": false}]}]'

> kubectl get ephemeralrunner large-dind-spot-rjz82-runner-4w7sp
Error from server (NotFound): ephemeralrunners.actions.github.com "large-dind-spot-rjz82-runner-4w7sp" not found

> kubectl get deployment builder-2f073425-0441-48bc-8ed2-2d8a286158001
Error from server (NotFound): deployments.apps "builder-2f073425-0441-48bc-8ed2-2d8a286158001" not found

This ensures that when the runner is deleted, the builder is deleted as well. This works much better than running the cleanup at the end of a GitHub Actions job since there are cases where a runner will exit prematurely and never actually run the builder cleanup at the end of a job.

Adding an owner reference ensures the builder deployment will be a part of the GitHub Actions runner lifecycle in Kubernetes.

Thank You

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names the Kubernetes driver and Buildx CLI but no files or tests; start by tracing how the driver's --driver-opt values are parsed and how Kubernetes resources are created. Define a supported owner-reference option covering the listed fields, then verify that resources created by the driver receive the requested metadata and lifecycle behavior described in the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go, kubernetes
Domain
cli, devops, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.