Merge pull request #118401 from skitt/ioutil-sig-cli

cli: stop using deprecated io/ioutil
This commit is contained in:
Kubernetes Prow Robot 2023-08-26 00:51:25 -07:00 committed by GitHub
commit dbcbf5e952
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 22 deletions

View File

@ -18,7 +18,7 @@ package genericclioptions
import (
"bytes"
"io/ioutil"
"io"
"k8s.io/cli-runtime/pkg/genericiooptions"
)
@ -48,7 +48,7 @@ func NewTestIOStreamsDiscard() genericiooptions.IOStreams {
in := &bytes.Buffer{}
return IOStreams{
In: in,
Out: ioutil.Discard,
ErrOut: ioutil.Discard,
Out: io.Discard,
ErrOut: io.Discard,
}
}

View File

@ -18,7 +18,7 @@ package genericclioptions
import (
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
@ -88,7 +88,7 @@ func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (printers.Resource
}
if templateFormat == "jsonpath-file" {
data, err := ioutil.ReadFile(templateValue)
data, err := os.ReadFile(templateValue)
if err != nil {
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
}

View File

@ -19,7 +19,6 @@ package genericclioptions
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
@ -32,7 +31,7 @@ import (
func TestPrinterSupportsExpectedJSONPathFormats(t *testing.T) {
testObject := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
jsonpathFile, err := ioutil.TempFile("", "printers_jsonpath_flags")
jsonpathFile, err := os.CreateTemp("", "printers_jsonpath_flags")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -18,7 +18,7 @@ package genericclioptions
import (
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
@ -89,7 +89,7 @@ func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (printers.Resour
}
if templateFormat == "templatefile" || templateFormat == "go-template-file" {
data, err := ioutil.ReadFile(templateValue)
data, err := os.ReadFile(templateValue)
if err != nil {
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
}

View File

@ -19,7 +19,6 @@ package genericclioptions
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
@ -32,7 +31,7 @@ import (
func TestPrinterSupportsExpectedTemplateFormats(t *testing.T) {
testObject := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
templateFile, err := ioutil.TempFile("", "printers_jsonpath_flags")
templateFile, err := os.CreateTemp("", "printers_jsonpath_flags")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"reflect"
"strings"
@ -39,7 +38,7 @@ import (
)
func objBody(obj runtime.Object) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(corev1Codec, obj))))
return io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(corev1Codec, obj))))
}
func header() http.Header {
@ -250,7 +249,7 @@ func TestHelperCreate(t *testing.T) {
if tt.Req != nil && !tt.Req(client.Req) {
t.Errorf("%d: unexpected request: %#v", i, client.Req)
}
body, err := ioutil.ReadAll(client.Req.Body)
body, err := io.ReadAll(client.Req.Body)
if err != nil {
t.Fatalf("%d: unexpected error: %#v", i, err)
}
@ -711,7 +710,7 @@ func TestHelperReplace(t *testing.T) {
if tt.Req != nil && (client.Req == nil || !tt.Req(tt.ExpectPath, client.Req)) {
t.Fatalf("unexpected request: %#v", client.Req)
}
body, err := ioutil.ReadAll(client.Req.Body)
body, err := io.ReadAll(client.Req.Body)
if err != nil {
t.Fatalf("unexpected error: %#v", err)
}

View File

@ -22,7 +22,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -75,7 +74,7 @@ func TestVisitorHttpGet(t *testing.T) {
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
assert.Equal(t, "hello", url)
i++
return 501, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
return 501, "Status", io.NopCloser(new(bytes.Buffer)), nil
},
args: httpArgs{
duration: 0,
@ -89,7 +88,7 @@ func TestVisitorHttpGet(t *testing.T) {
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
assert.Equal(t, "hello", url)
i++
return 300, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
return 300, "Status", io.NopCloser(new(bytes.Buffer)), nil
},
args: httpArgs{
@ -104,7 +103,7 @@ func TestVisitorHttpGet(t *testing.T) {
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
assert.Equal(t, "hello", url)
i++
return 501, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
return 501, "Status", io.NopCloser(new(bytes.Buffer)), nil
},
args: httpArgs{
@ -117,7 +116,7 @@ func TestVisitorHttpGet(t *testing.T) {
{
name: "Test attempts less than 1 results in an error",
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
return 200, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
return 200, "Status", io.NopCloser(new(bytes.Buffer)), nil
},
args: httpArgs{
@ -133,9 +132,9 @@ func TestVisitorHttpGet(t *testing.T) {
assert.Equal(t, "hello", url)
i++
if i > 1 {
return 200, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
return 200, "Status", io.NopCloser(new(bytes.Buffer)), nil
}
return 501, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
return 501, "Status", io.NopCloser(new(bytes.Buffer)), nil
},
args: httpArgs{