#7410·kubevela

[LFX Mentorship] Legacy Config migration and backward compatibility for CRD-based Config Management behind feature gates

Author: jerrinfrancisCreated Sep 29, 2026Updated Sep 29, 2026

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:

  • LegacyConfigCompatibility keeps legacy config-templates and configs fully usable next to the new CRs, including the existing commands under --config-mode legacy.
  • AutoMigrateLegacyConfigs lets the controller adopt legacy config-templates and configs into ConfigTemplate and Config CRs 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.

yaml
# vela-core Helm values
featureGates:
  LegacyConfigCompatibility: true   # Beta, default on
  AutoMigrateLegacyConfigs: false   # Alpha, default off

Why 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:

  1. Legacy objects are invisible to the default CLI. Once the CRDs are installed, vela config[-template] list only reads CRs, and vela config[-template] delete reports legacy objects as not found. Configs created by older CLIs, addons or VelaUX can no longer be managed.

  2. There's no way to adopt legacy resources into CRs. Existing config-template-* ConfigMaps and config.oam.dev/catalog=velacore-config Secrets stay in legacy storage forever unless they are recreated by hand.

  3. Nacos only works through the CLI. The imperative factory calls writer.Write for templates with a nacos block, but the Config reconciler doesn't. A Config applied through GitOps reaches Available without ever writing to Nacos.

  4. The workflow provider still writes legacy storage. create-config calls the imperative factory and creates a legacy Secret, not a Config CR.

  5. Upgrade behaviour can't be controlled. The config controllers are always on, so operators can't choose between staying compatible and moving to CRs.

  6. Template scope isn't enforced. ConfigTemplate.spec.scope is stored, printed and copied onto the output Secret's labels, but nothing acts on it. A scope: system template can live in any namespace. A Config can reference a template in any namespace through spec.templateRef.namespace. The webhook and controller then read that template with the controller's own permissions, so anyone allowed to create a Config can render any template in the cluster.

  7. Sensitive data can leak through a non-sensitive template. The output Secret's config.oam.dev/sensitive annotation comes only from the template. A Config that reads credentials through spec.propertiesFrom.secretRef against a non-sensitive template ends up with those credentials copied into input-properties and marked sensitive: "false". That makes them readable through vela config read paths and the read-config workflow step. sensitive can also be flipped from true to false on 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 list and vela config-template list in auto mode merge CRD and legacy results and add a SOURCE column (crd / legacy). If both backends hold the same name, the CR wins and the output says so.
  • show and delete route to whichever backend holds the object. Deleting a legacy config keeps its current behaviour: objects in objects-reference are removed and distribution is recalled.
  • --config-mode legacy keeps working unchanged while LegacyConfigCompatibility is on.
  • The workflow provider's create-config writes a Config CR when the CRD is installed. read-config, list-config and delete-config read 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).

yaml
# 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> becomes ConfigTemplate <name> in the same namespace. template, sensitive, alias, description and the expanded-writer data carry over, and scope: project maps to namespace.
  • Configs: each legacy Secret becomes a Config with the same name and namespace. templateRef comes from the config.oam.dev/type label. Non-sensitive input goes into spec.properties. Sensitive input goes into a <name>-properties Secret owned by the Config and referenced through spec.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 in objects-reference and the distribute-<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 a MigrationConflict Event 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 Config reconciler reads the nacos block from ConfigTemplate.spec.template (or from the legacy ConfigMap's expanded-writer key), renders it with writer.RenderForExpandedWriter, and writes it with writer.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 NacosSynced condition. 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 nacos block.

5. GitOps compatibility

  • Admission doesn't depend on apply order. A Config applied before or together with its ConfigTemplate is admitted and converges once the template exists; schema checks run only when the template is Available.
  • Legacy objects managed by Argo CD or Flux are adopted like any other. Adoption adds only owner references and the migrated-to annotation, doesn't change Secret data, and uses its own field manager, so the GitOps tool sees no diff. An informational MigratedGitOpsManaged Event 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 Config also garbage-collects its Secret.
  • kubectl delete config and GitOps pruning clean up the same objects as vela config delete: the output Secret, outputs objects, 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: system is only valid in vela-system. The ConfigTemplate webhook denies scope: system in any other namespace. CEL can't express this, because it can't read metadata.namespace.

  • Config.spec.templateRef access rules:

    Template Referenced from Allowed
    any scope the same namespace yes
    scope: system (in vela-system) any namespace yes
    scope: namespace another namespace only if a SubjectAccessReview shows the requesting user can get that ConfigTemplate
  • templateRef is already immutable, so an access check when the Config is created covers its whole lifetime.

  • Legacy templates: legacy config-template-* ConfigMaps in vela-system are treated as system scope, 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 to namespace scope.

  • Workflow steps: create-config runs as the controller's service account, which would pass any access check. When AuthenticateApplication is on, the provider runs the SubjectAccessReview for the Application's user (app.oam.dev/username). Otherwise it allows only same-namespace or system templates.

  • 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

  • sensitive can't be turned off. On update, the ConfigTemplate webhook denies sensitive: true → false. A CEL transition rule on ConfigTemplateSpec enforces the same thing where the webhook isn't installed:

    go
    // +kubebuilder:validation:XValidation:rule="!has(oldSelf.sensitive) || !oldSelf.sensitive || (has(self.sensitive) && self.sensitive)",message="sensitive cannot be changed from true to false"
  • Turning sensitive on (false → true) is allowed. Dependent Configs that still carry inline spec.properties move to Error with a message telling the user to switch to propertiesFrom. Their existing Secret is marked sensitive right away.

  • propertiesFrom always means sensitive. A Config that uses spec.propertiesFrom gets an output Secret marked config.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 apply refuses to turn sensitive off on a legacy ConfigMap template, so the same rule holds in legacy storage while LegacyConfigCompatibility is on.

  • Migration keeps sensitive as it is on templates, and marks adopted configs as sensitive when they end up using propertiesFrom.

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: system outside vela-system is denied; each row of the templateRef access table, with the SubjectAccessReview allowed and denied; sensitive true → false is denied; false → true is admitted; a propertiesFrom Config 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 LegacyConfigCompatibility is off; Nacos retry on transient errors; the CEL transition rule on sensitive, with no webhook; dependent Configs going to Error after sensitive is turned on.
  • RBAC e2e: as a non-admin user bound to one namespace, check that a Config referencing a system template is admitted; one referencing a namespace-scoped template in another namespace is denied, then admitted once the user is granted get on it; and a create-config workflow step with AuthenticateApplication on 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:
    1. vela config and vela config-template list, show and delete, with both the old and the new CLI.
    2. Applications that consume these configs keep working, with no Secret churn (same UID and resourceVersion until something is edited).
    3. With migration on, each object is adopted exactly once, and restarting the controller changes nothing.
    4. Nacos content stays the same, and a later edit through the Config CR reaches Nacos.
    5. Downgrading to the old controller works with the legacy objects intact.
  • Nacos e2e: against a standalone nacos/nacos-server container, a Config applied with kubectl alone shows up under the expected dataId and group.
  • GitOps e2e: Argo CD (or Flux) syncs a ConfigTemplate and a Config, 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 featureGates values 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.