[LFX Mentorship] Legacy Config migration and backward compatibility for CRD-based Config Management behind feature gates
Sub-issue of #7105 · Follow-up to #7211
What would you like to be added?
Two controller feature gates that give existing clusters a safe path from the legacy ConfigMap/Secret-based config storage to the config.oam.dev/v1alpha1 CRDs:
LegacyConfigCompatibilitykeeps legacy config-templates and configs fully usable next to the new CRs, including the existing commands under--config-mode legacy.AutoMigrateLegacyConfigslets the controller adopt legacy config-templates and configs intoConfigTemplateandConfigCRs automatically.
The work also brings the controller up to parity with the imperative path for the Nacos expanded writer, and makes sure GitOps-driven configs behave the same as CLI-driven ones. It also closes two API contract gaps, template scope and sensitive handling, before the API ships. After release they would be breaking changes.
# vela-core Helm values
featureGates:
LegacyConfigCompatibility: true # Beta, default on
AutoMigrateLegacyConfigs: false # Alpha, default offWhy is this needed?
#7211 added the CRDs, controllers and webhooks, with migration and upgrade work planned as follow-up before release. On a cluster that already has legacy configs, upgrading today causes these problems:
Legacy objects are invisible to the default CLI. Once the CRDs are installed,
vela config[-template] listonly reads CRs, andvela config[-template] deletereports legacy objects as not found. Configs created by older CLIs, addons or VelaUX can no longer be managed.There's no way to adopt legacy resources into CRs. Existing
config-template-*ConfigMaps andconfig.oam.dev/catalog=velacore-configSecrets stay in legacy storage forever unless they are recreated by hand.Nacos only works through the CLI. The imperative factory calls
writer.Writefor templates with anacosblock, but theConfigreconciler doesn't. AConfigapplied through GitOps reachesAvailablewithout ever writing to Nacos.The workflow provider still writes legacy storage.
create-configcalls the imperative factory and creates a legacy Secret, not aConfigCR.Upgrade behaviour can't be controlled. The config controllers are always on, so operators can't choose between staying compatible and moving to CRs.
Template scope isn't enforced.
ConfigTemplate.spec.scopeis stored, printed and copied onto the output Secret's labels, but nothing acts on it. Ascope: systemtemplate can live in any namespace. AConfigcan reference a template in any namespace throughspec.templateRef.namespace. The webhook and controller then read that template with the controller's own permissions, so anyone allowed to create aConfigcan render any template in the cluster.Sensitive data can leak through a non-sensitive template. The output Secret's
config.oam.dev/sensitiveannotation comes only from the template. AConfigthat reads credentials throughspec.propertiesFrom.secretRefagainst a non-sensitive template ends up with those credentials copied intoinput-propertiesand markedsensitive: "false". That makes them readable throughvela configread paths and theread-configworkflow step.sensitivecan also be flipped fromtruetofalseon a live template, which re-marks every dependent Secret as readable on the next reconcile.
Proposal
1. Feature gates
Both gates are added to pkg/features/controller_features.go, following the existing Legacy* naming for compatibility gates.
| Gate | Stage | Default | Controls |
|---|---|---|---|
LegacyConfigCompatibility |
Beta | true |
Legacy storage stays usable: template fallback to config-template-* ConfigMaps, legacy watches, reads and deletes across both backends, --config-mode legacy |
AutoMigrateLegacyConfigs |
Alpha | false |
The controller adopts legacy templates and configs into CRs |
| Compatibility | Migration | Behaviour |
|---|---|---|
| on | off | Default. Nothing is converted. New writes go to CRs; reads and deletes cover both backends. |
| on | on | Legacy objects are adopted into CRs and kept in place, so older CLIs, VelaUX and addons can still read them. |
| off | on | Full cutover. The legacy fallback and legacy watches are disabled; --config-mode legacy fails with an error that names the gate. |
| off | off | Only valid when no legacy objects exist. Otherwise the controller logs a warning at startup and emits an Event listing the unmanaged objects. |
At startup the controller writes its gate states to the ConfigMap vela-system/kubevela-config-features. The CLI reads it to decide how to behave, and treats compatibility as on when the ConfigMap is missing (older controllers).
2. Backward compatibility — dual-read, dual-delete
vela config listandvela config-template listinautomode merge CRD and legacy results and add aSOURCEcolumn (crd/legacy). If both backends hold the same name, the CR wins and the output says so.showanddeleteroute to whichever backend holds the object. Deleting a legacy config keeps its current behaviour: objects inobjects-referenceare removed and distribution is recalled.--config-mode legacykeeps working unchanged whileLegacyConfigCompatibilityis on.- The workflow provider's
create-configwrites aConfigCR when the CRD is installed.read-config,list-configanddelete-configread both backends. The factory path remains the fallback when the CRD is absent. - The controller runs its legacy ConfigMap template fallback and legacy ConfigMap watch only while the gate is on.
3. Automatic adoption
With AutoMigrateLegacyConfigs on, a leader-elected runnable adopts legacy objects once at startup, and adopts new ones as they appear (for example from older CLIs or addons).
# Before: legacy config (Secret)
apiVersion: v1
kind: Secret
metadata:
name: my-registry
labels:
config.oam.dev/catalog: velacore-config
config.oam.dev/type: image-registry
---
# After: the same Secret, now owned by a Config
apiVersion: config.oam.dev/v1alpha1
kind: Config
metadata:
name: my-registry
labels:
config.oam.dev/created-by: migration
spec:
templateRef:
name: image-registry
propertiesFrom: # sensitive templates only
secretRef:
name: my-registry-properties- Templates:
config-template-<name>becomesConfigTemplate <name>in the same namespace.template,sensitive,alias,descriptionand theexpanded-writerdata carry over, andscope: projectmaps tonamespace. - Configs: each legacy Secret becomes a
Configwith the same name and namespace.templateRefcomes from theconfig.oam.dev/typelabel. Non-sensitive input goes intospec.properties. Sensitive input goes into a<name>-propertiesSecret owned by the Config and referenced throughspec.propertiesFrom, so it never enters the CR. - Adopt in place. The existing Secret gets the Config as its controller owner and keeps its name, UID and data. The first reconcile after adoption must produce an identical Secret, including the default type
/<template-name>. Objects listed inobjects-referenceand thedistribute-<name>Application also become owned by the Config. - Idempotent. Adopted sources are marked with
config.oam.dev/migrated-to: <uid>. If a CR with the same name already exists and wasn't created by migration, the object is skipped and aMigrationConflictEvent is recorded. - Opt-out per object with
config.oam.dev/migrate: "false". - Reporting: Events on each source object, a summary log line, and a metric
kubevela_config_migration_total{result="adopted|skipped|conflict|failed"}. - Rollback: turning the gate off stops new adoption. Legacy objects are never deleted, so downgrading to an older controller keeps working.
4. Nacos expanded writer in the controller
- The
Configreconciler reads thenacosblock fromConfigTemplate.spec.template(or from the legacy ConfigMap'sexpanded-writerkey), renders it withwriter.RenderForExpandedWriter, and writes it withwriter.Write. - The endpoint config (
nacos.endpoint.name) is resolved from either CR-backed or legacy storage. - The controller writes only when the rendered content changes, stores a content hash in status, and reports a
NacosSyncedcondition. Network and 5xx failures requeue with backoff; they aren't treated as terminal errors. - Deleting a Config removes nothing from Nacos, same as the CLI today.
- The ConfigTemplate webhook validates the
nacosblock.
5. GitOps compatibility
- Admission doesn't depend on apply order. A
Configapplied before or together with itsConfigTemplateis admitted and converges once the template exists; schema checks run only when the template isAvailable. - Legacy objects managed by Argo CD or Flux are adopted like any other. Adoption adds only owner references and the
migrated-toannotation, doesn't change Secret data, and uses its own field manager, so the GitOps tool sees no diff. An informationalMigratedGitOpsManagedEvent tells owners to commit the matching CR to git. - Two risks are documented. If git later reapplies legacy data that differs from the rendered output, the controller and the GitOps tool will fight until the CR is committed to git. Deleting a migration-created
Configalso garbage-collects its Secret. kubectl delete configand GitOps pruning clean up the same objects asvela config delete: the output Secret,outputsobjects, and the distribution Application.
6. Template scope and cross-namespace access
The rules below are enforced in the Config and ConfigTemplate webhooks (failurePolicy: Fail). The reconciler repeats the structural checks as a second line of defence.
scope: systemis only valid invela-system. The ConfigTemplate webhook deniesscope: systemin any other namespace. CEL can't express this, because it can't readmetadata.namespace.Config.spec.templateRefaccess rules:Template Referenced from Allowed any scope the same namespace yes scope: system(invela-system)any namespace yes scope: namespaceanother namespace only if a SubjectAccessReview shows the requesting user can getthatConfigTemplatetemplateRefis already immutable, so an access check when the Config is created covers its whole lifetime.Legacy templates: legacy
config-template-*ConfigMaps invela-systemare treated assystemscope, both when the controller falls back to them and when migration adopts them. Today they are used from every namespace, so this keeps existing configs working. Legacy templates in other namespaces map tonamespacescope.Workflow steps:
create-configruns as the controller's service account, which would pass any access check. WhenAuthenticateApplicationis on, the provider runs the SubjectAccessReview for the Application's user (app.oam.dev/username). Otherwise it allows only same-namespace orsystemtemplates.The chart's RBAC stays as it is. The controller still needs to read templates cluster-wide, and the access decision is made per requesting user at admission.
7. Sensitive handling
sensitivecan't be turned off. On update, the ConfigTemplate webhook deniessensitive: true→false. A CEL transition rule onConfigTemplateSpecenforces the same thing where the webhook isn't installed:// +kubebuilder:validation:XValidation:rule="!has(oldSelf.sensitive) || !oldSelf.sensitive || (has(self.sensitive) && self.sensitive)",message="sensitive cannot be changed from true to false"Turning
sensitiveon (false→true) is allowed. Dependent Configs that still carry inlinespec.propertiesmove toErrorwith a message telling the user to switch topropertiesFrom. Their existing Secret is marked sensitive right away.propertiesFromalways means sensitive. AConfigthat usesspec.propertiesFromgets an output Secret markedconfig.oam.dev/sensitive: "true", whatever the template says. Read paths (vela config,read-config,list-config) treat it as sensitive and don't return the input properties.vela config-template applyrefuses to turnsensitiveoff on a legacy ConfigMap template, so the same rule holds in legacy storage whileLegacyConfigCompatibilityis on.Migration keeps
sensitiveas it is on templates, and marks adopted configs as sensitive when they end up usingpropertiesFrom.
Verification plan
- Unit tests: gate wiring and the gate-state ConfigMap; dual-read merge and routing in the CLI; legacy-to-CR mapping for templates and configs, sensitive and non-sensitive; the adoption parity check (identical Secret after the first reconcile); Nacos render and change detection.
- Webhook tests:
scope: systemoutsidevela-systemis denied; each row of thetemplateRefaccess table, with the SubjectAccessReview allowed and denied;sensitivetrue → false is denied; false → true is admitted; apropertiesFromConfig against a non-sensitive template produces a sensitive Secret. - envtest controller tests: startup sweep and event-driven adoption; adopting the same object twice changes nothing; conflict and opt-out handling; fallback and watches off when
LegacyConfigCompatibilityis off; Nacos retry on transient errors; the CEL transition rule onsensitive, with no webhook; dependent Configs going toErroraftersensitiveis turned on. - RBAC e2e: as a non-admin user bound to one namespace, check that a
Configreferencing asystemtemplate is admitted; one referencing anamespace-scoped template in another namespace is denied, then admitted once the user is grantedgeton it; and acreate-configworkflow step withAuthenticateApplicationon applies the same rule to the Application's user. - Upgrade e2e (kind, old image → new image): on the old controller, create a plain config, a sensitive config, a config with
outputs, a distributed config, a Nacos config, a config created by the workflow step, and an addon-shipped template. Upgrade, then under each gate combination check:vela configandvela config-templatelist, show and delete, with both the old and the new CLI.- Applications that consume these configs keep working, with no Secret churn (same UID and resourceVersion until something is edited).
- With migration on, each object is adopted exactly once, and restarting the controller changes nothing.
- Nacos content stays the same, and a later edit through the
ConfigCR reaches Nacos. - Downgrading to the old controller works with the legacy objects intact.
- Nacos e2e: against a standalone
nacos/nacos-servercontainer, aConfigapplied withkubectlalone shows up under the expecteddataIdandgroup. - GitOps e2e: Argo CD (or Flux) syncs a
ConfigTemplateand aConfig, including a Nacos template. The sync is healthy, there's no diff loop after reconcile, pruning removes everything, and an adopted GitOps-managed legacy Secret shows no diff. - Docs: both gates are documented in the Helm chart
featureGatesvalues and in the CLI reference, along with the upgrade and rollback steps.
Out of scope (potential follow-ups)
- VelaUX changes.
- Removing legacy storage, and a deprecation timeline.
Source: kubevela/kubevela