[Bug] vela/velaconfig reader: Secret identity, output namespaces and fallback keys
Is there an existing issue for this?
- I have searched the existing issues
Affected area
CUE providers (vela/velaconfig), Config CRD (config.oam.dev/v1alpha1)
KubeVela version
master only. The reader arrived with SourceDefinition (#7371) and the Config CRD with #7211; neither is in a release yet, so this can be fixed before one ships.
Repos: kubevela only. The reader uses pkg/config's factory and reads what the Config controller (pkg/controller/config.oam.dev/v1alpha1/config) stores. #7400 moves the reader, unchanged, from cmd/core/app/bootstrap.go to pkg/cue/cuex/providers/velaconfig/reader, so the line numbers below are for that file.
Describe the bug
Review of #7400 turned up five things in how the reader reads a Config. None is a regression from that PR; they came in with the code it moved.
- Any labelled Secret reads as a Config.
ReadConfigreads the named Secret'sinput-properties, andGetConfigaccepts any Secret with non-nil labels (convertSecret2Config,pkg/config/factory.go:1075). Nothing checksconfig.oam.dev/catalog: velacore-config, so a source can read a Secret that is not a Config, if it has labels and aninput-propertieskey. (reader.go:55) - Output namespaces disagree between the two render paths. The Config controller's
renderOutputsforces every output into the Config's namespace (config_controller.go:291), butpkg/config'sParseConfigkeeps whatever namespace the template declares. The reader re-renders withParseConfigand matches byapiVersion|kind|namespace|name, so for a template that declares a namespace, the match misses and the output falls back to aKind/namekey instead of its template label. (reader.go:94-98) - The fallback key can collide. When the re-render fails, outputs are keyed
Kind/name, so two outputs of the same kind and name in different namespaces or API versions collapse into one map entry. (reader.go:100) - The Secret is read twice, and a comment is stale.
ReadConfigthenGetConfigeach read the Secret. The comment saysGetConfigonly blanks a sensitive Config, but it returnsErrSensitiveConfigtoo (pkg/config/factory.go:706), so oneGetConfigwould do. (reader.go:55) - The fallback weakens the
velaconfig.#Readcontract.#Readsaysoutputsare keyed by template label; the fallback silently keys them byKind/name. It is documented as intentional ("A failure here is not fatal"), but a consumer cannot tell which keying it got. Worth deciding whether to surface it (an error, or a field saying the labels are unknown). (reader.go:100)
To reproduce
For 2: create a ConfigTemplate whose outputs entry sets metadata.namespace to something other than the Config's namespace, create a Config from it through the CRD, then read it with velaconfig.#Read. The output comes back under Kind/name, not its label.
For 1: create any Secret with a label and an input-properties key holding JSON, then velaconfig.#Read it by name.
Expected behavior
- Only a Secret carrying the Config catalog label is read as a Config.
- Both render paths agree on output namespaces (normalise before keying, or make
ParseConfigmatch the controller). - The fallback key includes namespace and API version.
- One read, with the comment corrected.
- A decision on whether the fallback is visible to the consumer.
Additional context
Raised by cubic on #7400, #7401 and #7402:
- https://github.com/kubevela/kubevela/pull/7401#discussion_r4120145267 (1)
- https://github.com/kubevela/kubevela/pull/7400#discussion_r4120107203 (2)
- https://github.com/kubevela/kubevela/pull/7401#discussion_r4120145321 (3)
- https://github.com/kubevela/kubevela/pull/7402#discussion_r4120133885 (4)
- https://github.com/kubevela/kubevela/pull/7402#discussion_r4120133898 (5)
Source: kubevela/kubevela