Examples
Creation¶
Note
Make sure you have installed the operator. to install it read Installation
Create a ConfigBundle with the desired configuration:
apiVersion: training.k8s.operators.dev/v1
kind: ConfigBundle
metadata:
name: example
spec:
message: "Hello, Kubernetes!"
immutable: false
Apply it to the cluster:
The operator creates the corresponding ConfigMap.
Verify both resources:
The created ConfigMap contains the configured message:
Updates¶
A mutable ConfigBundle can be updated by changing its spec.
For example, change the message:
apiVersion: training.k8s.operators.dev/v1
kind: ConfigBundle
metadata:
name: example
spec:
message: "Updated message"
immutable: false
Apply the updated resource:
The operator updates the managed ConfigMap to reflect the new desired
configuration.
The operator also updates ConfigBundle.status using the resulting
ConfigMap.
Verify both resources:
Immutability¶
A ConfigBundle can make its managed ConfigMap immutable by setting
spec.immutable to true.
apiVersion: training.k8s.operators.dev/v1
kind: ConfigBundle
metadata:
name: example
spec:
message: "Immutable configuration"
immutable: true
After applying the resource:
the managed ConfigMap is created with:
Once the previous ConfigBundle.spec.immutable value is true, subsequent
updates to the spec are reverted to the previous values.
For example, changing:
does not change the existing configuration.
Instead, the operator restores the previous spec values on the
ConfigBundle.
ConfigMap Recovery¶
The operator continuously watches the managed ConfigMap.
If the ConfigMap is deleted while its ConfigBundle still exists, the
operator detects that the managed resource is missing and recreates it from
the current ConfigBundle.spec.
Find the corresponding ConfigMap and delete it, after a little bit of time check its
existence again.
Drift Recovery¶
The operator also detects changes made directly to the managed ConfigMap.
For example, manually modify the message:
The actual ConfigMap now differs from the desired configuration defined by
the ConfigBundle.
The operator's watch loop detects this difference and replaces the ConfigMap with the desired state.
After the next integrity check, the managed ConfigMap contains the original desired message again.
Metadata Synchronization¶
Changes to metadata.labels and metadata.annotations on the
ConfigBundle are propagated to the managed ConfigMap.
For example, add a label:
apiVersion: training.k8s.operators.dev/v1
kind: ConfigBundle
metadata:
name: example
labels:
environment: production
spec:
message: "Hello, Kubernetes!"
immutable: false
Apply the change:
The operator updates the corresponding label on the managed ConfigMap.
The same behavior applies to annotations:
The operator handles adding, changing, and removing labels and annotations.
The metadata of the managed ConfigMap is therefore kept synchronized with the
corresponding metadata changes on the ConfigBundle.