Merge pull request #117477 from HirazawaUi/replace-pkg-credentialprovider-ioutil

Replace the deprecated ioutil method in the credentialprovider directory
This commit is contained in:
Kubernetes Prow Robot
2023-05-08 07:01:17 -07:00
committed by GitHub
8 changed files with 14 additions and 19 deletions

View File

@@ -53,7 +53,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
@@ -185,7 +184,7 @@ func performTokenExchange(
var content []byte var content []byte
limitedReader := &io.LimitedReader{R: exchange.Body, N: maxReadLength} 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) return "", fmt.Errorf("Www-Authenticate: error reading response from %s", authEndpoint)
} }

View File

@@ -23,7 +23,6 @@ import (
"context" "context"
"errors" "errors"
"io" "io"
"io/ioutil"
"os" "os"
"regexp" "regexp"
"strings" "strings"
@@ -115,7 +114,7 @@ func parseConfig(configReader io.Reader) (*auth.AzureAuthConfig, error) {
} }
limitedReader := &io.LimitedReader{R: configReader, N: maxReadLength} limitedReader := &io.LimitedReader{R: configReader, N: maxReadLength}
configContents, err := ioutil.ReadAll(limitedReader) configContents, err := io.ReadAll(limitedReader)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -22,7 +22,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@@ -108,7 +107,7 @@ func ReadDockercfgFile(searchPaths []string) (cfg DockerConfig, err error) {
continue continue
} }
klog.V(4).Infof("looking for .dockercfg at %s", absDockerConfigFileLocation) klog.V(4).Infof("looking for .dockercfg at %s", absDockerConfigFileLocation)
contents, err := ioutil.ReadFile(absDockerConfigFileLocation) contents, err := os.ReadFile(absDockerConfigFileLocation)
if os.IsNotExist(err) { if os.IsNotExist(err) {
continue continue
} }
@@ -160,7 +159,7 @@ func ReadDockerConfigJSONFile(searchPaths []string) (cfg DockerConfig, err error
func ReadSpecificDockerConfigJSONFile(filePath string) (cfg DockerConfig, err error) { func ReadSpecificDockerConfigJSONFile(filePath string) (cfg DockerConfig, err error) {
var contents []byte var contents []byte
if contents, err = ioutil.ReadFile(filePath); err != nil { if contents, err = os.ReadFile(filePath); err != nil {
return nil, err return nil, err
} }
return readDockerConfigJSONFileFromBytes(contents) 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} limitedReader := &io.LimitedReader{R: resp.Body, N: maxReadLength}
contents, err := ioutil.ReadAll(limitedReader) contents, err := io.ReadAll(limitedReader)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -19,7 +19,6 @@ package credentialprovider
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@@ -33,7 +32,7 @@ func TestReadDockerConfigFile(t *testing.T) {
//test dockerconfig json //test dockerconfig json
inputDockerconfigJSONFile := "{ \"auths\": { \"http://foo.example.com\":{\"auth\":\"Zm9vOmJhcgo=\",\"email\":\"foo@example.com\"}}}" 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 { if err != nil {
t.Fatalf("Creating tmp dir fail: %v", err) t.Fatalf("Creating tmp dir fail: %v", err)
return return

View File

@@ -18,8 +18,8 @@ package gcp
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"net/http" "net/http"
"os"
"os/exec" "os/exec"
"runtime" "runtime"
"strings" "strings"
@@ -134,7 +134,7 @@ func onGCEVM() bool {
} }
name = fields[1] name = fields[1]
} else { } else {
data, err := ioutil.ReadFile(gceProductNameFile) data, err := os.ReadFile(gceProductNameFile)
if err != nil { if err != nil {
klog.V(2).Infof("Error while reading product_name: %v", err) klog.V(2).Infof("Error while reading product_name: %v", err)
return false return false

View File

@@ -20,7 +20,6 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@@ -36,11 +35,11 @@ import (
) )
func createProductNameFile() (string, error) { func createProductNameFile() (string, error) {
file, err := ioutil.TempFile("", "") file, err := os.CreateTemp("", "")
if err != nil { if err != nil {
return "", fmt.Errorf("failed to create temporary test file: %v", err) 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 // The tests here are run in this fashion to ensure TestAllProvidersNoMetadata

View File

@@ -18,9 +18,10 @@ package plugin
import ( import (
"fmt" "fmt"
"io/ioutil"
"strings" "strings"
"os"
"k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/credentialprovider" "k8s.io/kubernetes/pkg/credentialprovider"
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" 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") return nil, fmt.Errorf("credential provider config path is empty")
} }
data, err := ioutil.ReadFile(configPath) data, err := os.ReadFile(configPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to read external registry credential provider configuration from %q: %w", configPath, err) return nil, fmt.Errorf("unable to read external registry credential provider configuration from %q: %w", configPath, err)
} }

View File

@@ -17,7 +17,6 @@ limitations under the License.
package plugin package plugin
import ( import (
"io/ioutil"
"os" "os"
"reflect" "reflect"
"testing" "testing"
@@ -317,7 +316,7 @@ providers:
for _, testcase := range testcases { for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.name, func(t *testing.T) {
file, err := ioutil.TempFile("", "config.yaml") file, err := os.CreateTemp("", "config.yaml")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }