diff --git a/pkg/credentialprovider/azure/azure_acr_helper.go b/pkg/credentialprovider/azure/azure_acr_helper.go index bcde4f385f2..3051c04a12c 100644 --- a/pkg/credentialprovider/azure/azure_acr_helper.go +++ b/pkg/credentialprovider/azure/azure_acr_helper.go @@ -53,7 +53,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -185,7 +184,7 @@ func performTokenExchange( var content []byte limitedReader := &io.LimitedReader{R: exchange.Body, N: maxReadLength} - if content, err = ioutil.ReadAll(limitedReader); err != nil { + if content, err = io.ReadAll(limitedReader); err != nil { return "", fmt.Errorf("Www-Authenticate: error reading response from %s", authEndpoint) } diff --git a/pkg/credentialprovider/azure/azure_credentials.go b/pkg/credentialprovider/azure/azure_credentials.go index 8302ebb47e8..d3b3f193267 100644 --- a/pkg/credentialprovider/azure/azure_credentials.go +++ b/pkg/credentialprovider/azure/azure_credentials.go @@ -23,7 +23,6 @@ import ( "context" "errors" "io" - "io/ioutil" "os" "regexp" "strings" @@ -115,7 +114,7 @@ func parseConfig(configReader io.Reader) (*auth.AzureAuthConfig, error) { } limitedReader := &io.LimitedReader{R: configReader, N: maxReadLength} - configContents, err := ioutil.ReadAll(limitedReader) + configContents, err := io.ReadAll(limitedReader) if err != nil { return nil, err } diff --git a/pkg/credentialprovider/config.go b/pkg/credentialprovider/config.go index 86ce18542c8..203ad14dfa6 100644 --- a/pkg/credentialprovider/config.go +++ b/pkg/credentialprovider/config.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -108,7 +107,7 @@ func ReadDockercfgFile(searchPaths []string) (cfg DockerConfig, err error) { continue } klog.V(4).Infof("looking for .dockercfg at %s", absDockerConfigFileLocation) - contents, err := ioutil.ReadFile(absDockerConfigFileLocation) + contents, err := os.ReadFile(absDockerConfigFileLocation) if os.IsNotExist(err) { continue } @@ -160,7 +159,7 @@ func ReadDockerConfigJSONFile(searchPaths []string) (cfg DockerConfig, err error func ReadSpecificDockerConfigJSONFile(filePath string) (cfg DockerConfig, err error) { var contents []byte - if contents, err = ioutil.ReadFile(filePath); err != nil { + if contents, err = os.ReadFile(filePath); err != nil { return nil, err } return readDockerConfigJSONFileFromBytes(contents) @@ -211,7 +210,7 @@ func ReadURL(url string, client *http.Client, header *http.Header) (body []byte, } limitedReader := &io.LimitedReader{R: resp.Body, N: maxReadLength} - contents, err := ioutil.ReadAll(limitedReader) + contents, err := io.ReadAll(limitedReader) if err != nil { return nil, err } diff --git a/pkg/credentialprovider/config_test.go b/pkg/credentialprovider/config_test.go index c9fe61c97e7..77d2fa66302 100644 --- a/pkg/credentialprovider/config_test.go +++ b/pkg/credentialprovider/config_test.go @@ -19,7 +19,6 @@ package credentialprovider import ( "encoding/base64" "encoding/json" - "io/ioutil" "os" "path/filepath" "reflect" @@ -33,7 +32,7 @@ func TestReadDockerConfigFile(t *testing.T) { //test dockerconfig json inputDockerconfigJSONFile := "{ \"auths\": { \"http://foo.example.com\":{\"auth\":\"Zm9vOmJhcgo=\",\"email\":\"foo@example.com\"}}}" - preferredPath, err := ioutil.TempDir("", "test_foo_bar_dockerconfigjson_") + preferredPath, err := os.MkdirTemp("", "test_foo_bar_dockerconfigjson_") if err != nil { t.Fatalf("Creating tmp dir fail: %v", err) return diff --git a/pkg/credentialprovider/gcp/metadata.go b/pkg/credentialprovider/gcp/metadata.go index e71cb2f24d6..f11b09a69fd 100644 --- a/pkg/credentialprovider/gcp/metadata.go +++ b/pkg/credentialprovider/gcp/metadata.go @@ -18,8 +18,8 @@ package gcp import ( "encoding/json" - "io/ioutil" "net/http" + "os" "os/exec" "runtime" "strings" @@ -134,7 +134,7 @@ func onGCEVM() bool { } name = fields[1] } else { - data, err := ioutil.ReadFile(gceProductNameFile) + data, err := os.ReadFile(gceProductNameFile) if err != nil { klog.V(2).Infof("Error while reading product_name: %v", err) return false diff --git a/pkg/credentialprovider/gcp/metadata_test.go b/pkg/credentialprovider/gcp/metadata_test.go index 5e469f3e1cf..130da5bb1c6 100644 --- a/pkg/credentialprovider/gcp/metadata_test.go +++ b/pkg/credentialprovider/gcp/metadata_test.go @@ -20,7 +20,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -36,11 +35,11 @@ import ( ) func createProductNameFile() (string, error) { - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") if err != nil { return "", fmt.Errorf("failed to create temporary test file: %v", err) } - return file.Name(), ioutil.WriteFile(file.Name(), []byte("Google"), 0600) + return file.Name(), os.WriteFile(file.Name(), []byte("Google"), 0600) } // The tests here are run in this fashion to ensure TestAllProvidersNoMetadata diff --git a/pkg/credentialprovider/plugin/config.go b/pkg/credentialprovider/plugin/config.go index c65f3bb472f..841d5b22123 100644 --- a/pkg/credentialprovider/plugin/config.go +++ b/pkg/credentialprovider/plugin/config.go @@ -18,9 +18,10 @@ package plugin import ( "fmt" - "io/ioutil" "strings" + "os" + "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/kubernetes/pkg/credentialprovider" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" @@ -33,7 +34,7 @@ func readCredentialProviderConfigFile(configPath string) (*kubeletconfig.Credent return nil, fmt.Errorf("credential provider config path is empty") } - data, err := ioutil.ReadFile(configPath) + data, err := os.ReadFile(configPath) if err != nil { return nil, fmt.Errorf("unable to read external registry credential provider configuration from %q: %w", configPath, err) } diff --git a/pkg/credentialprovider/plugin/config_test.go b/pkg/credentialprovider/plugin/config_test.go index 940109cc44d..2d1e10bf966 100644 --- a/pkg/credentialprovider/plugin/config_test.go +++ b/pkg/credentialprovider/plugin/config_test.go @@ -17,7 +17,6 @@ limitations under the License. package plugin import ( - "io/ioutil" "os" "reflect" "testing" @@ -317,7 +316,7 @@ providers: for _, testcase := range testcases { t.Run(testcase.name, func(t *testing.T) { - file, err := ioutil.TempFile("", "config.yaml") + file, err := os.CreateTemp("", "config.yaml") if err != nil { t.Fatal(err) }