From 77bb29b05e7ed5b87c28929910e4032149dbad47 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Fri, 8 Sep 2023 11:54:52 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil Signed-off-by: guoguangwu --- cmd/install.go | 9 ++++----- cmd/install_test.go | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 1cd7748b..5798482d 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -3,7 +3,6 @@ package cmd import ( "bytes" "fmt" - "io/ioutil" "log" "net" "os" @@ -428,7 +427,7 @@ kubectl get node -o wide pkg.SupportMessageShort) } - if err := ioutil.WriteFile(absPath, []byte(data), 0600); err != nil { + if err := os.WriteFile(absPath, []byte(data), 0600); err != nil { return err } @@ -437,7 +436,7 @@ kubectl get node -o wide func mergeConfigs(localKubeconfigPath, context string, k3sconfig []byte) ([]byte, error) { // Create a temporary kubeconfig to store the config of the newly create k3s cluster - file, err := ioutil.TempFile(os.TempDir(), "k3s-temp-*") + file, err := os.CreateTemp(os.TempDir(), "k3s-temp-*") if err != nil { return nil, fmt.Errorf("could not generate a temporary file to store the kubeconfig: %w", err) } @@ -498,7 +497,7 @@ func sshAgent(publicKeyPath string) (ssh.AuthMethod, func() error) { return nil, sshAgentConn.Close } - pubkey, err := ioutil.ReadFile(publicKeyPath) + pubkey, err := os.ReadFile(publicKeyPath) if err != nil { return nil, sshAgentConn.Close } @@ -521,7 +520,7 @@ func sshAgent(publicKeyPath string) (ssh.AuthMethod, func() error) { func loadPublickey(path string) (ssh.AuthMethod, func() error, error) { noopCloseFunc := func() error { return nil } - key, err := ioutil.ReadFile(path) + key, err := os.ReadFile(path) if err != nil { return nil, noopCloseFunc, fmt.Errorf("unable to read file: %s, %s", path, err) } diff --git a/cmd/install_test.go b/cmd/install_test.go index 56da64a0..c25bb497 100644 --- a/cmd/install_test.go +++ b/cmd/install_test.go @@ -2,7 +2,6 @@ package cmd import ( "errors" - "io/ioutil" "os" "regexp" "strings" @@ -48,7 +47,7 @@ kfFJfrUjElq6Bx9oPPxc2vD40gqnYL57A+Y+X+A0kL4fO7pfh2VxOw== func Test_loadPublickeyEncrypted(t *testing.T) { want := &ssh.PassphraseMissingError{} - tmpfile, err := ioutil.TempFile("", "key") + tmpfile, err := os.CreateTemp("", "key") if err != nil { t.Error(err) }