Skip to content

Watches Kubernetes namespaces and applies pre-configured YAML when specific label is applied to a namespace.

License

Notifications You must be signed in to change notification settings

mchmarny/ns-label-operator

Repository files navigation

ns-label-operator

Release Head Go Report Card GitHub go.mod Go version codecov

Watches Kubernetes namespaces and applies pre-configured YAML when specific label is applied to a namespace. Helpful in configuring common roles, trace forwarders, or any other common settings on a new namespace (e.g. Dapr.io role, role binding, and trace exporter).

Installation Options

Usage

To illustrate the usage, let's assume you want to apply custom trace export configuration to any namespace in your cluster that's labeled with the dapr-demo=true label.

To start, create a ConfigMap to hold all the deployments (YAML files) that you need to create the necessary configuration:

This example uses default namespace but you can deploy the ns-label-operator to any existing namespace in your cluster.

kubectl create secret generic demo-ns-config \
    --from-file manifests/role.yaml \
    --from-file manifests/exporter.yaml \
    -n default

Next, add the Helm repo:

helm repo add ns-label-operator https://charts.chmarny.dev
helm repo update

Then, deploy the ns-label-operator into your cluster to start monitoring for specific label:

This example uses Helm chart, See Installation Options for other ways to use ns-label-operator

helm install dapr-demo-operator ns-label-operator/ns-label-operator \
  --set triggerLabel=dapr-demo \
  --set manifestConfigMap=demo-ns-config \
  -n default

Make sure that the ConfigMap and ns-label-operator are deployed into the same namespace.

Now whenever someone labels namespace in your cluster with with the dapr-demo label:

kubectl label ns example-namespace dapr-demo=true

All the files loaded into the demo-ns-config ConfigMap will be applied in that namespace.

Note, you can remove trigger label to prevent the trigger from firming again on that namespace but that will not undo the already created resources.

kubectl label ns example-namespace dapr-demo-

Cleanup

kubectl delete secret demo-ns-config
helm uninstall dapr-demo-operator

Disclaimer

This is my personal project and it does not represent my employer. While I do my best to ensure that everything works, I take no responsibility for issues caused by this code.

License

This software is released under the MIT

About

Watches Kubernetes namespaces and applies pre-configured YAML when specific label is applied to a namespace.

Topics

Resources

License

Stars

Watchers

Forks