KVM labels-injector is a lightweight Kubernetes controller that reconciles Pod resources and injects predefined labels taken from the Node each Pod is scheduled on.
This repository contains the controller source, Kubernetes manifests (kustomize), and a Helm chart.
- Go 1.23+ (for building from source)
- Docker (if you want to build and push container images)
- kubectl
- Access to a Kubernetes cluster (v1.11.3+ should work; this project uses controller-runtime tooling)
- make (GNU make recommended)
- Build the controller binary:
make build-allThe built binary will be placed at build/manager.
- Install the binary locally (to /usr/local/bin by default):
sudo make install- Generate Kubernetes manifests (deepcopy, CRDs, webhooks):
make generateThis will run controller-gen and place generated CRD artifacts under config/crd.
- Produce Helm chart from kustomize (optional):
make helm-chartsThis uses helmify to convert the kustomize output into a Helm chart under charts/labels-injector.
make build-all— build the manager binary (output:build/manager).make install— installbuild/managerto$(PREFIX)/bin(defaults to/usr/local/binon macOS).make generate— generate CRDs and deepcopy code usingcontroller-gen.make helm-charts— generate Helm chart from kustomize output withhelmify.make check— run unit tests, coverage and static checks (requires some tools).make tidy-deps— rungo mod tidyandgo mod verify.make goimports— rungoimportsover the repo.make clean— remove build artifacts.
Some make targets automatically install required tools if missing (see the top of the Makefile). In CI you may prefer installing tools via your package manager rather than letting the Makefile install them.
- Build the binary locally:
make build-all- Build a container image (example):
docker build -t <registry>/labels-injector:<tag> .- Push the image:
docker push <registry>/labels-injector:<tag>- Update the deployment manifest or Helm values to use the pushed image and deploy to your cluster.
Tips: you can use kind load docker-image for local testing with kind clusters instead of pushing to a remote registry.
There are two supported deployment workflows: kustomize-based manifests (recommended for dev/test) and the Helm chart.
Kustomize (manifests)
- Generate code and CRDs (if you changed the API code):
make generate- Apply the manifests (example using the
config/defaultoverlay):
kubectl apply -k config/default- If you changed the image, update the deployment (for example):
kubectl -n <namespace> set image deployment/labels-injector manager=<registry>/labels-injector:<tag>Helm
- Generate the Helm chart (optional):
make helm-charts- Install using Helm:
helm install labels-injector charts/labels-injector --namespace <namespace> --create-namespace- To upgrade after building a new image or chart:
helm upgrade labels-injector charts/labels-injector --namespace <namespace>Notes on configuration
- The
config/directory contains kustomize overlays used for generating manifests. The default overlay (config/default) is a good starting point for a simple install. - RBAC, TLS/webhook configuration, metrics Service and ServiceAccount manifests are included in
config/and in the Helm chart templates.
You can test the controller locally against a Kubernetes API using envtest (used by controller-runtime) — the project Makefile knows how to install setup-envtest and run tests that use it. To run the unit tests and generate a coverage report:
make build/cover.out
make build/cover.htmlcontroller-gennot found: runmake install-controller-genor install it manually (go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest).helmifymissing formake helm-charts: install it (go install github.com/arttor/helmify/cmd/helmify@latest) or install Helm and use the included chart directly.- Image does not update in cluster: make sure you updated the deployment image or the Helm values and redeployed (see commands above). If using immutable image tags, bump the tag.
Contributions are welcome. Please follow the repository conventions and run make goimports and make run-golangci-lint before opening a PR.
This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.
If you find any bug that may be a security problem, please follow our instructions at in our security policy on how to report it. Please do not create GitHub issues for security-related doubts or problems.
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.
Copyright 2025.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.