configmap-operator

command module
v0.0.0-...-f868bc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

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.

usage: configmap-operator run [<flags>]

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 and are generated with jsonnet!

Spin-up a cluster with kind and create a configmap-operator-demo namespace,

kubectl apply -f examples/manifests/namespace.yaml

Deploy the configmap-operator,

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.

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)

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.

watch kubectl get configmap example-prom-config --namespace configmap-operator-demo -o yaml 

Credits

Initially inspired by cloud-native-skunkworks/cnskunkworks-operator!

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
extkingpin
Taken from Thanos project.
Taken from Thanos project.
scripts
copyright command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL