A Kubernetes operator that automatically syncs ConfigMaps between different namespaces. This operator watches for ConfigmapSync
custom resources and ensures that specified ConfigMaps are replicated across target namespaces.
- 🔄 Automatic Sync: Syncs ConfigMaps from source namespace to multiple target namespaces
- ⏱️ Configurable Intervals: Set custom sync intervals (default: 30s)
- 🏷️ Smart Labeling: Automatically labels synced ConfigMaps for easy identification
- 🧹 Cleanup: Automatically removes synced ConfigMaps when the operator is deleted
- 📊 Status Tracking: Tracks sync status and last sync time
- Go version v1.23.0+
- Docker version 17.03+
- kubectl version v1.11.3+
- KIND (for local development) or access to a Kubernetes cluster
- Make
# Build the Docker image
make docker-build IMG=configmapsync-operator:dev
# Load the image into your KIND cluster
kind load docker-image configmapsync-operator:dev --name operator-dev
Note: Replace operator-dev
with your actual KIND cluster name if different
# Deploy the operator with all required resources (CRDs, RBAC, Deployment)
make deploy IMG=configmapsync-operator:dev
# Check if the operator pod is running
kubectl get pods -A | grep configmapsync
You should see something like:
configmapsyncoperator-system configmapsyncoperator-controller-manager-xxxxx 1/1 Running 0 30s
kubectl create namespace target-ns-1
kubectl create namespace target-ns-2
kubectl create configmap my-config \
--from-literal=key1=value1 \
--from-literal=key2=value2 \
-n default
kubectl apply -f - <<EOF
apiVersion: sync.local.dev/v1
kind: ConfigmapSync
metadata:
name: test-sync
namespace: default
spec:
sourceConfigmap: my-config
sourceNamespace: default
targetNamespaces:
- target-ns-1
- target-ns-2
syncInterval: "30s"
EOF
# Check the ConfigmapSync status
kubectl get configmapsync -n default
kubectl describe configmapsync test-sync -n default
# Verify ConfigMaps in target namespaces
kubectl get configmaps -n target-ns-1
kubectl get configmaps -n target-ns-2
# Update the source ConfigMap
kubectl patch configmap my-config -n default \
--type='merge' \
-p='{"data":{"key3":"value3"}}'
# Wait a few seconds and check if changes are synced
kubectl get configmap my-config -n target-ns-1 -o yaml
# Get the operator pod name
POD_NAME=$(kubectl get pods -n configmapsyncoperator-system -l app.kubernetes.io/name=configmapsyncoperator -o jsonpath='{.items[0].metadata.name}')
# View logs
kubectl logs $POD_NAME -n configmapsyncoperator-system --tail=20
apiVersion: sync.local.dev/v1
kind: ConfigmapSync
metadata:
name: my-sync
namespace: default
spec:
sourceConfigmap: "config-to-sync" # Name of source ConfigMap
sourceNamespace: "source-namespace" # Namespace of source ConfigMap
targetNamespaces: # List of target namespaces
- "target-ns-1"
- "target-ns-2"
syncInterval: "30s" # Optional: sync interval (default: 30s)
The operator automatically updates the status with:
lastSyncTime
: Timestamp of the last successful syncsyncedNamespaces
: List of namespaces where ConfigMaps were synced
# Delete the ConfigmapSync resource (this will also delete synced ConfigMaps)
kubectl delete configmapsync test-sync -n default
# Remove the operator deployment
make undeploy
# Remove CRDs
make uninstall
# Check if operator is running
kubectl get pods -n configmapsyncoperator-system
# Check operator logs
kubectl logs -n configmapsyncoperator-system -l app.kubernetes.io/name=configmapsyncoperator --tail=50
- Source ConfigMap not found: Ensure the source ConfigMap exists in the specified namespace
- Permission errors: The operator needs RBAC permissions to manage ConfigMaps across namespaces
- Sync not working: Check the operator logs for reconciliation errors
# Generate manifests
make manifests
# Generate code
make generate
# Run tests
make test
# Build for local testing
make docker-build IMG=configmapsync-operator:dev
make help # Show all available make targets
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.