Merge pull request #118399 from skitt/ioutil-sig-api-machinery

api-machinery: stop using deprecated io/ioutil
This commit is contained in:
Kubernetes Prow Robot 2023-08-15 15:17:05 -07:00 committed by GitHub
commit 10beda334e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 48 additions and 58 deletions

View File

@ -20,7 +20,7 @@ import (
"context"
"crypto/tls"
"encoding/json"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
@ -237,7 +237,7 @@ func TestVersion(t *testing.T) {
func decodeResponse(resp *http.Response, obj interface{}) error {
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

View File

@ -19,7 +19,6 @@ package wsstream
import (
"encoding/base64"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"reflect"
@ -57,7 +56,7 @@ func TestRawConn(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
data, err := ioutil.ReadAll(conn.channels[0])
data, err := io.ReadAll(conn.channels[0])
if err != nil {
t.Error(err)
return
@ -140,7 +139,7 @@ func TestBase64Conn(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
data, err := ioutil.ReadAll(conn.channels[0])
data, err := io.ReadAll(conn.channels[0])
if err != nil {
t.Error(err)
return

View File

@ -21,7 +21,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
"reflect"
"strings"
@ -251,7 +250,7 @@ func readWebSocket(r *Reader, t *testing.T, fn func(*websocket.Conn), protocols
fn(client)
}
data, err := ioutil.ReadAll(client)
data, err := io.ReadAll(client)
if err != nil {
return data, err
}

View File

@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -60,7 +59,7 @@ func ReadAdmissionConfiguration(pluginNames []string, configFilePath string, con
return configProvider{config: &apiserver.AdmissionConfiguration{}}, nil
}
// a file was provided, so we just read it.
data, err := ioutil.ReadFile(configFilePath)
data, err := os.ReadFile(configFilePath)
if err != nil {
return nil, fmt.Errorf("unable to read admission control configuration from %q [%v]", configFilePath, err)
}
@ -141,7 +140,7 @@ func GetAdmissionPluginConfigurationFor(pluginCfg apiserver.AdmissionPluginConfi
}
// there is nothing nested, so we delegate to path
if pluginCfg.Path != "" {
content, err := ioutil.ReadFile(pluginCfg.Path)
content, err := os.ReadFile(pluginCfg.Path)
if err != nil {
klog.Fatalf("Couldn't open admission plugin configuration %s: %#v", pluginCfg.Path, err)
return nil, err

View File

@ -17,7 +17,7 @@ limitations under the License.
package admission
import (
"io/ioutil"
"io"
"os"
"reflect"
"testing"
@ -33,7 +33,7 @@ import (
func TestReadAdmissionConfiguration(t *testing.T) {
// create a place holder file to hold per test config
configFile, err := ioutil.TempFile("", "admission-plugin-config")
configFile, err := os.CreateTemp("", "admission-plugin-config")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -188,7 +188,7 @@ func TestReadAdmissionConfiguration(t *testing.T) {
require.NoError(t, apiserverapiv1.AddToScheme(scheme))
for testName, testCase := range testCases {
if err = ioutil.WriteFile(configFileName, []byte(testCase.ConfigBody), 0644); err != nil {
if err = os.WriteFile(configFileName, []byte(testCase.ConfigBody), 0644); err != nil {
t.Fatalf("unexpected err writing temp file: %v", err)
}
config, err := ReadAdmissionConfiguration(testCase.PluginNames, configFileName, scheme)
@ -203,7 +203,7 @@ func TestReadAdmissionConfiguration(t *testing.T) {
func TestEmbeddedConfiguration(t *testing.T) {
// create a place holder file to hold per test config
configFile, err := ioutil.TempFile("", "admission-plugin-config")
configFile, err := os.CreateTemp("", "admission-plugin-config")
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
@ -297,7 +297,7 @@ func TestEmbeddedConfiguration(t *testing.T) {
require.NoError(t, apiserverapiv1alpha1.AddToScheme(scheme))
require.NoError(t, apiserverapiv1.AddToScheme(scheme))
if err = ioutil.WriteFile(configFileName, []byte(test.ConfigBody), 0644); err != nil {
if err = os.WriteFile(configFileName, []byte(test.ConfigBody), 0644); err != nil {
t.Errorf("[%s] unexpected err writing temp file: %v", desc, err)
continue
}
@ -311,7 +311,7 @@ func TestEmbeddedConfiguration(t *testing.T) {
t.Errorf("[%s] Failed to get Foo config: %v", desc, err)
continue
}
bs, err := ioutil.ReadAll(r)
bs, err := io.ReadAll(r)
if err != nil {
t.Errorf("[%s] Failed to read Foo config data: %v", desc, err)
continue

View File

@ -19,7 +19,6 @@ package resourcequota
import (
"fmt"
"io"
"io/ioutil"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
@ -50,7 +49,7 @@ func LoadConfiguration(config io.Reader) (*resourcequotaapi.Configuration, error
return internalConfig, nil
}
// we have a config so parse it.
data, err := ioutil.ReadAll(config)
data, err := io.ReadAll(config)
if err != nil {
return nil, err
}

View File

@ -19,7 +19,6 @@ package config
import (
"fmt"
"io"
"io/ioutil"
"path"
"k8s.io/apimachinery/pkg/runtime"
@ -47,7 +46,7 @@ func LoadConfig(configFile io.Reader) (string, error) {
var kubeconfigFile string
if configFile != nil {
// we have a config so parse it.
data, err := ioutil.ReadAll(configFile)
data, err := io.ReadAll(configFile)
if err != nil {
return "", err
}

View File

@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"reflect"
"sort"
"strings"
@ -115,7 +114,7 @@ func splitStream(config io.Reader) (io.Reader, io.Reader, error) {
return nil, nil, nil
}
configBytes, err := ioutil.ReadAll(config)
configBytes, err := io.ReadAll(config)
if err != nil {
return nil, nil, err
}

View File

@ -18,7 +18,7 @@ package server
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/http/httputil"
@ -192,7 +192,7 @@ func TestNewWithDelegate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
data, _ := ioutil.ReadAll(resp.Body)
data, _ := io.ReadAll(resp.Body)
if http.StatusOK != resp.StatusCode {
t.Logf("got %d", resp.StatusCode)
t.Log(string(data))
@ -233,7 +233,7 @@ func checkPath(url string, expectedStatusCode int, expectedBody string, t *testi
dump, _ := httputil.DumpResponse(resp, true)
t.Log(string(dump))
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
@ -256,7 +256,7 @@ func checkExpectedPathsAtRoot(url string, expectedPaths []string, t *testing.T)
dump, _ := httputil.DumpResponse(resp, true)
t.Log(string(dump))
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}

View File

@ -21,7 +21,7 @@ import (
"context"
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"sync/atomic"
"time"
@ -98,7 +98,7 @@ func (c *DynamicFileCAContent) AddListener(listener Listener) {
// loadCABundle determines the next set of content for the file.
func (c *DynamicFileCAContent) loadCABundle() error {
caBundle, err := ioutil.ReadFile(c.filename)
caBundle, err := os.ReadFile(c.filename)
if err != nil {
return err
}

View File

@ -20,7 +20,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"os"
"sync/atomic"
"time"
@ -80,11 +80,11 @@ func (c *DynamicCertKeyPairContent) AddListener(listener Listener) {
// loadCertKeyPair determines the next set of content for the file.
func (c *DynamicCertKeyPairContent) loadCertKeyPair() error {
cert, err := ioutil.ReadFile(c.certFile)
cert, err := os.ReadFile(c.certFile)
if err != nil {
return err
}
key, err := ioutil.ReadFile(c.keyFile)
key, err := os.ReadFile(c.keyFile)
if err != nil {
return err
}

View File

@ -18,7 +18,7 @@ package egressselector
import (
"fmt"
"io/ioutil"
"os"
"strings"
"k8s.io/apimachinery/pkg/runtime"
@ -51,7 +51,7 @@ func ReadEgressSelectorConfiguration(configFilePath string) (*apiserver.EgressSe
return nil, nil
}
// a file was provided, so we just read it.
data, err := ioutil.ReadFile(configFilePath)
data, err := os.ReadFile(configFilePath)
if err != nil {
return nil, fmt.Errorf("unable to read egress selector configuration from %q [%v]", configFilePath, err)
}

View File

@ -18,7 +18,6 @@ package egressselector
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
@ -279,12 +278,12 @@ spec:
t.Run(tc.name, func(t *testing.T) {
proxyConfig := fmt.Sprintf("test-egress-selector-config-%s", tc.name)
if tc.createFile {
f, err := ioutil.TempFile("", proxyConfig)
f, err := os.CreateTemp("", proxyConfig)
if err != nil {
t.Fatal(err)
}
defer utiltesting.CloseAndRemove(t, f)
if err := ioutil.WriteFile(f.Name(), []byte(tc.contents), os.FileMode(0755)); err != nil {
if err := os.WriteFile(f.Name(), []byte(tc.contents), os.FileMode(0755)); err != nil {
t.Fatal(err)
}
proxyConfig = f.Name()

View File

@ -22,10 +22,10 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"strings"
"time"
@ -277,7 +277,7 @@ func getTLSConfig(t *apiserver.TLSConfig) (*tls.Config, error) {
}
certPool := x509.NewCertPool()
if caCert != "" {
certBytes, err := ioutil.ReadFile(caCert)
certBytes, err := os.ReadFile(caCert)
if err != nil {
return nil, fmt.Errorf("failed to read cert file %s, got %v", caCert, err)
}

View File

@ -21,7 +21,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
@ -971,7 +971,7 @@ func setupDoer(t *testing.T, info *SecureServingInfo) doer {
// in this test, we don't depend on the body of the response, so we can
// close the Body here to ensure the underlying transport can be reused
if response != nil {
ioutil.ReadAll(response.Body)
io.ReadAll(response.Body)
response.Body.Close()
}
return result{

View File

@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
@ -233,7 +232,7 @@ func TestInstallAPIGroups(t *testing.T) {
continue
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("[%d] unexpected error reading body at path %q: %v", i, path, err)
continue
@ -277,7 +276,7 @@ func TestInstallAPIGroups(t *testing.T) {
continue
}
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
if err != nil {
t.Errorf("[%d] unexpected error reading body at path %q: %v", i, path, err)
continue
@ -339,7 +338,7 @@ func TestPrepareRun(t *testing.T) {
// healthz checks are installed in PrepareRun
resp, err = http.Get(server.URL + "/healthz")
assert.NoError(err)
data, _ := ioutil.ReadAll(resp.Body)
data, _ := io.ReadAll(resp.Body)
if http.StatusOK != resp.StatusCode {
t.Logf("got %d", resp.StatusCode)
t.Log(string(data))
@ -368,7 +367,7 @@ func TestUpdateOpenAPISpec(t *testing.T) {
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
assert.NoError(err)
assert.Equal(oldSpec, body)
resp.Body.Close()
@ -387,7 +386,7 @@ func TestUpdateOpenAPISpec(t *testing.T) {
defer resp.Body.Close()
assert.Equal(http.StatusOK, resp.StatusCode)
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
assert.NoError(err)
assert.Equal(newSpec, body)
}

View File

@ -21,7 +21,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
@ -142,7 +142,7 @@ func TestGracefulShutdownForActiveHTTP2Streams(t *testing.T) {
// validate
defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body)
_, err = io.ReadAll(resp.Body)
if err != nil {
t.Errorf("%v", err)
}

View File

@ -19,7 +19,7 @@ package storage
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"os"
"strings"
"k8s.io/apimachinery/pkg/runtime"
@ -337,7 +337,7 @@ func backends(storageConfig storagebackend.Config, grOverrides map[schema.GroupR
}
}
if len(storageConfig.Transport.TrustedCAFile) > 0 {
if caCert, err := ioutil.ReadFile(storageConfig.Transport.TrustedCAFile); err != nil {
if caCert, err := os.ReadFile(storageConfig.Transport.TrustedCAFile); err != nil {
klog.Errorf("failed to read ca file while getting backends: %s", err)
} else {
caPool := x509.NewCertPool()

View File

@ -18,9 +18,9 @@ package webhook
import (
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"strconv"
"strings"
"time"
@ -233,7 +233,7 @@ func restConfigFromKubeconfig(configAuthInfo *clientcmdapi.AuthInfo) (*rest.Conf
config.BearerToken = configAuthInfo.Token
config.BearerTokenFile = configAuthInfo.TokenFile
} else if len(configAuthInfo.TokenFile) > 0 {
tokenBytes, err := ioutil.ReadFile(configAuthInfo.TokenFile)
tokenBytes, err := os.ReadFile(configAuthInfo.TokenFile)
if err != nil {
return nil, err
}

View File

@ -23,7 +23,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
@ -688,7 +687,7 @@ func TestWithExponentialBackoff(t *testing.T) {
}
func bootstrapTestDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
@ -703,7 +702,7 @@ func bootstrapTestDir(t *testing.T) string {
// Write the certificate files to disk or fail
for fileName, fileData := range files {
if err := ioutil.WriteFile(filepath.Join(dir, fileName), fileData, 0400); err != nil {
if err := os.WriteFile(filepath.Join(dir, fileName), fileData, 0400); err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}
@ -713,7 +712,7 @@ func bootstrapTestDir(t *testing.T) string {
}
func newKubeConfigFile(config v1.Config) (string, error) {
configFile, err := ioutil.TempFile("", "")
configFile, err := os.CreateTemp("", "")
if err != nil {
return "", err
}

View File

@ -23,7 +23,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
@ -416,7 +415,7 @@ func TestStreamRandomData(t *testing.T) {
}
}
data, err := ioutil.ReadAll(bytes.NewReader(stdout.Bytes()))
data, err := io.ReadAll(bytes.NewReader(stdout.Bytes()))
if err != nil {
t.Errorf("error reading the stream: %v", err)
return