mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	replace deprecated ioutil functions
Signed-off-by: wangguoyan <717338097@qq.com>
This commit is contained in:
		| @@ -22,7 +22,6 @@ import ( | |||||||
| 	"crypto/x509" | 	"crypto/x509" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"time" | 	"time" | ||||||
| @@ -243,7 +242,7 @@ func validateKubeConfig(outDir, filename string, config *clientcmdapi.Config) er | |||||||
| 		// fallback to load CA cert data from external CA file | 		// fallback to load CA cert data from external CA file | ||||||
| 		clusterCAFilePath := currentConfig.Clusters[currentCluster].CertificateAuthority | 		clusterCAFilePath := currentConfig.Clusters[currentCluster].CertificateAuthority | ||||||
| 		if len(clusterCAFilePath) > 0 { | 		if len(clusterCAFilePath) > 0 { | ||||||
| 			clusterCABytes, err := ioutil.ReadFile(clusterCAFilePath) | 			clusterCABytes, err := os.ReadFile(clusterCAFilePath) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				klog.Warningf("failed to load CA cert from %q for kubeconfig %q, %v", clusterCAFilePath, kubeConfigFilePath, err) | 				klog.Warningf("failed to load CA cert from %q for kubeconfig %q, %v", clusterCAFilePath, kubeConfigFilePath, err) | ||||||
| 			} else { | 			} else { | ||||||
|   | |||||||
| @@ -22,7 +22,6 @@ import ( | |||||||
| 	"crypto/x509" | 	"crypto/x509" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| @@ -492,7 +491,7 @@ func TestValidateKubeConfig(t *testing.T) { | |||||||
| 	if configWithSameClusterCaByExternalFile.Clusters[currentCtx.Cluster] == nil { | 	if configWithSameClusterCaByExternalFile.Clusters[currentCtx.Cluster] == nil { | ||||||
| 		t.Fatal("failed to find the given CurrentContext Cluster in Clusters of the kubeconfig") | 		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 { | 	if err != nil { | ||||||
| 		t.Fatal(err) | 		t.Fatal(err) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -20,7 +20,6 @@ import ( | |||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
| @@ -223,12 +222,12 @@ func CleanupKubeletDynamicEnvFileContainerRuntime(dryRun bool) error { | |||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	klog.V(2).Infof("Ensuring that %q does not include a --container-runtime flag", filePath) | 	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 { | 	if err != nil { | ||||||
| 		return errors.Wrapf(err, "failed to read kubelet configuration from file %q", filePath) | 		return errors.Wrapf(err, "failed to read kubelet configuration from file %q", filePath) | ||||||
| 	} | 	} | ||||||
| 	updated := cleanupKubeletDynamicEnvFileContainerRuntime(string(bytes)) | 	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 errors.Wrapf(err, "failed to write kubelet configuration to the file %q", filePath) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 wangguoyan
					wangguoyan