diff --git a/pkg/node-servant/components/kubelet.go b/pkg/node-servant/components/kubelet.go index 261e31ec3c6..1c67e6a7bda 100644 --- a/pkg/node-servant/components/kubelet.go +++ b/pkg/node-servant/components/kubelet.go @@ -18,7 +18,6 @@ package components import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -93,7 +92,7 @@ func (op *kubeletOperator) writeYurthubKubeletConfig() (string, error) { return "", err } fullPath := op.getYurthubKubeletConf() - err = ioutil.WriteFile(fullPath, []byte(enutil.OpenyurtKubeletConf), fileMode) + err = os.WriteFile(fullPath, []byte(enutil.OpenyurtKubeletConf), fileMode) if err != nil { return "", err } @@ -117,7 +116,7 @@ func (op *kubeletOperator) appendConfig() error { kubeConfigSetup := op.getAppendSetting() // if wrote, return - content, err := ioutil.ReadFile(kubeAdmFlagsEnvFile) + content, err := os.ReadFile(kubeAdmFlagsEnvFile) if err != nil { return err } @@ -135,7 +134,7 @@ func (op *kubeletOperator) appendConfig() error { } r := strings.Replace(args, finding[1], fmt.Sprintf("%s %s", finding[1], kubeConfigSetup), 1) - err = ioutil.WriteFile(kubeAdmFlagsEnvFile, []byte(r), fileMode) + err = os.WriteFile(kubeAdmFlagsEnvFile, []byte(r), fileMode) if err != nil { return err } @@ -145,13 +144,13 @@ func (op *kubeletOperator) appendConfig() error { func (op *kubeletOperator) undoAppendConfig() error { kubeConfigSetup := op.getAppendSetting() - contentbyte, err := ioutil.ReadFile(kubeAdmFlagsEnvFile) + contentbyte, err := os.ReadFile(kubeAdmFlagsEnvFile) if err != nil { return err } content := strings.ReplaceAll(string(contentbyte), kubeConfigSetup, "") - err = ioutil.WriteFile(kubeAdmFlagsEnvFile, []byte(content), fileMode) + err = os.WriteFile(kubeAdmFlagsEnvFile, []byte(content), fileMode) if err != nil { return err } diff --git a/pkg/node-servant/components/yurthub.go b/pkg/node-servant/components/yurthub.go index c8ce50972f6..e4c91f8e0f2 100644 --- a/pkg/node-servant/components/yurthub.go +++ b/pkg/node-servant/components/yurthub.go @@ -18,7 +18,7 @@ package components import ( "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -84,7 +84,7 @@ func (op *yurtHubOperator) Install() error { if err := enutil.EnsureDir(podManifestPath); err != nil { return err } - if err := ioutil.WriteFile(getYurthubYaml(podManifestPath), []byte(yurthubTemplate), fileMode); err != nil { + if err := os.WriteFile(getYurthubYaml(podManifestPath), []byte(yurthubTemplate), fileMode); err != nil { return err } klog.Infof("create the %s/yurt-hub.yaml", podManifestPath) @@ -196,7 +196,7 @@ func pingClusterHealthz(client *http.Client, addr string) (bool, error) { return false, err } - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { return false, fmt.Errorf("failed to read response of cluster healthz, %v", err) diff --git a/pkg/util/certmanager/pki.go b/pkg/util/certmanager/pki.go index 4aef1d5877c..c50cc381c1e 100644 --- a/pkg/util/certmanager/pki.go +++ b/pkg/util/certmanager/pki.go @@ -21,7 +21,6 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" "net" "os" @@ -167,7 +166,7 @@ func GenCertPoolUseCA(caFile string) (*x509.CertPool, error) { return nil, fmt.Errorf("fail to stat the CA file(%s): %s", caFile, err) } - caData, err := ioutil.ReadFile(caFile) + caData, err := os.ReadFile(caFile) if err != nil { return nil, err } diff --git a/pkg/yurtctl/cmd/join/phases/joinnode.go b/pkg/yurtctl/cmd/join/phases/joinnode.go index d862b5a9c69..f46cfb51edc 100644 --- a/pkg/yurtctl/cmd/join/phases/joinnode.go +++ b/pkg/yurtctl/cmd/join/phases/joinnode.go @@ -19,7 +19,6 @@ package phases import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -148,7 +147,7 @@ func writeConfigBytesToDisk(b []byte, kubeletDir string) error { return errors.Wrapf(err, "failed to create directory %q", kubeletDir) } - if err := ioutil.WriteFile(configFile, b, 0644); err != nil { + if err := os.WriteFile(configFile, b, 0644); err != nil { return errors.Wrapf(err, "failed to write kubelet configuration to the file %q", configFile) } return nil @@ -182,7 +181,7 @@ func addYurthubStaticYaml(data joindata.YurtJoinData, podManifestPath string) er return err } - if err := ioutil.WriteFile(filepath.Join(podManifestPath, yurtconstants.YurthubStaticPodFileName), []byte(yurthubTemplate), 0600); err != nil { + if err := os.WriteFile(filepath.Join(podManifestPath, yurtconstants.YurthubStaticPodFileName), []byte(yurthubTemplate), 0600); err != nil { return err } klog.Info("[join-node] Add hub agent static yaml is ok") diff --git a/pkg/yurtctl/cmd/join/phases/postcheck.go b/pkg/yurtctl/cmd/join/phases/postcheck.go index 563c934dcd9..5a494b12cdb 100644 --- a/pkg/yurtctl/cmd/join/phases/postcheck.go +++ b/pkg/yurtctl/cmd/join/phases/postcheck.go @@ -18,7 +18,7 @@ package phases import ( "fmt" - "io/ioutil" + "io" "net/http" "path/filepath" "time" @@ -96,7 +96,7 @@ func checkYurthubHealthz() error { if err != nil { return false, nil } - ok, err := ioutil.ReadAll(resp.Body) + ok, err := io.ReadAll(resp.Body) if err != nil { return false, nil } diff --git a/pkg/yurtctl/cmd/reset/phases/unmount_linux.go b/pkg/yurtctl/cmd/reset/phases/unmount_linux.go index 84ba5db2e55..d885fec6258 100644 --- a/pkg/yurtctl/cmd/reset/phases/unmount_linux.go +++ b/pkg/yurtctl/cmd/reset/phases/unmount_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux /* @@ -19,7 +20,7 @@ limitations under the License. package phases import ( - "io/ioutil" + "os" "strings" "syscall" @@ -28,7 +29,7 @@ import ( // unmountKubeletDirectory unmounts all paths that contain KubeletRunDirectory func unmountKubeletDirectory(absoluteKubeletRunDirectory string) error { - raw, err := ioutil.ReadFile("/proc/mounts") + raw, err := os.ReadFile("/proc/mounts") if err != nil { return err } diff --git a/pkg/yurtctl/cmd/yurtinit/init.go b/pkg/yurtctl/cmd/yurtinit/init.go index 21cdecf2694..05a9e8404f5 100644 --- a/pkg/yurtctl/cmd/yurtinit/init.go +++ b/pkg/yurtctl/cmd/yurtinit/init.go @@ -20,7 +20,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "os" "os/exec" "runtime" @@ -252,7 +251,7 @@ func (ci *clusterInitializer) PrepareClusterfile() error { return err } - err = ioutil.WriteFile(fmt.Sprintf("%s/Clusterfile", TmpDownloadDir), []byte(clusterfile), constants.FileMode) + err = os.WriteFile(fmt.Sprintf("%s/Clusterfile", TmpDownloadDir), []byte(clusterfile), constants.FileMode) if err != nil { return err } diff --git a/pkg/yurtctl/cmd/yurttest/kindinit/init.go b/pkg/yurtctl/cmd/yurttest/kindinit/init.go index e530b4cba68..fb868108dac 100644 --- a/pkg/yurtctl/cmd/yurttest/kindinit/init.go +++ b/pkg/yurtctl/cmd/yurttest/kindinit/init.go @@ -18,7 +18,6 @@ package kindinit import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -321,7 +320,7 @@ func (i *Initializer) prepareKindConfigFile(kindConfigPath string) error { kindConfigContent = strings.Join([]string{kindConfigContent, worker}, "\n") } - if err = ioutil.WriteFile(kindConfigPath, []byte(kindConfigContent), constants.FileMode); err != nil { + if err = os.WriteFile(kindConfigPath, []byte(kindConfigContent), constants.FileMode); err != nil { return err } klog.V(1).Infof("generated new kind config file at %s", kindConfigPath) diff --git a/pkg/yurtctl/cmd/yurttest/kindinit/init_test.go b/pkg/yurtctl/cmd/yurttest/kindinit/init_test.go index 5c37e4ca725..f89fe7c49ba 100644 --- a/pkg/yurtctl/cmd/yurttest/kindinit/init_test.go +++ b/pkg/yurtctl/cmd/yurttest/kindinit/init_test.go @@ -18,7 +18,6 @@ package kindinit import ( "fmt" - "io/ioutil" "os" "strings" "testing" @@ -149,7 +148,7 @@ nodes: t.Errorf("TestPrepareKindConfigFile failed at case %s for %s", name, err) continue } - buf, err := ioutil.ReadFile(c.kindConfigPath) + buf, err := os.ReadFile(c.kindConfigPath) if err != nil { t.Errorf("TestPrepareKindConfigFile failed at case %s, when reading file %s, %s", name, c.kindConfigPath, err) continue diff --git a/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags.go b/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags.go index 88f0b94082f..90e387acd14 100644 --- a/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags.go +++ b/pkg/yurtctl/kubernetes/kubeadm/app/phases/kubelet/flags.go @@ -19,7 +19,6 @@ package kubelet import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -109,7 +108,7 @@ func writeKubeletFlagBytesToDisk(b []byte, kubeletDir string) error { if err := os.MkdirAll(kubeletDir, 0700); err != nil { return errors.Wrapf(err, "failed to create directory %q", kubeletDir) } - if err := ioutil.WriteFile(kubeletEnvFilePath, b, 0644); err != nil { + if err := os.WriteFile(kubeletEnvFilePath, b, 0644); err != nil { return errors.Wrapf(err, "failed to write kubelet configuration to the file %q", kubeletEnvFilePath) } return nil diff --git a/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig.go b/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig.go index fead644c60b..92221643a12 100644 --- a/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig.go +++ b/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig.go @@ -18,7 +18,7 @@ package kubeconfig import ( "fmt" - "io/ioutil" + "os" "github.com/pkg/errors" clientset "k8s.io/client-go/kubernetes" @@ -150,7 +150,7 @@ func EnsureAuthenticationInfoAreEmbedded(config *clientcmdapi.Config) error { } if len(authInfo.ClientCertificateData) == 0 && len(authInfo.ClientCertificate) != 0 { - clientCert, err := ioutil.ReadFile(authInfo.ClientCertificate) + clientCert, err := os.ReadFile(authInfo.ClientCertificate) if err != nil { return errors.Wrap(err, "error while reading client cert file defined in kubeconfig") } @@ -158,7 +158,7 @@ func EnsureAuthenticationInfoAreEmbedded(config *clientcmdapi.Config) error { authInfo.ClientCertificate = "" } if len(authInfo.ClientKeyData) == 0 && len(authInfo.ClientKey) != 0 { - clientKey, err := ioutil.ReadFile(authInfo.ClientKey) + clientKey, err := os.ReadFile(authInfo.ClientKey) if err != nil { return errors.Wrap(err, "error while reading client key file defined in kubeconfig") } @@ -177,7 +177,7 @@ func EnsureCertificateAuthorityIsEmbedded(cluster *clientcmdapi.Cluster) error { } if len(cluster.CertificateAuthorityData) == 0 && len(cluster.CertificateAuthority) != 0 { - ca, err := ioutil.ReadFile(cluster.CertificateAuthority) + ca, err := os.ReadFile(cluster.CertificateAuthority) if err != nil { return errors.Wrap(err, "error while reading certificate authority file defined in kubeconfig") } diff --git a/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig_test.go b/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig_test.go index 44cbbaa6795..66dee617a3c 100644 --- a/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig_test.go +++ b/pkg/yurtctl/kubernetes/kubeadm/app/util/kubeconfig/kubeconfig_test.go @@ -19,7 +19,6 @@ package kubeconfig import ( "bytes" "fmt" - "io/ioutil" "os" "testing" @@ -143,7 +142,7 @@ func TestCreateWithToken(t *testing.T) { } func TestWriteKubeconfigToDisk(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "") + tmpdir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("Couldn't create tmpdir") } @@ -177,7 +176,7 @@ func TestWriteKubeconfigToDisk(t *testing.T) { err, ) } - newFile, _ := ioutil.ReadFile(configPath) + newFile, _ := os.ReadFile(configPath) if !bytes.Equal(newFile, rt.file) { t.Errorf( "failed WriteToDisk config write:\n\texpected: %s\n\t actual: %s", diff --git a/pkg/yurtctl/kubernetes/kubeadm/app/util/runtime/runtime_test.go b/pkg/yurtctl/kubernetes/kubeadm/app/util/runtime/runtime_test.go index 7deab15e38c..b8095384186 100644 --- a/pkg/yurtctl/kubernetes/kubeadm/app/util/runtime/runtime_test.go +++ b/pkg/yurtctl/kubernetes/kubeadm/app/util/runtime/runtime_test.go @@ -18,7 +18,6 @@ limitations under the License. package util import ( - "io/ioutil" "net" "os" "reflect" @@ -337,7 +336,7 @@ func TestIsExistingSocket(t *testing.T) { { name: "Valid domain socket is detected as such", proc: func(t *testing.T) { - tmpFile, err := ioutil.TempFile("", tempPrefix) + tmpFile, err := os.CreateTemp(os.TempDir(), tempPrefix) if err != nil { t.Fatalf("unexpected error by TempFile: %v", err) } @@ -359,7 +358,7 @@ func TestIsExistingSocket(t *testing.T) { { name: "Regular file is not a domain socket", proc: func(t *testing.T) { - tmpFile, err := ioutil.TempFile("", tempPrefix) + tmpFile, err := os.CreateTemp(os.TempDir(), tempPrefix) if err != nil { t.Fatalf("unexpected error by TempFile: %v", err) } diff --git a/pkg/yurtctl/util/edgenode/util.go b/pkg/yurtctl/util/edgenode/util.go index 5e3aeefeafb..d9cb956158c 100644 --- a/pkg/yurtctl/util/edgenode/util.go +++ b/pkg/yurtctl/util/edgenode/util.go @@ -18,7 +18,6 @@ package edgenode import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -50,7 +49,7 @@ func FileExists(filename string) (bool, error) { // GetContentFormFile returns all strings that match the regular expression regularExpression func GetContentFormFile(filename string, regularExpression string) ([]string, error) { - content, err := ioutil.ReadFile(filename) + content, err := os.ReadFile(filename) if err != nil { return nil, err } @@ -88,11 +87,11 @@ func EnsureDir(dirname string) error { // CopyFile copys sourceFile to destinationFile func CopyFile(sourceFile string, destinationFile string, perm os.FileMode) error { - content, err := ioutil.ReadFile(sourceFile) + content, err := os.ReadFile(sourceFile) if err != nil { return fmt.Errorf("failed to read source file %s: %v", sourceFile, err) } - err = ioutil.WriteFile(destinationFile, content, perm) + err = os.WriteFile(destinationFile, content, perm) if err != nil { return fmt.Errorf("failed to write destination file %s: %v", destinationFile, err) } @@ -143,7 +142,7 @@ func GetNodeName(kubeadmConfPath string) (string, error) { } //4. read nodeName from /etc/hostname - content, err := ioutil.ReadFile(Hostname) + content, err := os.ReadFile(Hostname) if err != nil { return "", err } diff --git a/pkg/yurtctl/util/kubernetes/util.go b/pkg/yurtctl/util/kubernetes/util.go index 2529898c20a..83c15186427 100644 --- a/pkg/yurtctl/util/kubernetes/util.go +++ b/pkg/yurtctl/util/kubernetes/util.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -790,7 +789,7 @@ func SetKubeletService() error { return err } } - if err := ioutil.WriteFile(constants.KubeletServiceFilepath, []byte(constants.KubeletServiceContent), 0644); err != nil { + if err := os.WriteFile(constants.KubeletServiceFilepath, []byte(constants.KubeletServiceContent), 0644); err != nil { klog.Errorf("Write file %s fail: %v", constants.KubeletServiceFilepath, err) return err } @@ -812,7 +811,7 @@ func SetKubeletUnitConfig() error { } } - if err := ioutil.WriteFile(constants.KubeletServiceConfPath, []byte(constants.KubeletUnitConfig), 0600); err != nil { + if err := os.WriteFile(constants.KubeletServiceConfPath, []byte(constants.KubeletUnitConfig), 0600); err != nil { return err } @@ -834,7 +833,7 @@ func SetKubeletConfigForNode() error { return err } } - if err := ioutil.WriteFile(kubeconfigFilePath, []byte(constants.KubeletConfForNode), constants.DirMode); err != nil { + if err := os.WriteFile(kubeconfigFilePath, []byte(constants.KubeletConfForNode), constants.DirMode); err != nil { return err } return nil @@ -857,7 +856,7 @@ func SetKubeletCaCert(config *clientcmdapi.Config) error { } clusterinfo := kubeconfigutil.GetClusterFromKubeConfig(config) - if err := ioutil.WriteFile(kubeletCaCertPath, []byte(clusterinfo.CertificateAuthorityData), constants.DirMode); err != nil { + if err := os.WriteFile(kubeletCaCertPath, []byte(clusterinfo.CertificateAuthorityData), constants.DirMode); err != nil { return err } return nil diff --git a/pkg/yurtctl/util/system/util.go b/pkg/yurtctl/util/system/util.go index dd6411b5f21..33527137283 100644 --- a/pkg/yurtctl/util/system/util.go +++ b/pkg/yurtctl/util/system/util.go @@ -18,7 +18,7 @@ package system import ( "fmt" - "io/ioutil" + "os" "os/exec" "github.com/opencontainers/selinux/go-selinux" @@ -41,7 +41,7 @@ net.bridge.bridge-nf-call-iptables = 1` //setIpv4Forward turn on the node ipv4 forward. func SetIpv4Forward() error { klog.Infof("Setting ipv4 forward") - if err := ioutil.WriteFile(ip_forward, []byte("1"), 0644); err != nil { + if err := os.WriteFile(ip_forward, []byte("1"), 0644); err != nil { return fmt.Errorf("Write content 1 to file %s fail: %v ", ip_forward, err) } return nil @@ -50,7 +50,7 @@ func SetIpv4Forward() error { //setBridgeSetting turn on the node bridge-nf-call-iptables. func SetBridgeSetting() error { klog.Info("Setting bridge settings for kubernetes.") - if err := ioutil.WriteFile(constants.SysctlK8sConfig, []byte(kubernetsBridgeSetting), 0644); err != nil { + if err := os.WriteFile(constants.SysctlK8sConfig, []byte(kubernetsBridgeSetting), 0644); err != nil { return fmt.Errorf("Write file %s fail: %v ", constants.SysctlK8sConfig, err) } @@ -60,10 +60,10 @@ func SetBridgeSetting() error { return err } } - if err := ioutil.WriteFile(bridgenf, []byte("1"), 0644); err != nil { + if err := os.WriteFile(bridgenf, []byte("1"), 0644); err != nil { return fmt.Errorf("Write file %s fail: %v ", bridgenf, err) } - if err := ioutil.WriteFile(bridgenf6, []byte("1"), 0644); err != nil { + if err := os.WriteFile(bridgenf6, []byte("1"), 0644); err != nil { return fmt.Errorf("Write file %s fail: %v ", bridgenf, err) } return nil diff --git a/pkg/yurthub/cachemanager/cache_manager_test.go b/pkg/yurthub/cachemanager/cache_manager_test.go index 27277ffa3e0..81509b99eb3 100644 --- a/pkg/yurthub/cachemanager/cache_manager_test.go +++ b/pkg/yurthub/cachemanager/cache_manager_test.go @@ -21,7 +21,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -462,7 +461,7 @@ func TestCacheGetResponse(t *testing.T) { ctx := req.Context() ctx = util.WithRespContentType(ctx, tt.accept) req = req.WithContext(ctx) - prc := ioutil.NopCloser(buf) + prc := io.NopCloser(buf) err = yurtCM.CacheResponse(req, prc, nil) }) @@ -811,7 +810,7 @@ func TestCacheWatchResponse(t *testing.T) { req.RemoteAddr = "127.0.0.1" var err error - rc := ioutil.NopCloser(r) + rc := io.NopCloser(r) var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { ctx := req.Context() ctx = util.WithRespContentType(ctx, tt.accept) @@ -1301,7 +1300,7 @@ func TestCacheListResponse(t *testing.T) { ctx := req.Context() ctx = util.WithRespContentType(ctx, tt.accept) req = req.WithContext(ctx) - prc := ioutil.NopCloser(buf) + prc := io.NopCloser(buf) err = yurtCM.CacheResponse(req, prc, nil) }) diff --git a/pkg/yurthub/certificate/hubself/cert_mgr.go b/pkg/yurthub/certificate/hubself/cert_mgr.go index 9b9fbd3004f..aa3a9304f4b 100644 --- a/pkg/yurthub/certificate/hubself/cert_mgr.go +++ b/pkg/yurthub/certificate/hubself/cert_mgr.go @@ -23,7 +23,6 @@ import ( "crypto/x509" "crypto/x509/pkix" "fmt" - "io/ioutil" "net/url" "os" "path/filepath" @@ -122,7 +121,7 @@ func NewYurtHubCertManager(cfg *config.YurtHubConfiguration) (interfaces.YurtCer } func removeDirContents(dir string) error { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return err } @@ -308,7 +307,7 @@ func (ycm *yurtHubCertManager) initCaCert() error { if caExisted { var curCABytes []byte - if curCABytes, err = ioutil.ReadFile(caFile); err != nil { + if curCABytes, err = os.ReadFile(caFile); err != nil { klog.Infof("could not read existed %s file, %v, ", caFile, err) } @@ -572,7 +571,7 @@ func createBootstrapConf(apiServerAddr, caFile, joinToken string) *clientcmdapi. return nil } - caCert, err := ioutil.ReadFile(caFile) + caCert, err := os.ReadFile(caFile) if err != nil { klog.Errorf("could not read ca file(%s), %v", caFile, err) return nil diff --git a/pkg/yurthub/filter/discardcloudservice/handler_test.go b/pkg/yurthub/filter/discardcloudservice/handler_test.go index 7fe1f8aa2e9..d33b6a947d8 100644 --- a/pkg/yurthub/filter/discardcloudservice/handler_test.go +++ b/pkg/yurthub/filter/discardcloudservice/handler_test.go @@ -19,7 +19,6 @@ package discardcloudservice import ( "bytes" "io" - "io/ioutil" "testing" "time" @@ -389,7 +388,7 @@ func TestStreamResponseFilter(t *testing.T) { w.Close() }(w) - rc := ioutil.NopCloser(r) + rc := io.NopCloser(r) ch := make(chan watch.Event, len(tt.inputObj)) go func(rc io.ReadCloser, ch chan watch.Event) { diff --git a/pkg/yurthub/filter/masterservice/handler_test.go b/pkg/yurthub/filter/masterservice/handler_test.go index 92a0ca21092..928d6615552 100644 --- a/pkg/yurthub/filter/masterservice/handler_test.go +++ b/pkg/yurthub/filter/masterservice/handler_test.go @@ -19,7 +19,6 @@ package masterservice import ( "bytes" "io" - "io/ioutil" "net/http" "testing" "time" @@ -442,7 +441,7 @@ func TestStreamResponseFilter(t *testing.T) { w.Close() }(w) - rc := ioutil.NopCloser(r) + rc := io.NopCloser(r) ch := make(chan watch.Event, len(tt.inputObj)) go func(rc io.ReadCloser, ch chan watch.Event) { diff --git a/pkg/yurthub/storage/disk/storage.go b/pkg/yurthub/storage/disk/storage.go index fc9da90181e..a2dda5fd24e 100644 --- a/pkg/yurthub/storage/disk/storage.go +++ b/pkg/yurthub/storage/disk/storage.go @@ -19,7 +19,6 @@ package disk import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -207,7 +206,7 @@ func (ds *diskStorage) get(path string) ([]byte, error) { } return nil, fmt.Errorf("failed to get bytes from %s, %v", path, err) } else if info.Mode().IsRegular() { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return []byte{}, err } diff --git a/pkg/yurthub/transport/transport.go b/pkg/yurthub/transport/transport.go index 859ae2ca608..cac2690c43b 100644 --- a/pkg/yurthub/transport/transport.go +++ b/pkg/yurthub/transport/transport.go @@ -20,8 +20,8 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" "net/http" + "os" "time" utilnet "k8s.io/apimachinery/pkg/util/net" @@ -175,7 +175,7 @@ func rootCertPool(caFile string) (*x509.CertPool, error) { if caFileExists, err := util.FileExists(caFile); err != nil { return nil, err } else if caFileExists { - caData, err := ioutil.ReadFile(caFile) + caData, err := os.ReadFile(caFile) if err != nil { return nil, err } diff --git a/pkg/yurthub/util/util_test.go b/pkg/yurthub/util/util_test.go index b9370f86909..e5aa7e056a8 100644 --- a/pkg/yurthub/util/util_test.go +++ b/pkg/yurthub/util/util_test.go @@ -19,14 +19,13 @@ package util import ( "bytes" "io" - "io/ioutil" "testing" ) func TestDualReader(t *testing.T) { src := []byte("hello, world") rb := bytes.NewBuffer(src) - rc := ioutil.NopCloser(rb) + rc := io.NopCloser(rb) drc, prc := NewDualReadCloser(nil, rc, true) rc = drc dst1 := make([]byte, len(src)) @@ -66,7 +65,7 @@ func TestDualReader(t *testing.T) { func TestDualReaderByPreClose(t *testing.T) { src := []byte("hello, world") rb := bytes.NewBuffer(src) - rc := ioutil.NopCloser(rb) + rc := io.NopCloser(rb) drc, prc := NewDualReadCloser(nil, rc, true) rc = drc dst := make([]byte, len(src)) diff --git a/pkg/yurttunnel/kubernetes/kubernetes.go b/pkg/yurttunnel/kubernetes/kubernetes.go index a20406305e5..e3ac0ec20b5 100644 --- a/pkg/yurttunnel/kubernetes/kubernetes.go +++ b/pkg/yurttunnel/kubernetes/kubernetes.go @@ -19,7 +19,6 @@ package kubernetes import ( "errors" "fmt" - "io/ioutil" "os" "k8s.io/client-go/kubernetes" @@ -75,7 +74,7 @@ func CreateClientSetApiserverAddr(apiserverAddr string) (*kubernetes.Clientset, return nil, errors.New("apiserver addr can't be empty") } - token, err := ioutil.ReadFile(constants.YurttunnelTokenFile) + token, err := os.ReadFile(constants.YurttunnelTokenFile) if err != nil { return nil, err } diff --git a/test/integration/yurttunnel_test.go b/test/integration/yurttunnel_test.go index b8815a5b87e..ff954122bb5 100644 --- a/test/integration/yurttunnel_test.go +++ b/test/integration/yurttunnel_test.go @@ -21,7 +21,7 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" + "io" "net" "net/http" "os" @@ -53,7 +53,7 @@ const ( ) func genCAPool(t *testing.T, CAPath string) *x509.CertPool { - caCertPEM, err := ioutil.ReadFile(CAPath) + caCertPEM, err := os.ReadFile(CAPath) if err != nil { t.Fatalf("fail to load the CA: %v", err) } @@ -134,7 +134,7 @@ func startDummyClient(t *testing.T, wg *sync.WaitGroup) { http.StatusOK, r.Response.StatusCode) } defer rep.Body.Close() - content, err := ioutil.ReadAll(rep.Body) + content, err := io.ReadAll(rep.Body) if err != nil { t.Fatalf("fail to read from the response body: %v", err) }