From 447ad7eacbc6035c1d8f9968bb5dfcff2ecf9b6c Mon Sep 17 00:00:00 2001 From: wangguoyan <717338097@qq.com> Date: Thu, 29 Sep 2022 09:00:10 +0800 Subject: [PATCH] replace deprecated ioutil functions Signed-off-by: wangguoyan <717338097@qq.com> --- cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go | 3 +-- cmd/kubeadm/app/phases/kubeconfig/kubeconfig_test.go | 3 +-- cmd/kubeadm/app/phases/upgrade/postupgrade.go | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go index b300146c3e9..628dccb47b8 100644 --- a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go +++ b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go @@ -22,7 +22,6 @@ import ( "crypto/x509" "fmt" "io" - "io/ioutil" "os" "path/filepath" "time" @@ -243,7 +242,7 @@ func validateKubeConfig(outDir, filename string, config *clientcmdapi.Config) er // fallback to load CA cert data from external CA file clusterCAFilePath := currentConfig.Clusters[currentCluster].CertificateAuthority if len(clusterCAFilePath) > 0 { - clusterCABytes, err := ioutil.ReadFile(clusterCAFilePath) + clusterCABytes, err := os.ReadFile(clusterCAFilePath) if err != nil { klog.Warningf("failed to load CA cert from %q for kubeconfig %q, %v", clusterCAFilePath, kubeConfigFilePath, err) } else { diff --git a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig_test.go b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig_test.go index 459f8bf3b5c..b223de52f84 100644 --- a/cmd/kubeadm/app/phases/kubeconfig/kubeconfig_test.go +++ b/cmd/kubeadm/app/phases/kubeconfig/kubeconfig_test.go @@ -22,7 +22,6 @@ import ( "crypto/x509" "fmt" "io" - "io/ioutil" "os" "path/filepath" "reflect" @@ -492,7 +491,7 @@ func TestValidateKubeConfig(t *testing.T) { if configWithSameClusterCaByExternalFile.Clusters[currentCtx.Cluster] == nil { t.Fatal("failed to find the given CurrentContext Cluster in Clusters of the kubeconfig") } - tmpfile, err := ioutil.TempFile("", "external-ca.crt") + tmpfile, err := os.CreateTemp("", "external-ca.crt") if err != nil { t.Fatal(err) } diff --git a/cmd/kubeadm/app/phases/upgrade/postupgrade.go b/cmd/kubeadm/app/phases/upgrade/postupgrade.go index c01e704e3a0..5b560e75133 100644 --- a/cmd/kubeadm/app/phases/upgrade/postupgrade.go +++ b/cmd/kubeadm/app/phases/upgrade/postupgrade.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -223,12 +222,12 @@ func CleanupKubeletDynamicEnvFileContainerRuntime(dryRun bool) error { return nil } klog.V(2).Infof("Ensuring that %q does not include a --container-runtime flag", filePath) - bytes, err := ioutil.ReadFile(filePath) + bytes, err := os.ReadFile(filePath) if err != nil { return errors.Wrapf(err, "failed to read kubelet configuration from file %q", filePath) } updated := cleanupKubeletDynamicEnvFileContainerRuntime(string(bytes)) - if err := ioutil.WriteFile(filePath, []byte(updated), 0644); err != nil { + if err := os.WriteFile(filePath, []byte(updated), 0644); err != nil { return errors.Wrapf(err, "failed to write kubelet configuration to the file %q", filePath) } return nil