Skip to content

Rupam-It/configmapSyncOperator

Repository files navigation

ConfigMapSync Operator

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.

Features

  • 🔄 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

Prerequisites

  • 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

Quick Start

1. Build the Operator

# Build the Docker image
make docker-build IMG=configmapsync-operator:dev

2. Load Image into KIND Cluster

# 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

3. Deploy to Cluster

# Deploy the operator with all required resources (CRDs, RBAC, Deployment)
make deploy IMG=configmapsync-operator:dev

4. Verify Deployment

# 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

Testing the Operator

1. Create Test Namespaces

kubectl create namespace target-ns-1
kubectl create namespace target-ns-2

2. Create a Source ConfigMap

kubectl create configmap my-config \
  --from-literal=key1=value1 \
  --from-literal=key2=value2 \
  -n default

3. Create ConfigmapSync Resource

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

4. Verify Sync Status

# 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

5. Test Real-time Updates

# 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

6. Check Operator Logs

# 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

Configuration

ConfigmapSync Resource Spec

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)

Status Fields

The operator automatically updates the status with:

  • lastSyncTime: Timestamp of the last successful sync
  • syncedNamespaces: List of namespaces where ConfigMaps were synced

Cleanup

Remove ConfigmapSync Resources

# Delete the ConfigmapSync resource (this will also delete synced ConfigMaps)
kubectl delete configmapsync test-sync -n default

Uninstall the Operator

# Remove the operator deployment
make undeploy

# Remove CRDs
make uninstall

Troubleshooting

Check Operator Status

# 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

Common Issues

  1. Source ConfigMap not found: Ensure the source ConfigMap exists in the specified namespace
  2. Permission errors: The operator needs RBAC permissions to manage ConfigMaps across namespaces
  3. Sync not working: Check the operator logs for reconciliation errors

Development

Local Development

# Generate manifests
make manifests

# Generate code
make generate

# Run tests
make test

# Build for local testing
make docker-build IMG=configmapsync-operator:dev

Available Make Targets

make help  # Show all available make targets

License

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.

About

it is a kubernates operator that can sync config map !

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published