https://github.com/saswatamcode/configmap-operator
Kubernetes Operator which allows you to update ConfigMaps, based on some external URL/filepath which serves the required data.
https://github.com/saswatamcode/configmap-operator
kubernetes-operator
Last synced: 12 months ago
JSON representation
Kubernetes Operator which allows you to update ConfigMaps, based on some external URL/filepath which serves the required data.
- Host: GitHub
- URL: https://github.com/saswatamcode/configmap-operator
- Owner: saswatamcode
- License: apache-2.0
- Created: 2021-12-28T10:36:07.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-03T17:41:30.000Z (about 4 years ago)
- Last Synced: 2025-01-25T16:24:00.951Z (about 1 year ago)
- Topics: kubernetes-operator
- Language: Go
- Homepage:
- Size: 145 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# configmap-operator
Kubernetes Operator which allows you to update ConfigMaps, based on some external URL/filepath which serves the required data.
> ⚠ This project is made for learning/experimentation purposes and config can change at any time. Ideally, you can replicate similar functionality via other standard configuration practices.
```bash mdox-exec="configmap-operator run --help"
usage: configmap-operator run []
Launches ConfigMap Operator
Flags:
-h, --help Show context-sensitive help (also try --help-long
and --help-man).
--version Show application version.
--log.level=info Log filtering level.
--log.format=clilog Log format to use.
--metrics="metrics" Endpoint for serving metrics.
--kubeconfig=KUBECONFIG Path to a kubeconfig. Only required if
out-of-cluster.
--master=MASTER The address of the Kubernetes API server.
Overrides any value in kubeconfig. Only required
if out-of-cluster.
--namespace="default" The namespace to watch.
--refresh.interval=10s The interval after which the ConfigMap will be
refreshed.
```
## Getting Started
Example manifests are provided [here](examples/manifests) and are generated with jsonnet!
Spin-up a cluster with [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) and create a `configmap-operator-demo` namespace,
```bash
kubectl apply -f examples/manifests/namespace.yaml
```
Deploy the `configmap-operator`,
```bash
kubectl apply -f examples/manifests/
```
This creates the ConfigMap below with an empty `data` field and the annotations `configmap-operator-src` and `configmap-operator-key` which will be used by the operator to fill in `data`.
```yaml mdox-exec="cat examples/manifests/configmap.yaml"
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
configmap-operator-key: prom.yaml
configmap-operator-src: https://raw.githubusercontent.com/prometheus/prometheus/main/documentation/examples/prometheus.yml
labels:
app.kubernetes.io/component: kubernetes-operator
app.kubernetes.io/instance: configmap-operator
app.kubernetes.io/name: configmap-operator
name: example-prom-config
namespace: configmap-operator-demo
```
The operator is deployed with the Deployment below and its related RoleBinding and ServiceAccount. It finds ConfigMaps with the above annotations and starts updating it periodically (15s)
```yaml mdox-exec="cat examples/manifests/deployment.yaml"
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/component: kubernetes-operator
app.kubernetes.io/instance: configmap-operator
app.kubernetes.io/name: configmap-operator
name: configmap-operator
namespace: configmap-operator-demo
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/component: kubernetes-operator
app.kubernetes.io/instance: configmap-operator
app.kubernetes.io/name: configmap-operator
template:
metadata:
labels:
app.kubernetes.io/component: kubernetes-operator
app.kubernetes.io/instance: configmap-operator
app.kubernetes.io/name: configmap-operator
spec:
containers:
- args:
- run
- --log.level=info
- --log.format=json
- --refresh.interval=15s
- --namespace=$(NAMESPACE)
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: saswatamcode/configmap-operator
imagePullPolicy: IfNotPresent
name: configmap-operator
ports:
- containerPort: 9090
resources: {}
serviceAccount: configmap-operator-sa
```
Watch the ConfigMap for changes and see the `data` field get populated with a `prom.yaml` sample Prometheus config.
```bash
watch kubectl get configmap example-prom-config --namespace configmap-operator-demo -o yaml
```
## Credits
Initially inspired by [cloud-native-skunkworks/cnskunkworks-operator](https://github.com/cloud-native-skunkworks/cnskunkworks-operator)!