[LFX Mentorship] Introduce CRD-based Config Management (`config.oam.dev/v1alpha1`) with server-side validation
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.
# 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: propertiesWhy 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:
No proper Kubernetes API types.
kubectl get configsreturns nothing meaningful. There's no schema for users, no discoverability, nokubectl explain, no integration with kubectl plugins or GitOps tooling.All validation runs client-side. CUE schema checks and
template.validation.$returnsrun in thevelaCLI. Configs created through any other path — workflow steps, VelaUX, directkubectl applyof a Secret — bypass validation entirely. The same template enforces different rules depending on entry point.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/:
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 tostatus.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 anownerRefpointing at theConfigso 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
ConfigReconcilerreads both ConfigTemplate CRDs and legacyconfig-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/propertiesFromenforced. - 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-systemshows addon-installed templates;kubectl describe config my-registryshows 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.
Source: kubevela/kubevela