diff --git a/cmd/clusterctl/client/cluster/proxy_test.go b/cmd/clusterctl/client/cluster/proxy_test.go index 7dd68e5fe6f6..b0ede3edbbf7 100644 --- a/cmd/clusterctl/client/cluster/proxy_test.go +++ b/cmd/clusterctl/client/cluster/proxy_test.go @@ -18,7 +18,6 @@ package cluster import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -63,11 +62,11 @@ func TestProxyGetConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) configFile := filepath.Join(dir, ".test-kubeconfig.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte(tt.kubeconfigContents), 0600)).To(Succeed()) proxy := newProxy(Kubeconfig{Path: configFile, Context: tt.context}) conf, err := proxy.GetConfig() @@ -90,11 +89,11 @@ func TestProxyGetConfig(t *testing.T) { t.Run("configure timeout", func(t *testing.T) { g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) configFile := filepath.Join(dir, ".test-kubeconfig.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfig("management", "default")), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte(kubeconfig("management", "default")), 0600)).To(Succeed()) proxy := newProxy(Kubeconfig{Path: configFile, Context: "management"}, InjectProxyTimeout(23*time.Second)) conf, err := proxy.GetConfig() @@ -117,11 +116,11 @@ func TestKUBECONFIGEnvVar(t *testing.T) { ) g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) configFile := filepath.Join(dir, ".test-kubeconfig.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfigContents), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte(kubeconfigContents), 0600)).To(Succeed()) proxy := newProxy( // dont't give an explicit path but rather define the file in the @@ -145,11 +144,11 @@ func TestKUBECONFIGEnvVar(t *testing.T) { expectedHost = "https://kind-server:38790" ) g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) configFile := filepath.Join(dir, ".test-kubeconfig.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfigContents), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte(kubeconfigContents), 0600)).To(Succeed()) proxy := newProxy( // dont't give an explicit path but rather define the file in the @@ -222,11 +221,11 @@ func TestProxyCurrentNamespace(t *testing.T) { if len(tt.kubeconfigPath) != 0 { configFile = tt.kubeconfigPath } else { - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) configFile = filepath.Join(dir, ".test-kubeconfig.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte(tt.kubeconfigContents), 0600)).To(Succeed()) } proxy := newProxy(Kubeconfig{Path: configFile, Context: tt.kubeconfigContext}) diff --git a/cmd/clusterctl/client/cluster/template.go b/cmd/clusterctl/client/cluster/template.go index fdc414b6e8be..ce4c31e55f7a 100644 --- a/cmd/clusterctl/client/cluster/template.go +++ b/cmd/clusterctl/client/cluster/template.go @@ -19,7 +19,6 @@ package cluster import ( "context" "encoding/base64" - "io/ioutil" "net/http" "net/url" "os" @@ -152,7 +151,7 @@ func (t *templateClient) getLocalFileContent(rURL *url.URL) ([]byte, error) { if f.IsDir() { return nil, errors.Errorf("invalid path: file %q is actually a directory", rURL.Path) } - content, err := ioutil.ReadFile(rURL.Path) + content, err := os.ReadFile(rURL.Path) if err != nil { return nil, errors.Wrapf(err, "failed to read file %q", rURL.Path) } diff --git a/cmd/clusterctl/client/cluster/template_test.go b/cmd/clusterctl/client/cluster/template_test.go index 3309cc9dc2c3..72379b0d700e 100644 --- a/cmd/clusterctl/client/cluster/template_test.go +++ b/cmd/clusterctl/client/cluster/template_test.go @@ -19,7 +19,6 @@ package cluster import ( "encoding/base64" "fmt" - "io/ioutil" "net/http" "net/url" "os" @@ -229,12 +228,12 @@ func Test_templateClient_getGitHubFileContent(t *testing.T) { func Test_templateClient_getLocalFileContent(t *testing.T) { g := NewWithT(t) - tmpDir, err := ioutil.TempDir("", "cc") + tmpDir, err := os.MkdirTemp("", "cc") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(tmpDir) path := filepath.Join(tmpDir, "cluster-template.yaml") - g.Expect(ioutil.WriteFile(path, []byte(template), 0600)).To(Succeed()) + g.Expect(os.WriteFile(path, []byte(template), 0600)).To(Succeed()) type args struct { rURL *url.URL @@ -283,7 +282,7 @@ func Test_templateClient_getLocalFileContent(t *testing.T) { func Test_templateClient_GetFromURL(t *testing.T) { g := NewWithT(t) - tmpDir, err := ioutil.TempDir("", "cc") + tmpDir, err := os.MkdirTemp("", "cc") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(tmpDir) @@ -306,7 +305,7 @@ func Test_templateClient_GetFromURL(t *testing.T) { }) path := filepath.Join(tmpDir, "cluster-template.yaml") - g.Expect(ioutil.WriteFile(path, []byte(template), 0600)).To(Succeed()) + g.Expect(os.WriteFile(path, []byte(template), 0600)).To(Succeed()) type args struct { templateURL string diff --git a/cmd/clusterctl/client/config.go b/cmd/clusterctl/client/config.go index f96c96ffaafa..81148c43a376 100644 --- a/cmd/clusterctl/client/config.go +++ b/cmd/clusterctl/client/config.go @@ -18,7 +18,6 @@ package client import ( "io" - "io/ioutil" "strconv" "k8s.io/utils/pointer" @@ -82,7 +81,7 @@ func (c *clusterctlClient) ProcessYAML(options ProcessYAMLOptions) (YamlPrinter, if options.ReaderSource != nil { // NOTE: Beware of potentially reading in large files all at once // since this is inefficient and increases memory utilziation. - content, err := ioutil.ReadAll(options.ReaderSource.Reader) + content, err := io.ReadAll(options.ReaderSource.Reader) if err != nil { return nil, err } diff --git a/cmd/clusterctl/client/config/reader_viper_test.go b/cmd/clusterctl/client/config/reader_viper_test.go index 60545989f2de..4cc834b278d8 100644 --- a/cmd/clusterctl/client/config/reader_viper_test.go +++ b/cmd/clusterctl/client/config/reader_viper_test.go @@ -18,7 +18,6 @@ package config import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -34,19 +33,19 @@ func Test_viperReader_Init(t *testing.T) { // Change HOME dir and do not specify config file // (.cluster-api/clusterctl) in it. - clusterctlHomeDir, err := ioutil.TempDir("", "clusterctl-default") + clusterctlHomeDir, err := os.MkdirTemp("", "clusterctl-default") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(clusterctlHomeDir) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) configFile := filepath.Join(dir, "clusterctl.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) configFileBadContents := filepath.Join(dir, "clusterctl-bad.yaml") - g.Expect(ioutil.WriteFile(configFileBadContents, []byte("bad-contents"), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFileBadContents, []byte("bad-contents"), 0600)).To(Succeed()) // To test the remote config file ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -122,14 +121,14 @@ func Test_viperReader_Init(t *testing.T) { func Test_viperReader_Get(t *testing.T) { g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) os.Setenv("FOO", "foo") configFile := filepath.Join(dir, "clusterctl.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) type args struct { key string @@ -187,7 +186,7 @@ func Test_viperReader_Get(t *testing.T) { func Test_viperReader_GetWithoutDefaultConfig(t *testing.T) { g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) @@ -204,7 +203,7 @@ func Test_viperReader_GetWithoutDefaultConfig(t *testing.T) { func Test_viperReader_Set(t *testing.T) { g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) @@ -212,7 +211,7 @@ func Test_viperReader_Set(t *testing.T) { configFile := filepath.Join(dir, "clusterctl.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) type args struct { key string @@ -251,13 +250,13 @@ func Test_viperReader_Set(t *testing.T) { func Test_viperReader_checkDefaultConfig(t *testing.T) { g := NewWithT(t) - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) dir = strings.TrimSuffix(dir, "/") configFile := filepath.Join(dir, "clusterctl.yaml") - g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) + g.Expect(os.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed()) type fields struct { configPaths []string diff --git a/cmd/clusterctl/client/config_test.go b/cmd/clusterctl/client/config_test.go index e1daef914607..348f223c9dc1 100644 --- a/cmd/clusterctl/client/config_test.go +++ b/cmd/clusterctl/client/config_test.go @@ -18,7 +18,6 @@ package client import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -438,12 +437,12 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) { rawTemplate := templateYAML("ns3", "${ CLUSTER_NAME }") // Template on a file - tmpDir, err := ioutil.TempDir("", "cc") + tmpDir, err := os.MkdirTemp("", "cc") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(tmpDir) path := filepath.Join(tmpDir, "cluster-template.yaml") - g.Expect(ioutil.WriteFile(path, rawTemplate, 0600)).To(Succeed()) + g.Expect(os.WriteFile(path, rawTemplate, 0600)).To(Succeed()) // Template on a repository & in a ConfigMap configMap := &corev1.ConfigMap{ @@ -620,12 +619,12 @@ func Test_clusterctlClient_ProcessYAML(t *testing.T) { template := `v1: ${VAR1:=default1} v2: ${VAR2=default2} v3: ${VAR3:-default3}` - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(dir) templateFile := filepath.Join(dir, "template.yaml") - g.Expect(ioutil.WriteFile(templateFile, []byte(template), 0600)).To(Succeed()) + g.Expect(os.WriteFile(templateFile, []byte(template), 0600)).To(Succeed()) inputReader := strings.NewReader(template) diff --git a/cmd/clusterctl/client/repository/overrides.go b/cmd/clusterctl/client/repository/overrides.go index a9677a5aef92..91337671901c 100644 --- a/cmd/clusterctl/client/repository/overrides.go +++ b/cmd/clusterctl/client/repository/overrides.go @@ -17,7 +17,6 @@ limitations under the License. package repository import ( - "io/ioutil" "os" "path/filepath" "strings" @@ -86,7 +85,7 @@ func getLocalOverride(info *newOverrideInput) ([]byte, error) { // it the local override exists, use it _, err := os.Stat(overridePath) if err == nil { - content, err := ioutil.ReadFile(overridePath) + content, err := os.ReadFile(overridePath) if err != nil { return nil, errors.Wrapf(err, "failed to read local override for %s", overridePath) } diff --git a/cmd/clusterctl/client/repository/repository_github.go b/cmd/clusterctl/client/repository/repository_github.go index 53ed95396524..3f66d6738afe 100644 --- a/cmd/clusterctl/client/repository/repository_github.go +++ b/cmd/clusterctl/client/repository/repository_github.go @@ -19,7 +19,7 @@ package repository import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "path/filepath" @@ -345,7 +345,7 @@ func (g *gitHubRepository) downloadFilesFromRelease(release *github.RepositoryRe defer reader.Close() // Read contents from the reader (redirect or not), and return. - content, err := ioutil.ReadAll(reader) + content, err := io.ReadAll(reader) if err != nil { return nil, errors.Wrapf(err, "failed to read downloaded file %q from %q release", *release.TagName, fileName) } diff --git a/cmd/clusterctl/client/repository/repository_local.go b/cmd/clusterctl/client/repository/repository_local.go index 01b0e72db63d..ea5c134341a1 100644 --- a/cmd/clusterctl/client/repository/repository_local.go +++ b/cmd/clusterctl/client/repository/repository_local.go @@ -17,7 +17,6 @@ limitations under the License. package repository import ( - "io/ioutil" "net/url" "os" "path/filepath" @@ -102,7 +101,7 @@ func (r *localRepository) GetFile(version, fileName string) ([]byte, error) { if f.IsDir() { return nil, errors.Errorf("invalid path: file %q is actually a directory %q", fileName, absolutePath) } - content, err := ioutil.ReadFile(absolutePath) + content, err := os.ReadFile(absolutePath) if err != nil { return nil, errors.Wrapf(err, "failed to read file %q from local release %s", absolutePath, version) } @@ -113,7 +112,7 @@ func (r *localRepository) GetFile(version, fileName string) ([]byte, error) { func (r *localRepository) GetVersions() ([]string, error) { // get all the sub-directories under {basepath}/{provider-id}/ releasesPath := filepath.Join(r.basepath, r.providerLabel) - files, err := ioutil.ReadDir(releasesPath) + files, err := os.ReadDir(releasesPath) if err != nil { return nil, errors.Wrap(err, "failed to list release directories") } diff --git a/cmd/clusterctl/client/repository/repository_local_test.go b/cmd/clusterctl/client/repository/repository_local_test.go index f6218beacae1..42c4e90a1cf1 100644 --- a/cmd/clusterctl/client/repository/repository_local_test.go +++ b/cmd/clusterctl/client/repository/repository_local_test.go @@ -17,7 +17,6 @@ limitations under the License. package repository import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -126,7 +125,7 @@ func Test_localRepository_newLocalRepository(t *testing.T) { } func createTempDir(t *testing.T) string { - dir, err := ioutil.TempDir("", "cc") + dir, err := os.MkdirTemp("", "cc") if err != nil { t.Fatalf("err: %s", err) } @@ -139,7 +138,7 @@ func createLocalTestProviderFile(t *testing.T, tmpDir, path, msg string) string dst := filepath.Join(tmpDir, path) // Create all directories in the standard layout g.Expect(os.MkdirAll(filepath.Dir(dst), 0755)).To(Succeed()) - g.Expect(ioutil.WriteFile(dst, []byte(msg), 0600)).To(Succeed()) + g.Expect(os.WriteFile(dst, []byte(msg), 0600)).To(Succeed()) return dst } diff --git a/cmd/clusterctl/cmd/config_repositories_test.go b/cmd/clusterctl/cmd/config_repositories_test.go index de8a1c19c6b9..0d61068d3510 100644 --- a/cmd/clusterctl/cmd/config_repositories_test.go +++ b/cmd/clusterctl/cmd/config_repositories_test.go @@ -18,7 +18,7 @@ package cmd import ( "bytes" - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -30,19 +30,19 @@ func Test_runGetRepositories(t *testing.T) { t.Run("prints output", func(t *testing.T) { g := NewWithT(t) - tmpDir, err := ioutil.TempDir("", "cc") + tmpDir, err := os.MkdirTemp("", "cc") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(tmpDir) path := filepath.Join(tmpDir, "clusterctl.yaml") - g.Expect(ioutil.WriteFile(path, []byte(template), 0600)).To(Succeed()) + g.Expect(os.WriteFile(path, []byte(template), 0600)).To(Succeed()) buf := bytes.NewBufferString("") for _, val := range RepositoriesOutputs { cro.output = val g.Expect(runGetRepositories(path, buf)).To(Succeed()) - out, err := ioutil.ReadAll(buf) + out, err := io.ReadAll(buf) g.Expect(err).ToNot(HaveOccurred()) if val == RepositoriesOutputText { @@ -67,12 +67,12 @@ func Test_runGetRepositories(t *testing.T) { t.Run("returns error for bad template", func(t *testing.T) { g := NewWithT(t) - tmpDir, err := ioutil.TempDir("", "cc") + tmpDir, err := os.MkdirTemp("", "cc") g.Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(tmpDir) path := filepath.Join(tmpDir, "clusterctl.yaml") - g.Expect(ioutil.WriteFile(path, []byte("providers: foobar"), 0600)).To(Succeed()) + g.Expect(os.WriteFile(path, []byte("providers: foobar"), 0600)).To(Succeed()) buf := bytes.NewBufferString("") g.Expect(runGetRepositories(path, buf)).ToNot(Succeed()) diff --git a/cmd/clusterctl/cmd/generate_yaml_test.go b/cmd/clusterctl/cmd/generate_yaml_test.go index 993d3190fa26..460183d23595 100644 --- a/cmd/clusterctl/cmd/generate_yaml_test.go +++ b/cmd/clusterctl/cmd/generate_yaml_test.go @@ -19,7 +19,6 @@ package cmd import ( "bytes" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -108,7 +107,7 @@ v3: default3 return } - output, err := ioutil.ReadAll(buf) + output, err := io.ReadAll(buf) g.Expect(err).ToNot(HaveOccurred()) g.Expect(string(output)).To(Equal(tt.expectedOutput)) }) @@ -118,11 +117,11 @@ v3: default3 // createTempFile creates a temporary yaml file inside a temp dir. It returns // the filepath and a cleanup function for the temp directory. func createTempFile(g *WithT, contents string) (string, func()) { - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) templateFile := filepath.Join(dir, "templ.yaml") - g.Expect(ioutil.WriteFile(templateFile, []byte(contents), 0600)).To(Succeed()) + g.Expect(os.WriteFile(templateFile, []byte(contents), 0600)).To(Succeed()) return templateFile, func() { os.RemoveAll(dir) diff --git a/cmd/clusterctl/cmd/version_checker.go b/cmd/clusterctl/cmd/version_checker.go index ab141a6234aa..c4c70e46392e 100644 --- a/cmd/clusterctl/cmd/version_checker.go +++ b/cmd/clusterctl/cmd/version_checker.go @@ -19,7 +19,6 @@ package cmd import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -173,14 +172,14 @@ func writeStateFile(path string, vs *VersionState) error { if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { return err } - if err := ioutil.WriteFile(path, vsb, 0600); err != nil { + if err := os.WriteFile(path, vsb, 0600); err != nil { return err } return nil } func readStateFile(filepath string) (*VersionState, error) { - b, err := ioutil.ReadFile(filepath) + b, err := os.ReadFile(filepath) if err != nil { if os.IsNotExist(err) { // if the file doesn't exist yet, don't error diff --git a/cmd/clusterctl/cmd/version_checker_test.go b/cmd/clusterctl/cmd/version_checker_test.go index bfc7b4969b64..d83dc08d5f0e 100644 --- a/cmd/clusterctl/cmd/version_checker_test.go +++ b/cmd/clusterctl/cmd/version_checker_test.go @@ -18,7 +18,6 @@ package cmd import ( "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -281,7 +280,7 @@ func TestVersionChecker_WriteStateFile(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) // ensure that the state file has been created g.Expect(tmpVersionFile).Should(BeARegularFile()) - fb, err := ioutil.ReadFile(tmpVersionFile) + fb, err := os.ReadFile(tmpVersionFile) g.Expect(err).ToNot(HaveOccurred()) var actualVersionState VersionState g.Expect(yaml.Unmarshal(fb, &actualVersionState)).To(Succeed()) @@ -375,7 +374,7 @@ func TestVersionChecker_ReadFromStateFileWithin24Hrs(t *testing.T) { } func generateTempVersionFilePath(g *WithT) (string, func()) { - dir, err := ioutil.TempDir("", "clusterctl") + dir, err := os.MkdirTemp("", "clusterctl") g.Expect(err).NotTo(HaveOccurred()) // don't create the state file, just have a path to the file tmpVersionFile := filepath.Join(dir, "clusterctl", "state.yaml") diff --git a/hack/tools/mdbook/embed/embed.go b/hack/tools/mdbook/embed/embed.go index 2e9d79f4754d..f12203e222a8 100644 --- a/hack/tools/mdbook/embed/embed.go +++ b/hack/tools/mdbook/embed/embed.go @@ -19,7 +19,7 @@ limitations under the License. package main import ( - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -58,7 +58,7 @@ func (l Embed) Process(input *plugin.Input) error { } defer resp.Body.Close() - out, err := ioutil.ReadAll(resp.Body) + out, err := io.ReadAll(resp.Body) return string(out), err }) } diff --git a/hack/tools/mdbook/releaselink/releaselink.go b/hack/tools/mdbook/releaselink/releaselink.go index da9f06b34ef3..44da84349289 100644 --- a/hack/tools/mdbook/releaselink/releaselink.go +++ b/hack/tools/mdbook/releaselink/releaselink.go @@ -20,7 +20,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "log" "net/http" "net/url" @@ -70,7 +70,7 @@ func (l ReleaseLink) Process(input *plugin.Input) error { } defer resp.Body.Close() - out, err := ioutil.ReadAll(resp.Body) + out, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/netlify.toml b/netlify.toml index 28a9bf907925..db669f5ba269 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,6 +3,9 @@ command = "make -C docs/book build" publish = "docs/book/book" +[build.environment] + GO_VERSION = "1.16" + # Standard Netlify redirects [[redirects]] from = "https://master--kubernetes-sigs-cluster-api.netlify.com/*" diff --git a/test/framework/alltypes_helpers.go b/test/framework/alltypes_helpers.go index 479194f1d87c..55d5277e70c2 100644 --- a/test/framework/alltypes_helpers.go +++ b/test/framework/alltypes_helpers.go @@ -20,7 +20,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -146,7 +145,7 @@ func dumpObject(resource runtime.Object, logPath string) { Expect(err).ToNot(HaveOccurred(), "Failed to open %s", resourceFilePath) defer f.Close() - Expect(ioutil.WriteFile(f.Name(), resourceYAML, 0600)).To(Succeed(), "Failed to write %s", resourceFilePath) + Expect(os.WriteFile(f.Name(), resourceYAML, 0600)).To(Succeed(), "Failed to write %s", resourceFilePath) } // capiProviderOptions returns a set of ListOptions that allows to identify all the objects belonging to Cluster API providers. diff --git a/test/framework/bootstrap/kind_provider.go b/test/framework/bootstrap/kind_provider.go index 0f258cf96595..7b81bab13845 100644 --- a/test/framework/bootstrap/kind_provider.go +++ b/test/framework/bootstrap/kind_provider.go @@ -18,7 +18,6 @@ package bootstrap import ( "context" - "io/ioutil" "os" . "github.com/onsi/gomega" @@ -86,7 +85,7 @@ func (k *kindClusterProvider) Create(ctx context.Context) { // Sets the kubeconfig path to a temp file. // NB. the ClusterProvider is responsible for the cleanup of this file - f, err := ioutil.TempFile("", "e2e-kind") + f, err := os.CreateTemp("", "e2e-kind") Expect(err).ToNot(HaveOccurred(), "Failed to create kubeconfig file for the kind cluster %q", k.name) k.kubeconfigPath = f.Name() diff --git a/test/framework/bootstrap/kind_util.go b/test/framework/bootstrap/kind_util.go index f625e817b9a6..698d81f2150f 100644 --- a/test/framework/bootstrap/kind_util.go +++ b/test/framework/bootstrap/kind_util.go @@ -18,7 +18,6 @@ package bootstrap import ( "context" - "io/ioutil" "os" "path/filepath" @@ -111,7 +110,7 @@ func LoadImagesToKindCluster(ctx context.Context, input LoadImagesToKindClusterI // LoadImage will put a local image onto the kind node. func loadImage(ctx context.Context, cluster, image string) error { // Save the image into a tar - dir, err := ioutil.TempDir("", "image-tar") + dir, err := os.MkdirTemp("", "image-tar") if err != nil { return errors.Wrap(err, "failed to create tempdir") } diff --git a/test/framework/cluster_proxy.go b/test/framework/cluster_proxy.go index 4083ad249caf..85387c4e0e44 100644 --- a/test/framework/cluster_proxy.go +++ b/test/framework/cluster_proxy.go @@ -19,7 +19,6 @@ package framework import ( "context" "fmt" - "io/ioutil" "net/url" "os" "path" @@ -129,7 +128,7 @@ func NewClusterProxy(name string, kubeconfigPath string, scheme *runtime.Scheme, // newFromAPIConfig returns a clusterProxy given a api.Config and the scheme defining the types hosted in the cluster. func newFromAPIConfig(name string, config *api.Config, scheme *runtime.Scheme) ClusterProxy { // NB. the ClusterProvider is responsible for the cleanup of this file - f, err := ioutil.TempFile("", "e2e-kubeconfig") + f, err := os.CreateTemp("", "e2e-kubeconfig") Expect(err).ToNot(HaveOccurred(), "Failed to create kubeconfig file for the kind cluster %q") kubeconfigPath := f.Name() diff --git a/test/framework/clusterctl/clusterctl_config.go b/test/framework/clusterctl/clusterctl_config.go index 513c18e08d43..f75c4ab71ce2 100644 --- a/test/framework/clusterctl/clusterctl_config.go +++ b/test/framework/clusterctl/clusterctl_config.go @@ -17,7 +17,7 @@ limitations under the License. package clusterctl import ( - "io/ioutil" + "os" . "github.com/onsi/gomega" @@ -45,5 +45,5 @@ func (c *clusterctlConfig) write() { data, err := yaml.Marshal(c.Values) Expect(err).ToNot(HaveOccurred(), "Failed to convert to yaml the clusterctl config file") - Expect(ioutil.WriteFile(c.Path, data, 0600)).To(Succeed(), "Failed to write the clusterctl config file") + Expect(os.WriteFile(c.Path, data, 0600)).To(Succeed(), "Failed to write the clusterctl config file") } diff --git a/test/framework/clusterctl/clusterctl_helpers.go b/test/framework/clusterctl/clusterctl_helpers.go index b8ccdc81aa54..47928806ad34 100644 --- a/test/framework/clusterctl/clusterctl_helpers.go +++ b/test/framework/clusterctl/clusterctl_helpers.go @@ -18,7 +18,6 @@ package clusterctl import ( "context" - "io/ioutil" "os" "path/filepath" @@ -173,7 +172,7 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate log.Logf("Installing a CNI plugin to the workload cluster") workloadCluster := input.ClusterProxy.GetWorkloadCluster(ctx, result.Cluster.Namespace, result.Cluster.Name) - cniYaml, err := ioutil.ReadFile(input.CNIManifestPath) + cniYaml, err := os.ReadFile(input.CNIManifestPath) Expect(err).ShouldNot(HaveOccurred()) Expect(workloadCluster.Apply(ctx, cniYaml)).ShouldNot(HaveOccurred()) diff --git a/test/framework/clusterctl/e2e_config.go b/test/framework/clusterctl/e2e_config.go index 0489c4616513..2c031a9d8cda 100644 --- a/test/framework/clusterctl/e2e_config.go +++ b/test/framework/clusterctl/e2e_config.go @@ -19,7 +19,6 @@ package clusterctl import ( "context" "fmt" - "io/ioutil" "net/url" "os" "path/filepath" @@ -49,7 +48,7 @@ type LoadE2EConfigInput struct { // LoadE2EConfig loads the configuration for the e2e test environment. func LoadE2EConfig(ctx context.Context, input LoadE2EConfigInput) *E2EConfig { - configData, err := ioutil.ReadFile(input.ConfigPath) + configData, err := os.ReadFile(input.ConfigPath) Expect(err).ToNot(HaveOccurred(), "Failed to read the e2e test config file") Expect(configData).ToNot(BeEmpty(), "The e2e test config file should not be empty") diff --git a/test/framework/clusterctl/repository.go b/test/framework/clusterctl/repository.go index d32f0753a4ed..36a4383249f2 100644 --- a/test/framework/clusterctl/repository.go +++ b/test/framework/clusterctl/repository.go @@ -20,7 +20,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -58,7 +58,7 @@ type CreateRepositoryInput struct { // NOTE: this transformation is specifically designed for replacing "data: ${envSubstVar}". func (i *CreateRepositoryInput) RegisterClusterResourceSetConfigMapTransformation(manifestPath, envSubstVar string) { By(fmt.Sprintf("Reading the ClusterResourceSet manifest %s", manifestPath)) - manifestData, err := ioutil.ReadFile(manifestPath) + manifestData, err := os.ReadFile(manifestPath) Expect(err).ToNot(HaveOccurred(), "Failed to read the ClusterResourceSet manifest file") Expect(manifestData).ToNot(BeEmpty(), "ClusterResourceSet manifest file should not be empty") @@ -91,12 +91,12 @@ func CreateRepository(ctx context.Context, input CreateRepositoryInput) string { Expect(os.MkdirAll(sourcePath, 0755)).To(Succeed(), "Failed to create the clusterctl local repository folder for %q / %q", providerLabel, version.Name) filePath := filepath.Join(sourcePath, "components.yaml") - Expect(ioutil.WriteFile(filePath, manifest, 0600)).To(Succeed(), "Failed to write manifest in the clusterctl local repository for %q / %q", providerLabel, version.Name) + Expect(os.WriteFile(filePath, manifest, 0600)).To(Succeed(), "Failed to write manifest in the clusterctl local repository for %q / %q", providerLabel, version.Name) destinationPath := filepath.Join(input.RepositoryFolder, providerLabel, version.Name, "components.yaml") allFiles := append(provider.Files, version.Files...) for _, file := range allFiles { - data, err := ioutil.ReadFile(file.SourcePath) + data, err := os.ReadFile(file.SourcePath) Expect(err).ToNot(HaveOccurred(), "Failed to read file %q / %q", provider.Name, file.SourcePath) // Applies FileTransformations if defined @@ -106,7 +106,7 @@ func CreateRepository(ctx context.Context, input CreateRepositoryInput) string { } destinationFile := filepath.Join(filepath.Dir(destinationPath), file.TargetName) - Expect(ioutil.WriteFile(destinationFile, data, 0600)).To(Succeed(), "Failed to write clusterctl local repository file %q / %q", provider.Name, file.TargetName) + Expect(os.WriteFile(destinationFile, data, 0600)).To(Succeed(), "Failed to write clusterctl local repository file %q / %q", provider.Name, file.TargetName) } } providers = append(providers, providerConfig{ @@ -183,7 +183,7 @@ func getComponentSourceFromURL(source ProviderVersionSource) ([]byte, error) { // url.Parse always lower cases scheme switch u.Scheme { case "", fileURIScheme: - buf, err = ioutil.ReadFile(u.Path) + buf, err = os.ReadFile(u.Path) if err != nil { return nil, errors.Wrap(err, "failed to read file") } @@ -193,7 +193,7 @@ func getComponentSourceFromURL(source ProviderVersionSource) ([]byte, error) { return nil, err } defer resp.Body.Close() - buf, err = ioutil.ReadAll(resp.Body) + buf, err = io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/test/framework/deployment_helpers.go b/test/framework/deployment_helpers.go index c21874a4b863..36eee3c833fe 100644 --- a/test/framework/deployment_helpers.go +++ b/test/framework/deployment_helpers.go @@ -21,7 +21,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -219,7 +218,7 @@ func dumpPodMetrics(ctx context.Context, client *kubernetes.Clientset, metricsPa metricsFile = path.Join(metricsDir, "metrics-error.txt") } - if err := ioutil.WriteFile(metricsFile, data, 0600); err != nil { + if err := os.WriteFile(metricsFile, data, 0600); err != nil { // Failing to dump metrics should not cause the test to fail log.Logf("Error writing metrics for pod %s/%s: %v", pod.Namespace, pod.Name, err) } diff --git a/test/framework/docker_logcollector.go b/test/framework/docker_logcollector.go index a8d06579df6d..e4d8bcceb5ab 100644 --- a/test/framework/docker_logcollector.go +++ b/test/framework/docker_logcollector.go @@ -19,7 +19,6 @@ package framework import ( "context" "fmt" - "io/ioutil" "os" osExec "os/exec" "path/filepath" @@ -58,7 +57,7 @@ func (k DockerLogCollector) CollectMachineLog(ctx context.Context, managementClu } copyDirFn := func(containerDir, dirName string) func() error { return func() error { - f, err := ioutil.TempFile("", containerName) + f, err := os.CreateTemp("", containerName) if err != nil { return err } diff --git a/test/framework/exec/command.go b/test/framework/exec/command.go index fe466d9db9ca..89dcdb179f7d 100644 --- a/test/framework/exec/command.go +++ b/test/framework/exec/command.go @@ -19,7 +19,6 @@ package exec import ( "context" "io" - "io/ioutil" "os/exec" "github.com/pkg/errors" @@ -86,11 +85,11 @@ func (c *Command) Run(ctx context.Context) ([]byte, []byte, error) { if err := cmd.Start(); err != nil { return nil, nil, errors.WithStack(err) } - output, err := ioutil.ReadAll(stdout) + output, err := io.ReadAll(stdout) if err != nil { return nil, nil, errors.WithStack(err) } - errout, err := ioutil.ReadAll(stderr) + errout, err := io.ReadAll(stderr) if err != nil { return nil, nil, errors.WithStack(err) } diff --git a/test/framework/kubernetesversions/template.go b/test/framework/kubernetesversions/template.go index 5a03403c66de..182ac6445bd3 100644 --- a/test/framework/kubernetesversions/template.go +++ b/test/framework/kubernetesversions/template.go @@ -19,7 +19,6 @@ package kubernetesversions import ( _ "embed" "errors" - "io/ioutil" "os" "os/exec" "path" @@ -88,7 +87,7 @@ func GenerateCIArtifactsInjectedTemplateForDebian(input GenerateCIArtifactsInjec kustomizedTemplate := path.Join(templateDir, "cluster-template-conformance-ci-artifacts.yaml") - if err := ioutil.WriteFile(path.Join(overlayDir, "kustomization.yaml"), kustomizationYamlBytes, 0o600); err != nil { + if err := os.WriteFile(path.Join(overlayDir, "kustomization.yaml"), kustomizationYamlBytes, 0o600); err != nil { return "", err } @@ -97,13 +96,13 @@ func GenerateCIArtifactsInjectedTemplateForDebian(input GenerateCIArtifactsInjec return "", err } - if err := ioutil.WriteFile(path.Join(overlayDir, "kustomizeversions.yaml"), kustomizeVersions, 0o600); err != nil { + if err := os.WriteFile(path.Join(overlayDir, "kustomizeversions.yaml"), kustomizeVersions, 0o600); err != nil { return "", err } - if err := ioutil.WriteFile(path.Join(overlayDir, "ci-artifacts-source-template.yaml"), input.SourceTemplate, 0o600); err != nil { + if err := os.WriteFile(path.Join(overlayDir, "ci-artifacts-source-template.yaml"), input.SourceTemplate, 0o600); err != nil { return "", err } - if err := ioutil.WriteFile(path.Join(overlayDir, "platform-kustomization.yaml"), input.PlatformKustomization, 0o600); err != nil { + if err := os.WriteFile(path.Join(overlayDir, "platform-kustomization.yaml"), input.PlatformKustomization, 0o600); err != nil { return "", err } cmd := exec.Command("kustomize", "build", overlayDir) @@ -111,7 +110,7 @@ func GenerateCIArtifactsInjectedTemplateForDebian(input GenerateCIArtifactsInjec if err != nil { return "", err } - if err := ioutil.WriteFile(kustomizedTemplate, data, 0o600); err != nil { + if err := os.WriteFile(kustomizedTemplate, data, 0o600); err != nil { return "", err } return kustomizedTemplate, nil diff --git a/test/framework/kubernetesversions/versions.go b/test/framework/kubernetesversions/versions.go index bbb10451618d..958d4af223f9 100644 --- a/test/framework/kubernetesversions/versions.go +++ b/test/framework/kubernetesversions/versions.go @@ -18,7 +18,7 @@ package kubernetesversions import ( "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -38,7 +38,7 @@ func LatestCIRelease() (string, error) { return "", err } defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return "", err } @@ -57,7 +57,7 @@ func LatestPatchRelease(searchVersion string) (string, error) { return "", err } defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/test/framework/kubetest/run.go b/test/framework/kubetest/run.go index feb8d3800b47..6ad362e9a43f 100644 --- a/test/framework/kubetest/run.go +++ b/test/framework/kubetest/run.go @@ -18,7 +18,6 @@ package kubetest import ( "context" - "io/ioutil" "os" "os/exec" "os/user" @@ -220,7 +219,7 @@ func countClusterNodes(ctx context.Context, proxy framework.ClusterProxy) (int, } func isSELinuxEnforcing() bool { - dat, err := ioutil.ReadFile("/sys/fs/selinux/enforce") + dat, err := os.ReadFile("/sys/fs/selinux/enforce") if err != nil { return false } diff --git a/test/helpers/envtest.go b/test/helpers/envtest.go index 4daaa0a0c05c..df7071c6bda3 100644 --- a/test/helpers/envtest.go +++ b/test/helpers/envtest.go @@ -19,8 +19,8 @@ package helpers import ( "context" "fmt" - "io/ioutil" "net" + "os" "path" "path/filepath" goruntime "runtime" @@ -226,7 +226,7 @@ func initializeWebhookInEnvironment() { // Get the root of the current file to use in CRD paths. _, filename, _, _ := goruntime.Caller(0) //nolint root := path.Join(path.Dir(filename), "..", "..") - configyamlFile, err := ioutil.ReadFile(filepath.Join(root, "config", "webhook", "manifests.yaml")) + configyamlFile, err := os.ReadFile(filepath.Join(root, "config", "webhook", "manifests.yaml")) if err != nil { klog.Fatalf("Failed to read core webhook configuration file: %v ", err) } @@ -239,7 +239,7 @@ func initializeWebhookInEnvironment() { klog.Fatalf("Failed to append core controller webhook config: %v", err) } - bootstrapyamlFile, err := ioutil.ReadFile(filepath.Join(root, "bootstrap", "kubeadm", "config", "webhook", "manifests.yaml")) + bootstrapyamlFile, err := os.ReadFile(filepath.Join(root, "bootstrap", "kubeadm", "config", "webhook", "manifests.yaml")) if err != nil { klog.Fatalf("Failed to get bootstrap yaml file: %v", err) } @@ -248,7 +248,7 @@ func initializeWebhookInEnvironment() { if err != nil { klog.Fatalf("Failed to append bootstrap controller webhook config: %v", err) } - controlplaneyamlFile, err := ioutil.ReadFile(filepath.Join(root, "controlplane", "kubeadm", "config", "webhook", "manifests.yaml")) + controlplaneyamlFile, err := os.ReadFile(filepath.Join(root, "controlplane", "kubeadm", "config", "webhook", "manifests.yaml")) if err != nil { klog.Fatalf(" Failed to get controlplane yaml file err: %v", err) } diff --git a/test/infrastructure/docker/docker/machine.go b/test/infrastructure/docker/docker/machine.go index 480fd959bbe8..f11d7b273acd 100644 --- a/test/infrastructure/docker/docker/machine.go +++ b/test/infrastructure/docker/docker/machine.go @@ -21,7 +21,6 @@ import ( "context" "encoding/base64" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -250,7 +249,7 @@ func kindMounts(mounts []infrav1.Mount) []v1alpha4.Mount { func (m *Machine) PreloadLoadImages(ctx context.Context, images []string) error { // Save the image into a tar - dir, err := ioutil.TempDir("", "image-tar") + dir, err := os.MkdirTemp("", "image-tar") if err != nil { return errors.Wrap(err, "failed to create tempdir") } diff --git a/util/yaml/yaml_test.go b/util/yaml/yaml_test.go index e388a81456b6..e7170471ca46 100644 --- a/util/yaml/yaml_test.go +++ b/util/yaml/yaml_test.go @@ -17,7 +17,6 @@ limitations under the License. package yaml import ( - "io/ioutil" "os" "testing" @@ -304,7 +303,7 @@ func TestParseMachineYaml(t *testing.T) { } func createTempFile(contents string) (filename string, reterr error) { - f, err := ioutil.TempFile("", "") + f, err := os.CreateTemp("", "") if err != nil { return "", err }