Repository: helm/helm
Pull request #13546 (2024-12-19 15:34:08)

Update to Go 1.23
Multiple changes were made to pass linting. Some Go built-in names are being used for variables (e.g., min). This happens in the Go source itself including the Go standard library and is not always a bad practice.

To handle allowing some built-in names to be used the linter config is updated to allow (via opt-in) some names to pass. This allows us to still check for re-use of Go built-in names and opt-in to any new uses.

There were also several cases where a value was checked for nil before checking its length when this is already handled by len() or the types default value. These were cleaned up.

The license validation was updated because it was checking everything in the .git directory including all remote content that was local. The previous vendor directory was from a time prior to Go modules when Helm handled dependencies differently. It was no longer needed.

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. Make sure to read the Contributing Guide before submitting your PR: https://github.com/helm/helm/blob/main/CONTRIBUTING.md
2. If this PR closes another issue, add 'closes #<issue number>' somewhere in the PR summary. GitHub will automatically close that issue when this PR gets merged. Alternatively, adding 'refs #<issue number>' will not close the issue, but help provide the reviewer more context.-->

**What this PR does / why we need it**: This is needed to update to the latest k8s packages as they require Go 1.23

**Special notes for your reviewer**: Most of the changes are to handling new linting messages when Go was updated.

**If applicable**:
- [ ] this PR contains user facing changes (the `docs needed` label should be applied if so)
- [ ] this PR contains unit tests
- [ ] this PR has been tested for backwards compatibility



Patch:
diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml
index 14fe0d414..2a54d0337 100644
--- a/.github/workflows/golangci-lint.yml
+++ b/.github/workflows/golangci-lint.yml
@@ -18,9 +18,9 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # pin@5.2.0
         with:
-          go-version: '1.22'
+          go-version: '1.23'
           check-latest: true
       - name: golangci-lint
         uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 #pin@6.1.1
         with:
-          version: v1.58
+          version: v1.62
diff --git a/.github/workflows/govulncheck.yml b/.github/workflows/govulncheck.yml
index 73efbb3f9..a2f3bfd4b 100644
--- a/.github/workflows/govulncheck.yml
+++ b/.github/workflows/govulncheck.yml
@@ -16,7 +16,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # pin@5.2.0
         with:
-          go-version: '1.22'
+          go-version: '1.23'
           check-latest: true
       - name: govulncheck
         uses: golang/govulncheck-action@b625fbe08f3bccbe446d94fbf87fcc875a4f50ee # pin@1.0.4
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b9fe27aa3..146baddd9 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -27,7 +27,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # pin@5.2.0
         with:
-          go-version: '1.22.7'
+          go-version: '1.23'
 
       - name: Run unit tests
         run: make test-coverage
@@ -83,7 +83,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # pin@5.2.0
         with:
-          go-version: '1.22'
+          go-version: '1.23'
           check-latest: true
 
       - name: Run unit tests
diff --git a/.golangci.yml b/.golangci.yml
index 3cf50a0d4..a3e5119d4 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -23,3 +23,23 @@ linters-settings:
     local-prefixes: helm.sh/helm/v3
   dupl:
     threshold: 400
+issues:
+  exclude-rules:
+    # Helm, and the Go source code itself, sometimes uses these names outside their built-in
+    # functions. As the Go source code has re-used these names it's ok for Helm to do the same.
+    # Linting will look for redefinition of built-in id's but we opt-in to the ones we choose to use.
+    - linters:
+        - revive
+      text: "redefines-builtin-id: redefinition of the built-in function append"
+    - linters:
+        - revive
+      text: "redefines-builtin-id: redefinition of the built-in function clear"
+    - linters:
+        - revive
+      text: "redefines-builtin-id: redefinition of the built-in function max"
+    - linters:
+        - revive
+      text: "redefines-builtin-id: redefinition of the built-in function min"
+    - linters:
+        - revive
+      text: "redefines-builtin-id: redefinition of the built-in function new"
diff --git a/cmd/helm/install.go b/cmd/helm/install.go
index c10e84c18..c5f9e5022 100644
--- a/cmd/helm/install.go
+++ b/cmd/helm/install.go
@@ -206,7 +206,6 @@ func addInstallFlags(cmd *cobra.Command, f *pflag.FlagSet, client *action.Instal
 	f.StringToStringVarP(&client.Labels, "labels", "l", nil, "Labels that would be added to release metadata. Should be divided by comma.")
 	f.BoolVar(&client.EnableDNS, "enable-dns", false, "enable DNS lookups when rendering templates")
 	f.BoolVar(&client.HideNotes, "hide-notes", false, "if set, do not show notes in install output. Does not affect presence in chart metadata")
-	f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, install will ignore the check for helm annotations and take ownership of the existing resources")
 	addValueOptionsFlags(f, valueOpts)
 	addChartPathOptionsFlags(f, &client.ChartPathOptions)
 
diff --git a/cmd/helm/plugin_uninstall.go b/cmd/helm/plugin_uninstall.go
index 607baab2e..458a92cc8 100644
--- a/cmd/helm/plugin_uninstall.go
+++ b/cmd/helm/plugin_uninstall.go
@@ -78,7 +78,7 @@ func (o *pluginUninstallOptions) run(out io.Writer) error {
 		}
 	}
 	if len(errorPlugins) > 0 {
-		return errors.Errorf(strings.Join(errorPlugins, "\n"))
+		return errors.New(strings.Join(errorPlugins, "\n"))
 	}
 	return nil
 }
