mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-30 06:09:11 +00:00
Merge pull request #117477 from HirazawaUi/replace-pkg-credentialprovider-ioutil
Replace the deprecated ioutil method in the credentialprovider directory
This commit is contained in:
commit
3187a3333b
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user