Skip to main content

composition-dynamic-controller

The composition-dynamic-controller is an operator that is instantiated by the core-provider to manage the Custom Resources whose Custom Resource Definition is generated by the core-provider.

Summary

Architecture

composition-dynamic-controller architecture

Workflow

composition-dynamic-controller State Diagram

Composition Dynamic Controller (CDC) & Chart Inspector: Secure Helm Lifecycle Management

The Composition Dynamic Controller (CDC) is a specialized Kubernetes operator that orchestrates the end-to-end lifecycle of Krateo compositions. Acting as the reconciliation engine for Composition custom resources, it bridges declarative application definitions with Helm’s packaging system through intelligent automation. The Chart Inspector serves as its "safety advisor," enabling proactive decision-making via dry-run analysis.

Core CDC Workflow (with Chart Inspector Integration)

  1. Reconciliation Trigger

    • Watches for changes to Composition CRs or Helm chart versions.
    • Invokes the Chart Inspector to simulate installations/upgrades before execution.
  2. Dry-Run Analysis Phase (Chart Inspector)

    helm install --dry-run=server <chart> --version <ver>  # Returns:
    • Resource Manifest List: All Kubernetes objects (Deployments, CRDs, etc.) the chart would create along with filename to .
    • Dependency Graph: Order of operations (e.g., CRDs before custom resources).
  3. RBAC Auto-Provisioning (CDC)

    • Dynamically generates least-privilege Roles/ClusterRoles based on the Inspector’s output.
    • Ensures the CDC’s service account has exactly the permissions needed—no more, no less.
  4. Atomic Execution (CDC)

    • Proceeds with helm install/upgrade only after successful dry-run and RBAC setup.

Key Capabilities Enabled by This Collaboration

FeatureCDC’s RoleChart Inspector’s Contribution
Version-Sensitive ReconciliationDetects chart version drift; rolls forward/back.Identifies version-specific resource changes during dry-run.
Atomic UpgradesEnsures all-or-nothing upgrades.Pre-flights resource compatibility (e.g., CRD schema changes).
Self-HealingCorrects configuration drift.Provides baseline "desired state" for comparison.
Declarative EnforcementContinuously reconciles actual vs. desired state.Supplies the desired state before cluster changes.
Secure RBACGenerates minimal required permissions.Audits chart manifests for required API operations.

Why This Architecture Matters

  1. Safety Net

    • The Chart Inspector’s dry-run prevents "helm surprises" (e.g., undeclared CRD creations or namespace pollution).
    • Example: Blocks a chart upgrade if the new version requires a ClusterRole the CDC isn’t authorized to manage.
  2. GitOps Compliance

    • The CDC enforces declarative intent by reconciling against the dry-run’s output, not just Helm’s last-applied state.
    • Self-healing kicks in if manual changes violate the composition’s definition.
  3. Multi-Tenancy Ready

    • RBAC is scoped per-composition, isolating teams/projects.
    • The Inspector’s resource listing ensures no cross-tenant leakage (e.g., a composition can’t create resources in forbidden namespaces).

Real-World Example: Handling a Breaking Chart Change

  1. Scenario: A Helm chart v1.2.0 introduces a new CustomResourceDefinition (CRD).
  2. CDC+Inspector Flow:
    • Dry-run detects the new CRD and its required API group permissions.
    • CDC creates a ClusterRole granting create/get/list for the CRD.
    • Upgrade proceeds only after the CRD and RBAC are confirmed active.
  3. Result: Zero downtime; no "helm upgrade failed: CRD missing" errors.

Composition Dynamic Controller Values Injection

The composition-dynamic-controller inject labels and values into the installed resources and in the helm chart release values. This values contains informations about the composition resource associated with the helm release. The values are injected in the following way:

