A Kubernetes Mutating Webhook that automatically adds missing labels to Pods.
It acts as a "helpful wizard" – instead of rejecting Pods that are missing the required allow=yes label, it patches the Pod definition to include it.
- Mutating Webhook: Intercepts Pod creation requests.
- JSONPatch: Uses JSON Patch to modify Pod objects on the fly.
- Auto-Labeling: Automatically adds
allow=yesif missing or incorrect. - Secure: Runs over HTTPS with certificates managed by
cert-manager.
- A Kubernetes cluster (Kind, Minikube, GKE, etc.)
kubectlinstalled and configured.cert-managerinstalled in the cluster (required for certificate generation).
Run unit tests:
make testBuild the binary locally:
make buildFirst, build the Docker image. If you are using Kind, you don't need to push to a registry, but you need to load the image.
make docker-build
# If using Kind: kind load docker-image label-guardian:v1Deploy the webhook and manifests:
make deployThis command applies deploy.yaml, which converts:
- Issuer & Certificate: Sets up a self-signed CA and generates a certificate for the webhook.
- Deployment:Deploys the
label-guardianpod. - Service: Exposes the webhook within the cluster.
- MutatingWebhookConfiguration: Registers the webhook with the API server.
Deploy a Pod without the label:
apiVersion: v1
kind: Pod
metadata:
name: test-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpinekubectl apply -f test-pod.yamlCheck the labels:
kubectl get pod test-pod --show-labelsYou should see allow=yes automatically added!
cmd/label-guardian: Main entry point.pkg/webhook: Webhook logic and testing.deploy.yaml: Kubernetes manifests.Makefile: Build automation.