ConfigTemplate CRs are missing from Factory.ListTemplates, so template lists omit them
Describe the bug
A ConfigTemplate custom resource (kubevela#7211) is missing from pkg/config's Factory.ListTemplates, which lists only the legacy config-template-* ConfigMaps. Factory.LoadTemplate already reads the CR first and falls back to the ConfigMap, so a CR template can be fetched by name but never appears in a list. Consumers that offer a choice of templates therefore cannot offer CR templates: VelaUX's config page lists none, so a user cannot create a config from a template installed as a CR.
vela config-template list in its default auto mode goes the other way and lists only CRs, and it includes SourceDefinition's internal templates (source-<name>-<hash>), which are not meant for users to create configs from.
Affects KubeVela master (1.12 line) since #7211, and VelaUX, which calls Factory.ListTemplates for /api/v1/config_templates.
To Reproduce
- Apply a ConfigTemplate CR:
apiVersion: config.oam.dev/v1alpha1
kind: ConfigTemplate
metadata:
name: demo-endpoint
namespace: vela-system
spec:
scope: system
template: |
metadata: name: "demo-endpoint"
template: {
parameter: url: string
output: {
apiVersion: "v1"
kind: "Secret"
stringData: url: parameter.url
}
}- It reconciles:
$ kubectl -n vela-system get configtemplate demo-endpoint
NAME SCOPE PHASE AGE
demo-endpoint system Available 5s- List templates through
Factory.ListTemplates(here via VelaUX, which calls it directly) and fetch the same one by name (Factory.LoadTemplate):
$ curl -s -H "Authorization: Bearer $TOKEN" localhost:8000/api/v1/config_templates | jq '[.templates[].name]'
[]
$ curl -s -H "Authorization: Bearer $TOKEN" 'localhost:8000/api/v1/config_templates/demo-endpoint?namespace=vela-system' | jq .name
"demo-endpoint"- The CLI lists it, along with SourceDefinition's internal templates:
$ vela config-template list -n vela-system
NAME ALIAS SCOPE SENSITIVE
demo-endpoint Demo endpoint system false
source-configmap-local-7a08375a configmap-local system false
source-git-file-603c7eae git-file system false
...Expected behavior
ListTemplates returns ConfigTemplate CRs as well as legacy ConfigMap templates, as LoadTemplate already reads both ("dual-read, single-write", kubevela#7308). Internal templates are not offered to users in either list.
Screenshots
N/A.
KubeVela Version
Core: master at f450c6e (built locally; `pkg/config` and the config controllers unchanged from master)
CLI: built from the same commitCluster information
k3d, local single-node, Kubernetes v1.35.5 (k3s).
Additional context
- Where it appears in the code:
pkg/config/factory.go:440ListTemplateslists ConfigMaps labelledconfig.oam.dev/catalog=velacore-configonly.pkg/config/factory.go:503LoadTemplatereads the ConfigTemplate CR first, then the ConfigMap.references/cli/config.go:159-175lists CRs only in CRD mode.- SourceDefinition writes its templates as ConfigTemplate CRs labelled
sourcedefinition.oam.dev/name(pkg/controller/core.oam.dev/v1beta1/core/sources/sourcedefinition/sourcedefinition_controller.go:51-53, 139-188).
- Suggested fix: make
ListTemplatesdual-read, returning CRs and ConfigMaps with the CR winning a name clash (matchingLoadTemplate), and leaving out templates labelledsourcedefinition.oam.dev/name. A CR'sscopeissystemornamespace; callers filtering on a legacy scope such as VelaUX'sprojectwould need that mapping documented,namespacein a project's namespace being the natural equivalent. - Requirements from a consumer (VelaUX): each returned template says which store it came from and, for a CR, its phase, so a UI can mark a template that is not yet Available; and
ListTemplatesandLoadTemplateagree on which wins when a CR and a ConfigMap share a name. - Related: Config CRs are likewise missing from
Factory.ListConfigs(separate issue, https://github.com/kubevela/kubevela/issues/7416). - Verified: steps 1 to 4 were run against a controller built from master on k3d, with VelaUX built against the same KubeVela commit; the outputs shown are observed (the CLI table is trimmed).
Source: kubevela/kubevela