replace deprecated ioutil functions

Signed-off-by: wangguoyan <717338097@qq.com>
This commit is contained in:
wangguoyan 2022-09-29 09:00:10 +08:00
parent f0823c0f59
commit 447ad7eacb
3 changed files with 4 additions and 7 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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