Skip to content

Commit

Permalink
Updating the Go version in go.mod
Browse files Browse the repository at this point in the history
At this time both Go 1.19 and 1.20 are supported. The version
specified in the go.mod file is the minimum version we expect Helm
to be compiled against. This is the oldest supported version to
support environments where others compile Helm. The Helm project
is using Go 1.20 to build Helm itself.

Updating to Go 1.19 also includes dealing with io/ioutil
deprecation and some additional linting issues around staticcheck.
All the staticcheck issues were in test files so linting was
skipped for those.

Signed-off-by: Matt Farina <matt.farina@suse.com>
  • Loading branch information
mattfarina committed Mar 22, 2023
1 parent 50c22ed commit 4e7e939
Show file tree
Hide file tree
Showing 60 changed files with 136 additions and 178 deletions.
5 changes: 2 additions & 3 deletions cmd/helm/create_test.go
Expand Up @@ -18,7 +18,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -77,7 +76,7 @@ func TestCreateStarterCmd(t *testing.T) {
t.Logf("Created %s", dest)
}
tplpath := filepath.Join(starterchart, "starterchart", "templates", "foo.tpl")
if err := ioutil.WriteFile(tplpath, []byte("test"), 0644); err != nil {
if err := os.WriteFile(tplpath, []byte("test"), 0644); err != nil {
t.Fatalf("Could not write template: %s", err)
}

Expand Down Expand Up @@ -140,7 +139,7 @@ func TestCreateStarterAbsoluteCmd(t *testing.T) {
t.Logf("Created %s", dest)
}
tplpath := filepath.Join(starterchart, "starterchart", "templates", "foo.tpl")
if err := ioutil.WriteFile(tplpath, []byte("test"), 0644); err != nil {
if err := os.WriteFile(tplpath, []byte("test"), 0644); err != nil {
t.Fatalf("Could not write template: %s", err)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/helm/helm.go
Expand Up @@ -18,7 +18,7 @@ package main // import "helm.sh/helm/v3/cmd/helm"

import (
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
Expand Down Expand Up @@ -106,10 +106,10 @@ func loadReleasesInMemory(actionConfig *action.Configuration) {
return
}

actionConfig.KubeClient = &kubefake.PrintingKubeClient{Out: ioutil.Discard}
actionConfig.KubeClient = &kubefake.PrintingKubeClient{Out: io.Discard}

for _, path := range filePaths {
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
log.Fatal("Unable to read memory driver data", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/helm/helm_test.go
Expand Up @@ -18,7 +18,7 @@ package main

import (
"bytes"
"io/ioutil"
"io"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -92,7 +92,7 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)

actionConfig := &action.Configuration{
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/helm/load_plugins.go
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -311,7 +310,7 @@ func addPluginCommands(plugin *plugin.Plugin, baseCmd *cobra.Command, cmds *plug
// loadFile takes a yaml file at the given path, parses it and returns a pluginCommand object
func loadFile(path string) (*pluginCommand, error) {
cmds := new(pluginCommand)
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return cmds, fmt.Errorf("file (%s) not provided by plugin. No plugin auto-completion possible", path)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/helm/package.go
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -87,7 +86,7 @@ func newPackageCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {

if client.DependencyUpdate {
downloadManager := &downloader.Manager{
Out: ioutil.Discard,
Out: io.Discard,
ChartPath: path,
Keyring: client.Keyring,
Getters: p,
Expand Down
3 changes: 1 addition & 2 deletions cmd/helm/registry_login.go
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -90,7 +89,7 @@ func getUsernamePassword(usernameOpt string, passwordOpt string, passwordFromStd
password := passwordOpt

if passwordFromStdinOpt {
passwordFromStdin, err := ioutil.ReadAll(os.Stdin)
passwordFromStdin, err := io.ReadAll(os.Stdin)
if err != nil {
return "", "", err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/helm/repo_add.go
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -134,7 +133,7 @@ func (o *repoAddOptions) run(out io.Writer) error {
return err
}

b, err := ioutil.ReadFile(o.repoFile)
b, err := os.ReadFile(o.repoFile)
if err != nil && !os.IsNotExist(err) {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/helm/repo_add_test.go
Expand Up @@ -18,7 +18,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestRepoAdd(t *testing.T) {
}
os.Setenv(xdg.CacheHomeEnvVar, rootDir)

if err := o.run(ioutil.Discard); err != nil {
if err := o.run(io.Discard); err != nil {
t.Error(err)
}

Expand All @@ -126,11 +126,11 @@ func TestRepoAdd(t *testing.T) {

o.forceUpdate = true

if err := o.run(ioutil.Discard); err != nil {
if err := o.run(io.Discard); err != nil {
t.Errorf("Repository was not updated: %s", err)
}

if err := o.run(ioutil.Discard); err != nil {
if err := o.run(io.Discard); err != nil {
t.Errorf("Duplicate repository name was added")
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestRepoAddCheckLegalName(t *testing.T) {

wantErrorMsg := fmt.Sprintf("repository name (%s) contains '/', please specify a different name without '/'", testRepoName)

if err := o.run(ioutil.Discard); err != nil {
if err := o.run(io.Discard); err != nil {
if wantErrorMsg != err.Error() {
t.Fatalf("Actual error %s, not equal to expected error %s", err, wantErrorMsg)
}
Expand Down Expand Up @@ -211,14 +211,14 @@ func repoAddConcurrent(t *testing.T, testName, repoFile string) {
forceUpdate: false,
repoFile: repoFile,
}
if err := o.run(ioutil.Discard); err != nil {
if err := o.run(io.Discard); err != nil {
t.Error(err)
}
}(fmt.Sprintf("%s-%d", testName, i))
}
wg.Wait()

b, err := ioutil.ReadFile(repoFile)
b, err := os.ReadFile(repoFile)
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/helm/repo_update_test.go
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestUpdateCustomCacheCmd(t *testing.T) {
repoFile: filepath.Join(ts.Root(), "repositories.yaml"),
repoCache: cachePath,
}
b := ioutil.Discard
b := io.Discard
if err := o.run(b); err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/helm/require/args_test.go
Expand Up @@ -17,7 +17,7 @@ package require

import (
"fmt"
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -71,7 +71,7 @@ func runTestCases(t *testing.T, testCases []testCase) {
Args: tc.validateFunc,
}
cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard)
cmd.SetOutput(io.Discard)

err := cmd.Execute()
if tc.wantError == "" {
Expand Down
3 changes: 1 addition & 2 deletions cmd/helm/search_repo.go
Expand Up @@ -21,7 +21,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -259,7 +258,7 @@ func compListChartsOfRepo(repoName string, prefix string) []string {
var charts []string

path := filepath.Join(settings.RepositoryCache, helmpath.CacheChartsFile(repoName))
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err == nil {
scanner := bufio.NewScanner(bytes.NewReader(content))
for scanner.Scan() {
Expand Down
3 changes: 1 addition & 2 deletions cmd/helm/upgrade_test.go
Expand Up @@ -18,7 +18,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -359,7 +358,7 @@ func TestUpgradeInstallWithValuesFromStdin(t *testing.T) {

func prepareMockRelease(releaseName string, t *testing.T) (func(n string, v int, ch *chart.Chart) *release.Release, *chart.Chart, string) {
tmpChart := ensure.TempDir(t)
configmapData, err := ioutil.ReadFile("testdata/testcharts/upgradetest/templates/configmap.yaml")
configmapData, err := os.ReadFile("testdata/testcharts/upgradetest/templates/configmap.yaml")
if err != nil {
t.Fatalf("Error loading template yaml %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,6 +1,6 @@
module helm.sh/helm/v3

go 1.17
go 1.19

require (
github.com/BurntSushi/toml v1.2.1
Expand Down
3 changes: 1 addition & 2 deletions internal/fileutil/fileutil.go
Expand Up @@ -18,7 +18,6 @@ package fileutil

import (
"io"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -28,7 +27,7 @@ import (
// AtomicWriteFile atomically (as atomic as os.Rename allows) writes a file to a
// disk.
func AtomicWriteFile(filename string, reader io.Reader, mode os.FileMode) error {
tempFile, err := ioutil.TempFile(filepath.Split(filename))
tempFile, err := os.CreateTemp(filepath.Split(filename))
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/fileutil/fileutil_test.go
Expand Up @@ -18,7 +18,6 @@ package fileutil

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -37,7 +36,7 @@ func TestAtomicWriteFile(t *testing.T) {
t.Errorf("AtomicWriteFile error: %s", err)
}

got, err := ioutil.ReadFile(testpath)
got, err := os.ReadFile(testpath)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/test/ensure/ensure.go
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package ensure

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -44,7 +43,7 @@ func HelmHome(t *testing.T) func() {
// TempDir ensures a scratch test directory for unit testing purposes.
func TempDir(t *testing.T) string {
t.Helper()
d, err := ioutil.TempDir("", "helm")
d, err := os.MkdirTemp("", "helm")
if err != nil {
t.Fatal(err)
}
Expand All @@ -63,7 +62,7 @@ func TempDir(t *testing.T) string {
func TempFile(t *testing.T, name string, data []byte) string {
path := TempDir(t)
filename := filepath.Join(path, name)
if err := ioutil.WriteFile(filename, data, 0755); err != nil {
if err := os.WriteFile(filename, data, 0755); err != nil {
t.Fatal(err)
}
return path
Expand Down
8 changes: 4 additions & 4 deletions internal/test/test.go
Expand Up @@ -19,7 +19,7 @@ package test
import (
"bytes"
"flag"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
Expand Down Expand Up @@ -53,7 +53,7 @@ func AssertGoldenString(t TestingT, actual, filename string) {
func AssertGoldenFile(t TestingT, actualFileName string, expectedFilename string) {
t.Helper()

actual, err := ioutil.ReadFile(actualFileName)
actual, err := os.ReadFile(actualFileName)
if err != nil {
t.Fatalf("%v", err)
}
Expand All @@ -73,7 +73,7 @@ func compare(actual []byte, filename string) error {
return err
}

expected, err := ioutil.ReadFile(filename)
expected, err := os.ReadFile(filename)
if err != nil {
return errors.Wrapf(err, "unable to read testdata %s", filename)
}
Expand All @@ -88,7 +88,7 @@ func update(filename string, in []byte) error {
if !*updateGolden {
return nil
}
return ioutil.WriteFile(filename, normalize(in), 0666)
return os.WriteFile(filename, normalize(in), 0666)
}

func normalize(in []byte) []byte {
Expand Down

0 comments on commit 4e7e939

Please sign in to comment.