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 <shaansatsangi@gmail.com>
pull/32250/head
Shaan Satsangi 3 weeks ago
parent 2cf9b05ced
commit 57667c932c

@ -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",

@ -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

@ -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"}

@ -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)

@ -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
Loading…
Cancel
Save