mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
cli: stop using deprecated io/ioutil
This replaces deprecated ioutil variables and functions as follows: * ioutil.Discard -> io.Discard * ioutil.NopCloser -> io.NopCloser * ioutil.ReadAll -> io.ReadAll * ioutil.ReadFile -> os.ReadFile * ioutil.TempFile -> os.CreateTemp Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
parent
decf1e1a9b
commit
fc1b8a823d
@ -18,7 +18,7 @@ package genericclioptions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"k8s.io/cli-runtime/pkg/genericiooptions"
|
"k8s.io/cli-runtime/pkg/genericiooptions"
|
||||||
)
|
)
|
||||||
@ -48,7 +48,7 @@ func NewTestIOStreamsDiscard() genericiooptions.IOStreams {
|
|||||||
in := &bytes.Buffer{}
|
in := &bytes.Buffer{}
|
||||||
return IOStreams{
|
return IOStreams{
|
||||||
In: in,
|
In: in,
|
||||||
Out: ioutil.Discard,
|
Out: io.Discard,
|
||||||
ErrOut: ioutil.Discard,
|
ErrOut: io.Discard,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package genericclioptions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (printers.Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
if templateFormat == "jsonpath-file" {
|
if templateFormat == "jsonpath-file" {
|
||||||
data, err := ioutil.ReadFile(templateValue)
|
data, err := os.ReadFile(templateValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
|
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package genericclioptions
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -32,7 +31,7 @@ import (
|
|||||||
func TestPrinterSupportsExpectedJSONPathFormats(t *testing.T) {
|
func TestPrinterSupportsExpectedJSONPathFormats(t *testing.T) {
|
||||||
testObject := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ package genericclioptions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (printers.Resour
|
|||||||
}
|
}
|
||||||
|
|
||||||
if templateFormat == "templatefile" || templateFormat == "go-template-file" {
|
if templateFormat == "templatefile" || templateFormat == "go-template-file" {
|
||||||
data, err := ioutil.ReadFile(templateValue)
|
data, err := os.ReadFile(templateValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
|
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package genericclioptions
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -32,7 +31,7 @@ import (
|
|||||||
func TestPrinterSupportsExpectedTemplateFormats(t *testing.T) {
|
func TestPrinterSupportsExpectedTemplateFormats(t *testing.T) {
|
||||||
testObject := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -39,7 +38,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func objBody(obj runtime.Object) io.ReadCloser {
|
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 {
|
func header() http.Header {
|
||||||
@ -250,7 +249,7 @@ func TestHelperCreate(t *testing.T) {
|
|||||||
if tt.Req != nil && !tt.Req(client.Req) {
|
if tt.Req != nil && !tt.Req(client.Req) {
|
||||||
t.Errorf("%d: unexpected request: %#v", i, 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 {
|
if err != nil {
|
||||||
t.Fatalf("%d: unexpected error: %#v", i, err)
|
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)) {
|
if tt.Req != nil && (client.Req == nil || !tt.Req(tt.ExpectPath, client.Req)) {
|
||||||
t.Fatalf("unexpected request: %#v", 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 {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %#v", err)
|
t.Fatalf("unexpected error: %#v", err)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -75,7 +74,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
|
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
|
||||||
assert.Equal(t, "hello", url)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
return 501, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
|
return 501, "Status", io.NopCloser(new(bytes.Buffer)), nil
|
||||||
},
|
},
|
||||||
args: httpArgs{
|
args: httpArgs{
|
||||||
duration: 0,
|
duration: 0,
|
||||||
@ -89,7 +88,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
|
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
|
||||||
assert.Equal(t, "hello", url)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
return 300, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
|
return 300, "Status", io.NopCloser(new(bytes.Buffer)), nil
|
||||||
|
|
||||||
},
|
},
|
||||||
args: httpArgs{
|
args: httpArgs{
|
||||||
@ -104,7 +103,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
|
httpRetries: func(url string) (int, string, io.ReadCloser, error) {
|
||||||
assert.Equal(t, "hello", url)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
return 501, "Status", ioutil.NopCloser(new(bytes.Buffer)), nil
|
return 501, "Status", io.NopCloser(new(bytes.Buffer)), nil
|
||||||
|
|
||||||
},
|
},
|
||||||
args: httpArgs{
|
args: httpArgs{
|
||||||
@ -117,7 +116,7 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Test attempts less than 1 results in an error",
|
name: "Test attempts less than 1 results in an error",
|
||||||
httpRetries: func(url string) (int, string, io.ReadCloser, 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{
|
args: httpArgs{
|
||||||
@ -133,9 +132,9 @@ func TestVisitorHttpGet(t *testing.T) {
|
|||||||
assert.Equal(t, "hello", url)
|
assert.Equal(t, "hello", url)
|
||||||
i++
|
i++
|
||||||
if i > 1 {
|
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{
|
args: httpArgs{
|
||||||
|
Loading…
Reference in New Issue
Block a user