refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
"hash"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -132,7 +131,7 @@ func checkHTTPErr(r *http.Response, validStatusCodes ...int) error {
|
||||
}
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 2<<15)) // 64 KiB
|
||||
body, err := io.ReadAll(io.LimitReader(r.Body, 2<<15)) // 64 KiB
|
||||
if err != nil {
|
||||
return fmt.Errorf("read response body: %v", err)
|
||||
}
|
||||
@@ -156,7 +155,7 @@ func checkHTTPErr(r *http.Response, validStatusCodes ...int) error {
|
||||
// Close the response body. The initial request is drained so the connection can
|
||||
// be reused.
|
||||
func closeResp(r *http.Response) {
|
||||
io.Copy(ioutil.Discard, r.Body)
|
||||
io.Copy(io.Discard, r.Body)
|
||||
r.Body.Close()
|
||||
}
|
||||
|
||||
@@ -312,7 +311,7 @@ func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, l
|
||||
if file == "" {
|
||||
return nil, nil
|
||||
}
|
||||
return ioutil.ReadFile(file)
|
||||
return os.ReadFile(file)
|
||||
}
|
||||
|
||||
if caData, err := data(cluster.CertificateAuthorityData, cluster.CertificateAuthority); err != nil {
|
||||
@@ -379,7 +378,7 @@ func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, l
|
||||
}
|
||||
|
||||
func loadKubeConfig(kubeConfigPath string) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, err error) {
|
||||
data, err := ioutil.ReadFile(kubeConfigPath)
|
||||
data, err := os.ReadFile(kubeConfigPath)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("read %s: %v", kubeConfigPath, err)
|
||||
return
|
||||
@@ -425,7 +424,7 @@ func namespaceFromServiceAccountJWT(s string) (string, error) {
|
||||
}
|
||||
|
||||
func namespaceFromFile(path string) (string, error) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -481,7 +480,7 @@ func inClusterConfig() (k8sapi.Cluster, k8sapi.AuthInfo, string, error) {
|
||||
CertificateAuthority: serviceAccountCAPath,
|
||||
}
|
||||
|
||||
token, err := ioutil.ReadFile(serviceAccountTokenPath)
|
||||
token, err := os.ReadFile(serviceAccountTokenPath)
|
||||
if err != nil {
|
||||
return cluster, k8sapi.AuthInfo{}, "", err
|
||||
}
|
||||
|
Reference in New Issue
Block a user