diff --git a/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go b/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go index 429d509ea..eed8dccdd 100644 --- a/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go +++ b/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go @@ -4,7 +4,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "os" "path/filepath" "strings" @@ -116,7 +115,7 @@ func main() { if info.IsDir() { return nil } - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return err } diff --git a/hack/tools/preferredimports/preferredimports.go b/hack/tools/preferredimports/preferredimports.go index d9c572753..622da3d71 100644 --- a/hack/tools/preferredimports/preferredimports.go +++ b/hack/tools/preferredimports/preferredimports.go @@ -30,7 +30,6 @@ import ( "go/format" "go/parser" "go/token" - "io/ioutil" "log" "os" "path/filepath" @@ -133,7 +132,7 @@ func (a *analyzer) collect(dir string) { panic(fmt.Sprintf("Error stat'ing file: %s\n%s\n", pathToFile, err.Error())) } - err = ioutil.WriteFile(pathToFile, buffer.Bytes(), fileInfo.Mode()) + err = os.WriteFile(pathToFile, buffer.Bytes(), fileInfo.Mode()) if err != nil { panic(fmt.Sprintf("Error writing file: %s\n%s\n", pathToFile, err.Error())) } @@ -244,7 +243,7 @@ func main() { sort.Strings(c.dirs) if len(*importAliases) > 0 { - bytes, err := ioutil.ReadFile(*importAliases) + bytes, err := os.ReadFile(*importAliases) if err != nil { log.Fatalf("Error reading import aliases: %v", err) } diff --git a/pkg/karmadactl/cmdinit/karmada/deploy.go b/pkg/karmadactl/cmdinit/karmada/deploy.go index 2a159a682..db9412a59 100644 --- a/pkg/karmadactl/cmdinit/karmada/deploy.go +++ b/pkg/karmadactl/cmdinit/karmada/deploy.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "os" "path" "path/filepath" "regexp" @@ -176,7 +176,7 @@ func createExtralResources(clientSet *kubernetes.Clientset, dir string) error { } func crdPatchesResources(filename, caBundle string) ([]byte, error) { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return nil, err } @@ -193,7 +193,7 @@ func crdPatchesResources(filename, caBundle string) ([]byte, error) { // createCRDs create crd resource func createCRDs(crdClient *clientset.Clientset, filename string) error { obj := apiextensionsv1.CustomResourceDefinition{} - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return err } diff --git a/pkg/karmadactl/cmdinit/utils/format.go b/pkg/karmadactl/cmdinit/utils/format.go index 674fa95bf..bda507857 100644 --- a/pkg/karmadactl/cmdinit/utils/format.go +++ b/pkg/karmadactl/cmdinit/utils/format.go @@ -3,7 +3,7 @@ package utils import ( "bytes" "fmt" - "io/ioutil" + "io" "net" "net/http" "os" @@ -60,7 +60,7 @@ func InternetIP() (net.IP, error) { defer resp.Body.Close() - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/pkg/karmadactl/register.go b/pkg/karmadactl/register.go index 3dc449737..d02231c0e 100644 --- a/pkg/karmadactl/register.go +++ b/pkg/karmadactl/register.go @@ -9,7 +9,6 @@ import ( "crypto/x509/pkix" "encoding/pem" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -262,7 +261,7 @@ func (o *CommandRegisterOption) Complete(args []string) error { } if len(o.ClusterName) == 0 { - configBytes, err := ioutil.ReadFile(o.KubeConfig) + configBytes, err := os.ReadFile(o.KubeConfig) if err != nil { return fmt.Errorf("failed to read kubeconfig file %s, err: %w", o.KubeConfig, err) } diff --git a/pkg/search/proxy/framework/plugins/cluster/cluster.go b/pkg/search/proxy/framework/plugins/cluster/cluster.go index 76e914d87..9c75c4e81 100644 --- a/pkg/search/proxy/framework/plugins/cluster/cluster.go +++ b/pkg/search/proxy/framework/plugins/cluster/cluster.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "net/http" corev1 "k8s.io/api/core/v1" @@ -121,7 +120,7 @@ func modifyRequest(req *http.Request, cluster string) error { _ = req.Body.Close() defer func() { - req.Body = ioutil.NopCloser(body) + req.Body = io.NopCloser(body) req.ContentLength = int64(body.Len()) }() diff --git a/pkg/search/proxy/framework/plugins/cluster/cluster_test.go b/pkg/search/proxy/framework/plugins/cluster/cluster_test.go index d728fda9b..bbd3df4cd 100644 --- a/pkg/search/proxy/framework/plugins/cluster/cluster_test.go +++ b/pkg/search/proxy/framework/plugins/cluster/cluster_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -137,7 +136,7 @@ func TestModifyRequest(t *testing.T) { var get runtime.Object if req.ContentLength != 0 { - data, err := ioutil.ReadAll(req.Body) + data, err := io.ReadAll(req.Body) if err != nil { t.Error(err) return @@ -368,7 +367,7 @@ func Test_clusterProxy_connect(t *testing.T) { request: (&http.Request{ Method: "PUT", URL: &url.URL{Scheme: "https", Host: "localhost", Path: "/test"}, - Body: ioutil.NopCloser(&alwaysErrorReader{}), + Body: io.NopCloser(&alwaysErrorReader{}), ContentLength: 10, Header: make(http.Header), }).WithContext(reqCtx), diff --git a/pkg/webhook/interpreter/http.go b/pkg/webhook/interpreter/http.go index 2571b066d..1c4a27981 100644 --- a/pkg/webhook/interpreter/http.go +++ b/pkg/webhook/interpreter/http.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "k8s.io/apimachinery/pkg/runtime" @@ -34,7 +33,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { } defer r.Body.Close() - if body, err = ioutil.ReadAll(r.Body); err != nil { + if body, err = io.ReadAll(r.Body); err != nil { klog.Errorf("unable to read the body from the incoming request: %w", err) res = Errored(http.StatusBadRequest, err) wh.writeResponse(w, res)