From 555f391dd732235b973445c4417e4ed3d60feb46 Mon Sep 17 00:00:00 2001 From: fd Date: Thu, 22 Aug 2024 16:02:10 +0200 Subject: [PATCH] Remove deprecated ioutil --- cmd/kubernetes/kubernetes_app_remove.go | 7 +++---- cmd/sshkey/ssh_key_create.go | 3 +-- utility/kubernetes.go | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/cmd/kubernetes/kubernetes_app_remove.go b/cmd/kubernetes/kubernetes_app_remove.go index 60dc9bc9..5271a516 100644 --- a/cmd/kubernetes/kubernetes_app_remove.go +++ b/cmd/kubernetes/kubernetes_app_remove.go @@ -3,7 +3,6 @@ package kubernetes import ( "bytes" "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -43,12 +42,12 @@ var kubernetesAppRemoveCmd = &cobra.Command{ } allApps := strings.Split(args[0], ",") - tmpFile, err := ioutil.TempFile(os.TempDir(), "kubeconfig-") + tmpFile, err := os.CreateTemp(os.TempDir(), "kubeconfig-") if err != nil { - utility.Error("Cannot create temporary file", err) + utility.Error("Cannot create temporary file: %v", err) } if _, err = tmpFile.Write([]byte(kube.KubeConfig)); err != nil { - utility.Error("Failed to write to temporary file", err) + utility.Error("Failed to write to temporary file: %v", err) } defer os.Remove(tmpFile.Name()) for _, split := range allApps { diff --git a/cmd/sshkey/ssh_key_create.go b/cmd/sshkey/ssh_key_create.go index d564ca1c..b4862f2b 100644 --- a/cmd/sshkey/ssh_key_create.go +++ b/cmd/sshkey/ssh_key_create.go @@ -2,7 +2,6 @@ package sshkey import ( "fmt" - "io/ioutil" "os" "github.com/civo/cli/common" @@ -27,7 +26,7 @@ var sshKeyCreateCmd = &cobra.Command{ } // reading the file - data, err := ioutil.ReadFile(keyCreate) + data, err := os.ReadFile(keyCreate) if err != nil { utility.Error("Reading the SSH key file failed with %s", err) os.Exit(1) diff --git a/utility/kubernetes.go b/utility/kubernetes.go index 4c5e9bfc..2497bd28 100644 --- a/utility/kubernetes.go +++ b/utility/kubernetes.go @@ -2,7 +2,6 @@ package utility import ( "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -41,7 +40,7 @@ func ObtainKubeConfig(KubeconfigFilename string, civoConfig string, merge bool, func mergeConfigs(localKubeconfigPath string, k3sconfig []byte, switchContext bool, clusterName string) ([]byte, error) { // Create a temporary kubeconfig to store the config of the newly create k3s cluster - file, err := ioutil.TempFile(os.TempDir(), "civo-temp-*") + file, err := os.CreateTemp(os.TempDir(), "civo-temp-*") if err != nil { return nil, fmt.Errorf("could not generate a temporary file to store the kuebeconfig: %s", err) } @@ -119,7 +118,7 @@ func writeConfig(path string, data []byte, suppressMessage bool, mergeConfigs bo defer file.Close() } - writeErr := ioutil.WriteFile(path, data, 0600) + writeErr := os.WriteFile(path, data, 0600) if writeErr != nil { return writeErr }