Helm Chart Release ValuesInstalled Resources LabelsDescription
global.compositionIdkrateo.io/composition-idThe composition resource uid
global.compositionNamekrateo.io/composition-nameThe composition resource name
global.compositionNamespacekrateo.io/composition-namespaceThe composition resource namespace
global.compositionInstalledVersionkrateo.io/composition-installed-versionThe version of the composition resource installed. This value changes if the chart version is upgraded
global.compositionApiVersionnot injectedThe api version of the composition resource. This values is deprecated but is mainteined for backward compatibility.
global.compositionGroupkrateo.io/composition-groupThe group of the composition resource.
global.compositionResourcekrateo.io/composition-resourceThe plural name of the composition resource.
global.compositionKindkrateo.io/composition-kindThe kind of the composition resource.
global.krateoNamespacekrateo.io/krateo-namespaceThe namespace where Krateo is installed. This value is used to identify the Krateo resources in the cluster.
global.gracefullyPausednot injectedThis value is set to true if the annotation krateo.io/gracefully-paused is set on the composition resource. This value is used to pause the reconciliation of the composition resource only after the value is injected in the helm release values with a successful helm upgrade. Read the paragraph below for more details.

About the gracefullyPaused value

The global.gracefullyPaused value provides a way to gracefully pause both the composition resource and all Krateo resources within its Helm chart.

How it works:

  1. Trigger: Set the annotation krateo.io/gracefully-paused on the composition resource
  2. Activation: The pause takes effect only after the next successful Helm upgrade injects this value into the chart
  3. Scope: Pauses both the composition reconciliation AND any Krateo resources in the chart that respect the krateo.io/paused annotation

Use cases:

  • Graceful pause: Temporarily halt all composition-related activity without resource deletion
  • Coordinated pause: Ensure both the composition and its managed resources pause simultaneously
  • Safe maintenance: Pause operations during maintenance windows

Comparison with krateo.io/paused:

AnnotationScopeWhen it takes effect
krateo.io/gracefully-pausedComposition + chart resourcesAfter next Helm upgrade
krateo.io/pausedComposition onlyImmediately

Example: Use krateo.io/gracefully-paused when you need to pause an entire application stack, or krateo.io/paused for immediate composition-only pausing.

How to include the pause in a resource included in the chart

To include the pause in a resource included in the chart, you can use the krateo.io/paused annotation on the resource. This will ensure that the resource is paused when the composition is paused.

apiVersion: git.krateo.io/v1alpha1
kind: Repo
metadata:
name: {{ include "fireworks-app.fullname" . }}-repo
labels:
{{- include "fireworks-app.labels" . | nindent 4 }}
annotations:
krateo.io/paused: "{{ default false (and .Values.global .Values.global.gracefullyPaused) }}"
spec:
...

Configuration

Operator Env Vars

These enviroment varibles can be changed in the Deployment of the composition-dynamic-controller we need to tweak.

NameDescriptionDefault ValueNotes
COMPOSITION_CONTROLLER_DEBUGdump verbose outputfalse
COMPOSITION_CONTROLLER_WORKERSnumber of workers1
COMPOSITION_CONTROLLER_RESYNC_INTERVALresync interval3m
COMPOSITION_CONTROLLER_GROUPresource api grouppopulated by core-provider
COMPOSITION_CONTROLLER_VERSIONresource api versionpopulated by core-provider
COMPOSITION_CONTROLLER_RESOURCEresource plural namepopulated by core-provider
COMPOSITION_CONTROLLER_SA_NAMEcdc deployment ServiceAccount namepopulated by core-provider
COMPOSITION_CONTROLLER_SA_NAMESPACEcdc deployment ServiceAccount namespacepopulated by core-provider
URL_PLURALSNOT USED from version 0.17.1 - URL to krateo pluraliser servicehttp://snowplow.krateo-system.svc.cluster.local:8081/api-info/namesIgnored from version 0.17.1
URL_CHART_INSPECTORurl to chart inspectorhttp://chart-inspector.krateo-system.svc.cluster.local:8081/
KRATEO_NAMESPACEnamespace where krateo is installedkrateo-system
HELM_REGISTRY_CONFIG_PATHdefault helm config path/tmp
HELM_MAX_HISTORYMax Helm History10
COMPOSITION_CONTROLLER_MAX_ERROR_RETRY_INTERVALThe maximum interval between retries when an error occurs. This should be less than the half of the poll interval.0m
COMPOSITION_CONTROLLER_MIN_ERROR_RETRY_INTERVALThe minimum interval between retries when an error occurs. This should be less than max-error-retry-interval.1m
COMPOSITION_CONTROLLER_METRICS_SERVER_PORTThe port where the metrics server will be listening. If not set, the metrics server is disabled.