diff --git a/cmd/helm/plugin_update.go b/cmd/helm/plugin_update.go
index 3f6d963fb..eb7505696 100644
--- a/cmd/helm/plugin_update.go
+++ b/cmd/helm/plugin_update.go
@@ -81,7 +81,7 @@ func (o *pluginUpdateOptions) run(out io.Writer) error {
 		}
 	}
 	if len(errorPlugins) > 0 {
-		return errors.Errorf(strings.Join(errorPlugins, "\n"))
+		return errors.New(strings.Join(errorPlugins, "\n"))
 	}
 	return nil
 }
diff --git a/cmd/helm/status.go b/cmd/helm/status.go
index 2bee5db44..747b2556b 100644
--- a/cmd/helm/status.go
+++ b/cmd/helm/status.go
@@ -140,7 +140,7 @@ func (s statusPrinter) WriteTable(out io.Writer) error {
 	}
 	_, _ = fmt.Fprintf(out, "DESCRIPTION: %s\n", s.release.Info.Description)
 
-	if s.release.Info.Resources != nil && len(s.release.Info.Resources) > 0 {
+	if len(s.release.Info.Resources) > 0 {
 		buf := new(bytes.Buffer)
 		printFlags := get.NewHumanPrintFlags()
 		typePrinter, _ := printFlags.ToPrinter("")
diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go
index 95d00e39c..df529db5b 100644
--- a/cmd/helm/upgrade.go
+++ b/cmd/helm/upgrade.go
@@ -151,7 +151,6 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
 					instClient.Labels = client.Labels
 					instClient.EnableDNS = client.EnableDNS
 					instClient.HideSecret = client.HideSecret
-					instClient.TakeOwnership = client.TakeOwnership
 
 					if isReleaseUninstalled(versions) {
 						instClient.Replace = true
@@ -290,7 +289,6 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
 	f.StringVar(&client.Description, "description", "", "add a custom description")
 	f.BoolVar(&client.DependencyUpdate, "dependency-update", false, "update dependencies if they are missing before installing the chart")
 	f.BoolVar(&client.EnableDNS, "enable-dns", false, "enable DNS lookups when rendering templates")
-	f.BoolVar(&client.TakeOwnership, "take-ownership", false, "if set, upgrade will ignore the check for helm annotations and take ownership of the existing resources")
 	addChartPathOptionsFlags(f, &client.ChartPathOptions)
 	addValueOptionsFlags(f, valueOpts)
 	bindOutputFlag(cmd, &outfmt)
diff --git a/go.mod b/go.mod
index fbb67f5c2..997385df2 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module helm.sh/helm/v3
 
-go 1.22.0
+go 1.23.0
 
 require (
 	github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24
diff --git a/pkg/action/hooks.go b/pkg/action/hooks.go
index 4bffb6ae0..e1cbab5e1 100644
--- a/pkg/action/hooks.go
+++ b/pkg/action/hooks.go
@@ -44,7 +44,7 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent,
 
 	for _, h := range executingHooks {
 		// Set default delete policy to before-hook-creation
-		if h.DeletePolicies == nil || len(h.DeletePolicies) == 0 {
+		if len(h.DeletePolicies) == 0 {
 			// TODO(jlegrone): Only apply before-hook-creation delete policy to run to completion
 			//                 resources. For all other resource types update in place if a
 			//                 resource with the same name already exists and is owned by the
diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go
index df3a600a3..d8ee313e1 100644
--- a/pkg/engine/engine.go
+++ b/pkg/engine/engine.go
@@ -206,7 +206,7 @@ func (e Engine) initFunMap(t *template.Template) {
 				log.Printf("[INFO] Missing required value: %s", warn)
 				return "", nil
 			}
-			return val, errors.Errorf(warnWrap(warn))
+			return val, errors.New(warnWrap(warn))
 		} else if _, ok := val.(string); ok {
 			if val == "" {
 				if e.LintMode {
@@ -214,7 +214,7 @@ func (e Engine) initFunMap(t *template.Template) {
 					log.Printf("[INFO] Missing required value: %s", warn)
 					return "", nil
 				}
-				return val, errors.Errorf(warnWrap(warn))
+				return val, errors.New(warnWrap(warn))
 			}
 		}
 		return val, nil
diff --git a/pkg/kube/client.go b/pkg/kube/client.go
index 4d93c91b9..5f16f2bfb 100644
--- a/pkg/kube/client.go
+++ b/pkg/kube/client.go
@@ -435,7 +435,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
 	case err != nil:
 		return res, err
 	case len(updateErrors) != 0:
-		return res, errors.Errorf(strings.Join(updateErrors, " && "))
+		return res, errors.New(strings.Join(updateErrors, " && "))
 	}
 
 	for _, info := range original.Difference(target) {
diff --git a/pkg/kube/wait.go b/pkg/kube/wait.go
index 36110d0de..bdafc8255 100644
--- a/pkg/kube/wait.go
+++ b/pkg/kube/wait.go
@@ -153,7 +153,7 @@ func SelectorsForObject(object runtime.Object) (selector labels.Selector, err er
 	case *batchv1.Job:
 		selector, err = metav1.LabelSelectorAsSelector(t.Spec.Selector)
 	case *corev1.Service:
-		if t.Spec.Selector == nil || len(t.Spec.Selector) == 0 {
+		if len(t.Spec.Selector) == 0 {
 			return nil, fmt.Errorf("invalid service '%s': Service is defined without a selector", t.Name)
 		}
 		selector = labels.SelectorFromSet(t.Spec.Selector)
diff --git a/pkg/registry/util.go b/pkg/registry/util.go
index 727cdae03..4454105c9 100644
--- a/pkg/registry/util.go
+++ b/pkg/registry/util.go
@@ -208,7 +208,7 @@ func generateChartOCIAnnotations(meta *chart.Metadata, creationTime string) map[
 		chartOCIAnnotations = addToMap(chartOCIAnnotations, ocispec.AnnotationSource, meta.Sources[0])
 	}
 
-	if meta.Maintainers != nil && len(meta.Maintainers) > 0 {
+	if len(meta.Maintainers) > 0 {
 		var maintainerSb strings.Builder
 
 		for maintainerIdx, maintainer := range meta.Maintainers {
diff --git a/scripts/validate-license.sh b/scripts/validate-license.sh
index dc247436f..f67812ca5 100755
--- a/scripts/validate-license.sh
+++ b/scripts/validate-license.sh
@@ -19,7 +19,7 @@ IFS=$'\n\t'
 find_files() {
   find . -not \( \
     \( \
-      -wholename './vendor' \
+      -wholename './.git' \
       -o -wholename '*testdata*' \
       -o -wholename '*third_party*' \
     \) -prune \


Test patch:
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index e6e347ecd..30ed80a34 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -21,7 +21,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # pin@5.2.0
         with:
-          go-version: '1.22'
+          go-version: '1.23'
           check-latest: true
       - name: Test source headers are present
         run: make test-source-headers
diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go
index 3e022b111..682b25164 100644
--- a/cmd/helm/install_test.go
+++ b/cmd/helm/install_test.go
@@ -102,12 +102,6 @@ func TestInstall(t *testing.T) {
 			cmd:    "install aeneas testdata/testcharts/empty --replace",
 			golden: "output/install-and-replace.txt",
 		},
-		// Install, take ownership
-		{
-			name:   "install and replace release",
-			cmd:    "install aeneas-take-ownership testdata/testcharts/empty --take-ownership",
-			golden: "output/install-and-take-ownership.txt",
-		},
 		// Install, with timeout
 		{
 			name:   "install with a timeout",
diff --git a/cmd/helm/testdata/output/install-and-take-ownership.txt b/cmd/helm/testdata/output/install-and-take-ownership.txt
deleted file mode 100644
index 413329ae1..000000000
--- a/cmd/helm/testdata/output/install-and-take-ownership.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-NAME: aeneas-take-ownership
-LAST DEPLOYED: Fri Sep  2 22:04:05 1977
-NAMESPACE: default
-STATUS: deployed
-REVISION: 1
-DESCRIPTION: Install complete
-TEST SUITE: None
diff --git a/cmd/helm/testdata/output/upgrade-and-take-ownership.txt b/cmd/helm/testdata/output/upgrade-and-take-ownership.txt
deleted file mode 100644
index 59267651f..000000000
--- a/cmd/helm/testdata/output/upgrade-and-take-ownership.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-Release "funny-bunny" has been upgraded. Happy Helming!
-NAME: funny-bunny
-LAST DEPLOYED: Fri Sep  2 22:04:05 1977
-NAMESPACE: default
-STATUS: deployed
-REVISION: 3
-DESCRIPTION: Upgrade complete
-TEST SUITE: None
diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go
index 6065647b9..497c78d71 100644
--- a/cmd/helm/upgrade_test.go
+++ b/cmd/helm/upgrade_test.go
@@ -114,12 +114,6 @@ func TestUpgradeCmd(t *testing.T) {
 			golden: "output/upgrade-with-reset-values2.txt",
 			rels:   []*release.Release{relMock("funny-bunny", 5, ch2)},
 		},
-		{
-			name:   "upgrade a release with --take-ownership",
-			cmd:    fmt.Sprintf("upgrade funny-bunny '%s' --take-ownership", chartPath),
-			golden: "output/upgrade-and-take-ownership.txt",
-			rels:   []*release.Release{relMock("funny-bunny", 2, ch)},
-		},
 		{
 			name:   "install a release with 'upgrade --install'",
 			cmd:    fmt.Sprintf("upgrade zany-bunny -i '%s'", chartPath),