From 57667c932ca1e9bcf24945a8da035c2ee4a26a72 Mon Sep 17 00:00:00 2001 From: Shaan Satsangi Date: Tue, 23 Jun 2026 01:59:44 +0530 Subject: [PATCH] fix(cmd): correct --show-source help text and cover get metadata source The --show-source help claimed JSON/YAML output 'always includes' the source field, but releaseElement.Source is tagged json:"source,omitempty" so it is omitted when a release has no recorded source. Reword the help to state the flag affects only table output and that JSON/YAML emit source whenever a release has one. Also add cmd-level get metadata coverage for a release whose chart records meta.helm.sh/release-source, with table/JSON/YAML golden files, so the new SOURCE line and source field do not regress. Signed-off-by: Shaan Satsangi --- pkg/cmd/get_metadata_test.go | 25 +++++++++++++++++++ pkg/cmd/list.go | 2 +- .../testdata/output/get-metadata-source.json | 1 + .../testdata/output/get-metadata-source.txt | 13 ++++++++++ .../testdata/output/get-metadata-source.yaml | 25 +++++++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 pkg/cmd/testdata/output/get-metadata-source.json create mode 100644 pkg/cmd/testdata/output/get-metadata-source.txt create mode 100644 pkg/cmd/testdata/output/get-metadata-source.yaml diff --git a/pkg/cmd/get_metadata_test.go b/pkg/cmd/get_metadata_test.go index 59fc3b82c..6f0b307b7 100644 --- a/pkg/cmd/get_metadata_test.go +++ b/pkg/cmd/get_metadata_test.go @@ -19,15 +19,40 @@ package cmd import ( "testing" + "helm.sh/helm/v4/pkg/action" release "helm.sh/helm/v4/pkg/release/v1" ) +// mockReleaseWithSource returns a mock release whose chart records a +// meta.helm.sh/release-source annotation, so the 'get metadata' output for the +// new SOURCE field can be exercised. +func mockReleaseWithSource(name string) *release.Release { + rel := release.Mock(&release.MockReleaseOptions{Name: name, Labels: map[string]string{"key1": "value1"}}) + rel.Chart.Metadata.Annotations[action.ReleaseSourceAnnotation] = "https://charts.example.com" + return rel +} + func TestGetMetadataCmd(t *testing.T) { tests := []cmdTestCase{{ name: "get metadata with a release", cmd: "get metadata thomas-guide", golden: "output/get-metadata.txt", rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide", Labels: map[string]string{"key1": "value1"}})}, + }, { + name: "get metadata with a recorded source", + cmd: "get metadata thomas-guide", + golden: "output/get-metadata-source.txt", + rels: []*release.Release{mockReleaseWithSource("thomas-guide")}, + }, { + name: "get metadata with a recorded source to json", + cmd: "get metadata thomas-guide --output json", + golden: "output/get-metadata-source.json", + rels: []*release.Release{mockReleaseWithSource("thomas-guide")}, + }, { + name: "get metadata with a recorded source to yaml", + cmd: "get metadata thomas-guide --output yaml", + golden: "output/get-metadata-source.yaml", + rels: []*release.Release{mockReleaseWithSource("thomas-guide")}, }, { name: "get metadata requires release name arg", cmd: "get metadata", diff --git a/pkg/cmd/list.go b/pkg/cmd/list.go index 8cad89c9e..907c5fb02 100644 --- a/pkg/cmd/list.go +++ b/pkg/cmd/list.go @@ -135,7 +135,7 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.IntVar(&client.Offset, "offset", 0, "next release index in the list, used to offset from start value") f.StringVarP(&client.Filter, "filter", "f", "", "a regular expression (Perl compatible). Any releases that match the expression will be included in the results") f.StringVarP(&client.Selector, "selector", "l", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Works only for secret(default) and configmap storage backends.") - f.BoolVar(&showSource, "show-source", false, "add a SOURCE column to the table output showing where each release's chart was installed from (chart reference or repository URL); JSON/YAML output always includes the 'source' field") + f.BoolVar(&showSource, "show-source", false, "add a SOURCE column to the table output showing where each release's chart was installed from (chart reference or repository URL); this flag affects only table output, while JSON/YAML output includes the 'source' field whenever a release has a recorded source") bindOutputFlag(cmd, &outfmt) return cmd diff --git a/pkg/cmd/testdata/output/get-metadata-source.json b/pkg/cmd/testdata/output/get-metadata-source.json new file mode 100644 index 000000000..a850fcea2 --- /dev/null +++ b/pkg/cmd/testdata/output/get-metadata-source.json @@ -0,0 +1 @@ +{"name":"thomas-guide","chart":"foo","version":"0.1.0-beta.1","appVersion":"1.0","source":"https://charts.example.com","annotations":{"category":"web-apps","meta.helm.sh/release-source":"https://charts.example.com","supported":"true"},"labels":{"key1":"value1"},"dependencies":[{"name":"cool-plugin","version":"1.0.0","repository":"https://coolplugin.io/charts","condition":"coolPlugin.enabled","enabled":true},{"name":"crds","version":"2.7.1","repository":"","condition":"crds.enabled"}],"namespace":"default","revision":1,"status":"deployed","deployedAt":"1977-09-02T22:04:05Z"} diff --git a/pkg/cmd/testdata/output/get-metadata-source.txt b/pkg/cmd/testdata/output/get-metadata-source.txt new file mode 100644 index 000000000..24a87b06c --- /dev/null +++ b/pkg/cmd/testdata/output/get-metadata-source.txt @@ -0,0 +1,13 @@ +NAME: thomas-guide +CHART: foo +VERSION: 0.1.0-beta.1 +APP_VERSION: 1.0 +SOURCE: https://charts.example.com +ANNOTATIONS: category=web-apps,meta.helm.sh/release-source=https://charts.example.com,supported=true +LABELS: key1=value1 +DEPENDENCIES: cool-plugin,crds +NAMESPACE: default +REVISION: 1 +STATUS: deployed +DEPLOYED_AT: 1977-09-02T22:04:05Z +APPLY_METHOD: client-side apply (defaulted) diff --git a/pkg/cmd/testdata/output/get-metadata-source.yaml b/pkg/cmd/testdata/output/get-metadata-source.yaml new file mode 100644 index 000000000..796270684 --- /dev/null +++ b/pkg/cmd/testdata/output/get-metadata-source.yaml @@ -0,0 +1,25 @@ +annotations: + category: web-apps + meta.helm.sh/release-source: https://charts.example.com + supported: "true" +appVersion: "1.0" +chart: foo +dependencies: +- condition: coolPlugin.enabled + enabled: true + name: cool-plugin + repository: https://coolplugin.io/charts + version: 1.0.0 +- condition: crds.enabled + name: crds + repository: "" + version: 2.7.1 +deployedAt: "1977-09-02T22:04:05Z" +labels: + key1: value1 +name: thomas-guide +namespace: default +revision: 1 +source: https://charts.example.com +status: deployed +version: 0.1.0-beta.1