Repository: helm/helm
Pull request #8590 (2020-08-12 21:03:45)

release/mock: Ensure conversion from int to string yields a string
With the release of go 1.15, the test-suite doesn't pass as `go test` got
a new warning for improper `string(x)` usage.

https://golang.org/doc/go1.15#vet

    $ make test-unit
    # helm.sh/helm/v3/pkg/release
    pkg/release/mock.go:56:27: conversion from int to string yields a string of one rune, not a string of digits (did you mean fmt.Sprint(x)?)
    [snip]
    make: *** [Makefile:82: test-unit] Error 2

This patch changes ensures we are utilizing `fmt.Sprint` instead as
recommended.

Signed-off-by: Morten Linderud <morten@linderud.pw>



Patch:
diff --git a/README.md b/README.md
index 9c39175bc..bb6908fdb 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ If you want to use a package manager:
 - [GoFish](https://gofi.sh/) users can use `gofish install helm`.
 - [Snapcraft](https://snapcraft.io/) users can use `snap install helm --classic`
 
-To rapidly get Helm up and running, start with the [Quick Start Guide](https://helm.sh/docs/intro/quickstart/).
+To rapidly get Helm up and running, start with the [Quick Start Guide](https://docs.helm.sh/using_helm/#quickstart-guide).
 
 See the [installation guide](https://helm.sh/docs/intro/install/) for more options,
 including installing pre-releases.
diff --git a/cmd/helm/show.go b/cmd/helm/show.go
index fe5eaee26..c122d8476 100644
--- a/cmd/helm/show.go
+++ b/cmd/helm/show.go
@@ -151,9 +151,6 @@ func addShowFlags(subCmd *cobra.Command, client *action.Show) {
 	f := subCmd.Flags()
 
 	f.BoolVar(&client.Devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored")
-	if subCmd.Name() == "values" {
-		f.StringVar(&client.JSONPathTemplate, "jsonpath", "", "supply a JSONPath expression to filter the output")
-	}
 	addChartPathOptionsFlags(f, &client.ChartPathOptions)
 
 	err := subCmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
diff --git a/internal/experimental/registry/reference.go b/internal/experimental/registry/reference.go
index f0e91d4ba..ebab29a7e 100644
--- a/internal/experimental/registry/reference.go
+++ b/internal/experimental/registry/reference.go
@@ -105,7 +105,7 @@ func (ref *Reference) validateRepo() error {
 	return err
 }
 
-// validateNumColons ensures the ref only contains a single colon character (:)
+// validateNumColon ensures the ref only contains a single colon character (:)
 // (or potentially two, there might be a port number specified i.e. :5000)
 func (ref *Reference) validateNumColons() error {
 	if strings.Contains(ref.Tag, ":") {
diff --git a/pkg/action/action.go b/pkg/action/action.go
index 071db709b..3c47cc6df 100644
--- a/pkg/action/action.go
+++ b/pkg/action/action.go
@@ -100,7 +100,7 @@ type Configuration struct {
 //
 // TODO: This function is badly in need of a refactor.
 // TODO: As part of the refactor the duplicate code in cmd/helm/template.go should be removed
-//       This code has to do with writing files to disk.
+//       This code has to do with writing files to dick.
 func (c *Configuration) renderResources(ch *chart.Chart, values chartutil.Values, releaseName, outputDir string, subNotes, useReleaseName, includeCrds bool, pr postrender.PostRenderer, dryRun bool) ([]*release.Hook, *bytes.Buffer, string, error) {
 	hs := []*release.Hook{}
 	b := bytes.NewBuffer(nil)
diff --git a/pkg/action/list.go b/pkg/action/list.go
index 0f85de519..ac6fd1b75 100644
--- a/pkg/action/list.go
+++ b/pkg/action/list.go
@@ -152,6 +152,12 @@ func (l *List) Run() ([]*release.Release, error) {
 	}
 
 	results, err := l.cfg.Releases.List(func(rel *release.Release) bool {
+		// Skip anything that the mask doesn't cover
+		currentStatus := l.StateMask.FromName(rel.Info.Status.String())
+		if l.StateMask&currentStatus == 0 {
+			return false
+		}
+
 		// Skip anything that doesn't match the filter.
 		if filter != nil && !filter.MatchString(rel.Name) {
 			return false
@@ -167,16 +173,7 @@ func (l *List) Run() ([]*release.Release, error) {
 		return results, nil
 	}
 
-	// by definition, superseded releases are never shown if
-	// only the latest releases are returned. so if requested statemask
-	// is _only_ ListSuperseded, skip the latest release filter
-	if l.StateMask != ListSuperseded {
-		results = filterLatestReleases(results)
-	}
-
-	// State mask application must occur after filtering to
-	// latest releases, otherwise outdated entries can be returned
-	results = l.filterStateMask(results)
+	results = filterList(results)
 
 	// Unfortunately, we have to sort before truncating, which can incur substantial overhead
 	l.sort(results)
@@ -225,8 +222,8 @@ func (l *List) sort(rels []*release.Release) {
 	}
 }
 
-// filterLatestReleases returns a list scrubbed of old releases.
-func filterLatestReleases(releases []*release.Release) []*release.Release {
+// filterList returns a list scrubbed of old releases.
+func filterList(releases []*release.Release) []*release.Release {
 	latestReleases := make(map[string]*release.Release)
 
 	for _, rls := range releases {
@@ -245,21 +242,6 @@ func filterLatestReleases(releases []*release.Release) []*release.Release {
 	return list
 }
 
-func (l *List) filterStateMask(releases []*release.Release) []*release.Release {
-	desiredStateReleases := make([]*release.Release, 0)
-
-	for _, rls := range releases {
-		currentStatus := l.StateMask.FromName(rls.Info.Status.String())
-		mask := l.StateMask & currentStatus
-		if mask == 0 {
-			continue
-		}
-		desiredStateReleases = append(desiredStateReleases, rls)
-	}
-
-	return desiredStateReleases
-}
-
 // SetStateMask calculates the state mask based on parameters.
 func (l *List) SetStateMask() {
 	if l.All {
diff --git a/pkg/action/show.go b/pkg/action/show.go
index 4eab2b4fd..9baa9cf43 100644
--- a/pkg/action/show.go
+++ b/pkg/action/show.go
@@ -20,8 +20,6 @@ import (
 	"fmt"
 	"strings"
 
-	"github.com/pkg/errors"
-	"k8s.io/cli-runtime/pkg/printers"
 	"sigs.k8s.io/yaml"
 
 	"helm.sh/helm/v3/pkg/chart"
@@ -54,10 +52,9 @@ func (o ShowOutputFormat) String() string {
 // It provides the implementation of 'helm show' and its respective subcommands.
 type Show struct {
 	ChartPathOptions
-	Devel            bool
-	OutputFormat     ShowOutputFormat
-	JSONPathTemplate string
-	chart            *chart.Chart // for testing
+	Devel        bool
+	OutputFormat ShowOutputFormat
+	chart        *chart.Chart // for testing
 }
 
 // NewShow creates a new Show object with the given configuration.
@@ -90,17 +87,9 @@ func (s *Show) Run(chartpath string) (string, error) {
 		if s.OutputFormat == ShowAll {
 			fmt.Fprintln(&out, "---")
 		}
-		if s.JSONPathTemplate != "" {
-			printer, err := printers.NewJSONPathPrinter(s.JSONPathTemplate)
-			if err != nil {
-				return "", errors.Wrapf(err, "error parsing jsonpath %s", s.JSONPathTemplate)
-			}
-			printer.Execute(&out, s.chart.Values)
-		} else {
-			for _, f := range s.chart.Raw {
-				if f.Name == chartutil.ValuesfileName {
-					fmt.Fprintln(&out, string(f.Data))
-				}
+		for _, f := range s.chart.Raw {
+			if f.Name == chartutil.ValuesfileName {
+				fmt.Fprintln(&out, string(f.Data))
 			}
 		}
 	}
diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go
index 8d8f48176..c036ce37d 100644
--- a/pkg/chartutil/create.go
+++ b/pkg/chartutil/create.go
@@ -381,9 +381,8 @@ const defaultNotes = `1. Get the application URL by running these commands:
   echo http://$SERVICE_IP:{{ .Values.service.port }}
 {{- else if contains "ClusterIP" .Values.service.type }}
   export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "<CHARTNAME>.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
-  export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
   echo "Visit http://127.0.0.1:8080 to use your application"
-  kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
+  kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
 {{- end }}
 `
 
@@ -425,7 +424,9 @@ Common labels
 {{- define "<CHARTNAME>.labels" -}}
 helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
 {{ include "<CHARTNAME>.selectorLabels" . }}
-app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
 app.kubernetes.io/managed-by: {{ .Release.Service }}
 {{- end }}
 
diff --git a/pkg/release/mock.go b/pkg/release/mock.go
index 3abbd574b..a28e1dc16 100644
--- a/pkg/release/mock.go
+++ b/pkg/release/mock.go
@@ -17,6 +17,7 @@ limitations under the License.
 package release
 
 import (
+	"fmt"
 	"math/rand"
 
 	"helm.sh/helm/v3/pkg/chart"
@@ -53,7 +54,7 @@ func Mock(opts *MockReleaseOptions) *Release {
 
 	name := opts.Name
 	if name == "" {
-		name = "testrelease-" + string(rand.Intn(100))
+		name = "testrelease-" + fmt.Sprint(rand.Intn(100))
 	}
 
 	version := 1


Test patch:
diff --git a/cmd/helm/repo_add_test.go b/cmd/helm/repo_add_test.go
index 7cb669a1a..d1b9bc0fc 100644
--- a/cmd/helm/repo_add_test.go
+++ b/cmd/helm/repo_add_test.go
@@ -40,12 +40,11 @@ func TestRepoAddCmd(t *testing.T) {
 	}
 	defer srv.Stop()
 
-	tmpdir := ensure.TempDir(t)
-	repoFile := filepath.Join(tmpdir, "repositories.yaml")
+	repoFile := filepath.Join(ensure.TempDir(t), "repositories.yaml")
 
 	tests := []cmdTestCase{{
 		name:   "add a repository",
-		cmd:    fmt.Sprintf("repo add test-name %s --repository-config %s --repository-cache %s", srv.URL(), repoFile, tmpdir),
+		cmd:    fmt.Sprintf("repo add test-name %s --repository-config %s", srv.URL(), repoFile),
 		golden: "output/repo-add.txt",
 	}}
 
diff --git a/pkg/action/list_test.go b/pkg/action/list_test.go
index b8e2ece68..378a747b0 100644
--- a/pkg/action/list_test.go
+++ b/pkg/action/list_test.go
@@ -188,56 +188,6 @@ func TestList_StateMask(t *testing.T) {
 	is.Len(res, 3)
 }
 
-func TestList_StateMaskWithStaleRevisions(t *testing.T) {
-	is := assert.New(t)
-	lister := newListFixture(t)
-	lister.StateMask = ListFailed
-
-	makeMeSomeReleasesWithStaleFailure(lister.cfg.Releases, t)
-
-	res, err := lister.Run()
-
-	is.NoError(err)
-	is.Len(res, 1)
-
-	// "dirty" release should _not_ be present as most recent
-	// release is deployed despite failed release in past
-	is.Equal("failed", res[0].Name)
-}
-
-func makeMeSomeReleasesWithStaleFailure(store *storage.Storage, t *testing.T) {
-	t.Helper()
-	one := namedReleaseStub("clean", release.StatusDeployed)
-	one.Namespace = "default"
-	one.Version = 1
-
-	two := namedReleaseStub("dirty", release.StatusDeployed)
-	two.Namespace = "default"
-	two.Version = 1
-
-	three := namedReleaseStub("dirty", release.StatusFailed)
-	three.Namespace = "default"
-	three.Version = 2
-
-	four := namedReleaseStub("dirty", release.StatusDeployed)
-	four.Namespace = "default"
-	four.Version = 3
-
-	five := namedReleaseStub("failed", release.StatusFailed)
-	five.Namespace = "default"
-	five.Version = 1
-
-	for _, rel := range []*release.Release{one, two, three, four, five} {
-		if err := store.Create(rel); err != nil {
-			t.Fatal(err)
-		}
-	}
-
-	all, err := store.ListReleases()
-	assert.NoError(t, err)
-	assert.Len(t, all, 5, "sanity test: five items added")
-}
-
 func TestList_Filter(t *testing.T) {
 	is := assert.New(t)
 	lister := newListFixture(t)
@@ -286,7 +236,7 @@ func makeMeSomeReleases(store *storage.Storage, t *testing.T) {
 	assert.Len(t, all, 3, "sanity test: three items added")
 }
 
-func TestFilterLatestReleases(t *testing.T) {
+func TestFilterList(t *testing.T) {
 	t.Run("should filter old versions of the same release", func(t *testing.T) {
 		r1 := releaseStub()
 		r1.Name = "r"
@@ -298,7 +248,7 @@ func TestFilterLatestReleases(t *testing.T) {
 		another.Name = "another"
 		another.Version = 1
 
-		filteredList := filterLatestReleases([]*release.Release{r1, r2, another})
+		filteredList := filterList([]*release.Release{r1, r2, another})
 		expectedFilteredList := []*release.Release{r2, another}
 
 		assert.ElementsMatch(t, expectedFilteredList, filteredList)
@@ -314,7 +264,7 @@ func TestFilterLatestReleases(t *testing.T) {
 		r2.Namespace = "testing"
 		r2.Version = 2
 
-		filteredList := filterLatestReleases([]*release.Release{r1, r2})
+		filteredList := filterList([]*release.Release{r1, r2})
 		expectedFilteredList := []*release.Release{r1, r2}
 
 		assert.ElementsMatch(t, expectedFilteredList, filteredList)
diff --git a/pkg/action/show_test.go b/pkg/action/show_test.go
index a2efdc8ac..7be9daaa5 100644
--- a/pkg/action/show_test.go
+++ b/pkg/action/show_test.go
@@ -69,17 +69,3 @@ func TestShowNoValues(t *testing.T) {
 		t.Errorf("expected empty values buffer, got %s", output)
 	}
 }
-
-func TestShowValuesByJsonPathFormat(t *testing.T) {
-	client := NewShow(ShowValues)
-	client.JSONPathTemplate = "{$.nestedKey.simpleKey}"
-	client.chart = buildChart(withSampleValues())
-	output, err := client.Run("")
-	if err != nil {
-		t.Fatal(err)
-	}
-	expect := "simpleValue"
-	if output != expect {
-		t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
-	}
-}