This Go operator watches Moat configuration ConfigMaps and keeps the running pods in sync by forcing a rollout any time the config content changes. It relies on the same Helm labels as the upstream moat-main/helm chart (app.kubernetes.io/name=moat) so it naturally plugs into Helm releases of Moat.
- Reconciles only
ConfigMapobjects labelled withapp.kubernetes.io/name=moat. - Hashes the combined
dataandbinaryDatapayload of the ConfigMap. - Patches every Moat
Deploymentin the same namespace (matching the same label) with the hash stored undermoat.arxignis.com/config-hashin the pod template annotations. - Updating the annotation bumps the ReplicaSet template hash, causing Kubernetes to roll the pods and pick up the new configuration.
main.gobootstraps a controller-runtime manager with health probes and optional namespace scoping.controllers/configmap_controller.gocontains the reconciliation logic and hashing helper.config/holds a kustomize deployment (service account, RBAC, manager deployment). Replaceghcr.io/example/moat-operator:latestwith your published image.
GOOS=linux GOARCH=amd64 go build -o bin/moat-operatorAdjust the target architecture if you are building for another platform.
To containerize:
docker build -t ghcr.io/<org>/moat-operator:latest .
docker push ghcr.io/<org>/moat-operator:latestUpdate config/manager.yaml with the pushed image reference.
kubectl apply -k configThis creates the moat-system namespace, service account, RBAC, and a single replica of the operator.
- Prepare tools – ensure WSL has
docker,kubectl, andkind(orminikube) installed and on$PATH. - Build & load the image – inside WSL build the Linux image and use
kind load docker-image ghcr.io/<org>/moat-operator:latest(or push to a registry reachable by your cluster). - Create a test cluster –
kind create cluster --name moat. - Deploy Moat via Helm – from
moat-main/helm, runhelm install moat ./helm --namespace moat --create-namespace. This produces the ConfigMap and Deployment with the expected labels. - Apply the operator manifests –
kubectl apply -k ../moat-operator/config. - Trigger a config change – edit the Moat ConfigMap (
kubectl edit configmap moat -n moat) or usekubectl patch. - Verify restart – watch the Deployment rollout:
kubectl rollout status deployment/moat -n moatand ensure pod annotationmoat.arxignis.com/config-hashupdates.
The Helm chart already labels both the ConfigMap and Deployment with app.kubernetes.io/name=moat. The operator leans on those labels to discover which objects belong together. When Helm updates the ConfigMap (e.g., via helm upgrade), the operator sees the new data, recalculates the hash, and patches the Deployment so the change propagates without any manual restarts.
