Documentation
¶
Overview ¶
Package config implements the INI configuration rendering pipeline for CobaltCore operators. It provides pure functions for rendering structured configuration data into INI format, merging defaults, injecting secrets, and configuring oslo.policy integration.
Feature: CC-0004
Index ¶
- Constants
- func CreateImmutableConfigMap(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) (string, error)
- func InjectOsloPolicyConfig(config map[string]map[string]string, policyFilePath string) map[string]map[string]string
- func InjectSecrets(config map[string]map[string]string, secrets map[string]string) map[string]map[string]string
- func MergeDefaults(userConfig, defaults map[string]map[string]string) map[string]map[string]string
- func PruneImmutableConfigMaps(ctx context.Context, c client.Client, owner client.Object, ...) error
- func RenderINI(sections map[string]map[string]string) string
Constants ¶
const ConfigBaseLabelKey = "forge.c5c3.io/config-base"
ConfigBaseLabelKey is the label key applied to immutable ConfigMaps created by CreateImmutableConfigMap, identifying the base name that generated them. PruneImmutableConfigMaps uses this label as a server-side selector to avoid listing all ConfigMaps in the namespace (CC-0077).
Variables ¶
This section is empty.
Functions ¶
func CreateImmutableConfigMap ¶
func CreateImmutableConfigMap(ctx context.Context, c client.Client, scheme *runtime.Scheme, owner client.Object, baseName, namespace string, data map[string]string) (string, error)
CreateImmutableConfigMap creates an immutable ConfigMap with a content-hash suffix appended to the base name. The hash ensures configuration changes result in new ConfigMap names, triggering pod restarts. It returns the actual name of the created ConfigMap (with hash suffix) (CC-0005).
Note: Old ConfigMaps with the same baseName but different hash suffixes accumulate during the owner's lifetime since GC only removes them when the owner is deleted. Callers (reconcilers) should prune obsolete ConfigMaps after rolling updates complete to avoid unbounded growth.
func InjectOsloPolicyConfig ¶
func InjectOsloPolicyConfig(config map[string]map[string]string, policyFilePath string) map[string]map[string]string
InjectOsloPolicyConfig returns a config map with oslo_policy configuration injected. If policyFilePath is non-empty, it creates a deep copy of the input map (via MergeDefaults), ensures the oslo_policy section exists, sets the policy_file key, and returns the copy without mutating the input. If policyFilePath is empty, it returns the original config reference unchanged (no copy is made).
func InjectSecrets ¶
func InjectSecrets(config map[string]map[string]string, secrets map[string]string) map[string]map[string]string
InjectSecrets replaces {{SECRET_KEY}} placeholders in config values with the corresponding values from the secrets map. Returns a new map without mutating the input config. Unresolved placeholders are left as-is.
func MergeDefaults ¶
MergeDefaults merges user-provided config with operator defaults. User values take precedence over defaults. Returns a new map without mutating the inputs.
func PruneImmutableConfigMaps ¶
func PruneImmutableConfigMaps(ctx context.Context, c client.Client, owner client.Object, baseName, namespace, currentName string, retain int) error
PruneImmutableConfigMaps deletes stale immutable ConfigMaps that were previously created by CreateImmutableConfigMap. It retains the newest `retain` historical ConfigMaps (by CreationTimestamp) plus the currently active one identified by currentName. This prevents unbounded accumulation of immutable ConfigMaps across reconcile cycles.
Known limitation: ConfigMaps created before the ConfigBaseLabelKey label was introduced (CC-0077) lack the label and are invisible to the server-side selector used by this function. These pre-existing ConfigMaps will not be pruned but are bounded in number (no new unlabeled ConfigMaps are created after the upgrade) and will be garbage-collected by Kubernetes when the owning CR is deleted, since they carry a controller owner reference.
func RenderINI ¶
RenderINI renders a map of INI sections into an INI format string. Sections are sorted alphabetically for deterministic output. Keys within each section are sorted alphabetically. Section names must be non-empty; an empty section name produces "[]", which is invalid INI. Callers are responsible for ensuring non-empty section names before calling this function.
Types ¶
This section is empty.