mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 11:38:15 +00:00
Merge pull request #118401 from skitt/ioutil-sig-cli
cli: stop using deprecated io/ioutil
This commit is contained in:
commit
dbcbf5e952
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user