#7105·kubevela

[LFX Mentorship] Introduce CRD-based Config Management (`config.oam.dev/v1alpha1`) with server-side validation

Author: Chaitanyareddy0702Created Apr 28, 2026Updated Sep 29, 2026
Labelsprogram/lfx

What would you like to be added?

Introduce a proper Kubernetes API group, config.oam.dev/v1alpha1, with two new CRDs — ConfigTemplate and Config — backed by controllers and validating webhooks. This replaces the current pattern of storing templates and configs as labeled ConfigMaps and Secrets, while preserving full backward compatibility.

yaml
# Today (still works after this change)
kind: ConfigMap
metadata:
  name: config-template-image-registry
  labels:
    config.oam.dev/catalog: velacore-config

# After this change
apiVersion: config.oam.dev/v1alpha1
kind: ConfigTemplate
metadata:
  name: image-registry
spec:
  template: |
    # CUE template
    ...
---
apiVersion: config.oam.dev/v1alpha1
kind: Config
metadata:
  name: my-registry
spec:
  templateRef:
    name: image-registry
  propertiesFrom:
    secretRef:
      name: my-registry-credentials
      key: properties

Why is this needed?

KubeVela's Config Management today stores ConfigTemplates as labeled ConfigMaps (config-template-* prefix) and Configs as labeled Secrets. This has three real problems:

  1. No proper Kubernetes API types. kubectl get configs returns nothing meaningful. There's no schema for users, no discoverability, no kubectl explain, no integration with kubectl plugins or GitOps tooling.

  2. All validation runs client-side. CUE schema checks and template.validation.$returns run in the vela CLI. Configs created through any other path — workflow steps, VelaUX, direct kubectl apply of a Secret — bypass validation entirely. The same template enforces different rules depending on entry point.

  3. No native sensitive-property handling. The current model stores property values directly in Secrets, which conflates "the resolved/materialized output" with "the user-supplied input."

Proposal

1. New API group config.oam.dev/v1alpha1

Two CRDs, defined in apis/config.oam.dev/v1alpha1/:

go
type ConfigTemplateSpec struct {
    Template    string `json:"template"`             // CUE template
    Scope       string `json:"scope,omitempty"`      // "system" | "namespace"
    Sensitive   bool   `json:"sensitive,omitempty"`
    Alias       string `json:"alias,omitempty"`
    Description string `json:"description,omitempty"`
}

type ConfigSpec struct {
    TemplateRef    *ConfigTemplateReference  `json:"templateRef,omitempty"`
    Properties     *runtime.RawExtension     `json:"properties,omitempty"`     // non-sensitive only
    PropertiesFrom *PropertiesReference      `json:"propertiesFrom,omitempty"` // for sensitive values
    Alias          string                    `json:"alias,omitempty"`
    Description    string                    `json:"description,omitempty"`
}

Sensitive values are never stored in the CRD. Users provide a propertiesFrom.secretRef pointing at an existing Secret; the controller reads it at reconcile time.

2. Controllers (event-driven, controller-runtime)

  • ConfigTemplateReconciler — parses the CUE template, extracts an OpenAPI schema, writes it to status.schema.
  • ConfigReconciler — loads the referenced template (CRD first, falls back to legacy ConfigMap), loads properties (inline or from Secret), evaluates the CUE template, and materializes the output Secret with an ownerRef pointing at the Config so deletion garbage-collects cleanly.

Both reconcilers are purely event-driven (no RequeueAfter), matching the existing ComponentDefinition/TraitDefinition pattern.

3. Validating webhooks

Move the validation that currently runs client-side in the CLI into admission webhooks:

Validation Today After
Properties match CUE schema CLI (script.ValidatePropertiesWithCueX) Webhook
Custom template.validation.$returns CLI (factory.go) Webhook
properties and propertiesFrom mutual exclusivity Not enforced Webhook
ConfigTemplate CUE syntax CLI Webhook

This ensures every entry point (CLI, workflow step, VelaUX, raw kubectl apply) enforces the same rules with the same error messages.

4. Backward compatibility — dual-read, single-write

  • ConfigReconciler reads both ConfigTemplate CRDs and legacy config-template-* ConfigMaps (CRD priority).
  • Old CLI versions continue to write ConfigMaps/Secrets directly and continue to work.
  • Addons that install ConfigMap-based templates are unaffected.
  • New CLI versions write the new CRDs.
  • A future migration tool (out of scope for this issue) can convert legacy ConfigMaps → ConfigTemplate CRDs.

5. Updated CLI and workflow provider

vela config-template apply/list/show/delete and vela config create/list/delete switch to operating on the new CRDs. The workflow config provider creates Config CRDs instead of calling the factory directly. Both fall back to the legacy code path if the CRD API is unavailable.

Verification plan

  • Unit tests: DeepCopy and serialization round-trip for the new types.
  • envtest controller tests: ConfigTemplate produces schema in status; Config materializes a Secret; legacy ConfigMap fallback resolves correctly; deletion of a Config GCs the Secret.
  • Webhook tests: valid Configs admitted; invalid CUE properties denied with field-level errors; invalid CUE templates denied; mutual exclusivity of properties / propertiesFrom enforced.
  • Backward compatibility: old CLI continues to create Secret-based configs without disruption; new controller resolves old ConfigMap-based templates.
  • Manual: kubectl get configtemplates -n vela-system shows addon-installed templates; kubectl describe config my-registry shows phase and template ref.

Out of scope (potential follow-ups)

  • Migration tool for ConfigMap → ConfigTemplate CRDs.
  • Deprecation timeline for the legacy ConfigMap-based storage.
  • Multi-cluster distribution changes — Phase 1 keeps the existing Application-based mechanism unchanged.