cmstate-injector-operator
is a Kubernetes operator that simplifies the management of ConfigMaps by dynamically creating them based on the specifications defined in Custom Resource Definitions (CRDs). The operator focuses on the interaction between CMTemplate
and CMState
CRDs, offering a streamlined approach to ConfigMap management in a Kubernetes cluster.
-
CMTemplate CRD: Define a template for ConfigMaps using the
CMTemplate
CRD. This includes specifying annotations for template replacement values. -
CMState CRD: Track the usage of ConfigMaps by Pods through the
CMState
CRD. Maintain an audience list to identify Pods utilizing the created ConfigMap. -
Reconcile Loop: The operator performs reconciliation for
CMState
andCMTemplate
CRDs, ensuring that the ConfigMap state aligns with the desired specifications. -
Mutating Webhook: Triggered on Pod creation and deletion, the mutating webhook watches for a specific annotation,
cache.spicedelver.me/cmtemplate
, targeting a valid and createdCMTemplate
.
- Kubernetes cluster
kubectl
configured to access the cluster
Only if modifying this operator by adding more controllers should you need this:
- operator-sdk installed
-
Clone the repository:
git clone https://github.com/your-username/cmstate-injector-operator.git cd cmstate-injector-operator
-
Build and deploy the operator:
make install make deploy
-
Verify the deployment:
kubectl get pods -n <namespace>
Alternatively, you can deploy the operator using the Helm chart located in the charts
directory.
-
Change into the
charts
directory:cd charts
-
Install the Helm chart:
helm install cmstate-injector-operator .
-
Verify the deployment:
kubectl get pods -n <namespace>
-
Define a
CMTemplate
to specify the template for your ConfigMap:apiVersion: cache.spicedelver.me/v1alpha1 kind: CMTemplate metadata: name: cmtemplate-example spec: template: annotationreplace: example-annotation: '{example-regex}' cmtemplate: config.ini: | name = {example-regex} write_to_example = true targetAnnotation: example-target-annotation
-
Create a
CMState
to track ConfigMap usage:apiVersion: cache.spicedelver.me/v1alpha1 kind: CMState metadata: name: cmstate-example namespace: example spec: audience: - kind: Pod name: example cmtemplate: cmtemplate-example target: cmstate-example-configmap
-
Pods that reference the created ConfigMap should include the annotation:
metadata: annotations: cache.spicedelver.me/cmtemplate: cmtemplate-example
Contributions are welcome! Please check out our contribution guidelines for more details.
This project is licensed under the MIT License. See the LICENSE file for details.
- operator-sdk
- Kubernetes community
For any questions or feedback, please reach out to stephen@tollenaar.com.