Stop using deprecated ioutil functions

This commit is contained in:
Katrina Verey
2022-08-10 16:59:18 -04:00
parent 416eed97c4
commit f6b72077c8
70 changed files with 322 additions and 362 deletions

View File

@@ -7,7 +7,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
@@ -268,7 +268,7 @@ func (c *FunctionFilter) doResults(r *kio.ByteReader) error {
if err != nil {
return err
}
err = ioutil.WriteFile(c.ResultsFile, []byte(results), 0600)
err = os.WriteFile(c.ResultsFile, []byte(results), 0600)
if err != nil {
return err
}

View File

@@ -6,7 +6,6 @@ package runtimeutil
import (
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"testing"
@@ -24,7 +23,7 @@ type testRun struct {
func (r testRun) run(reader io.Reader, writer io.Writer) error {
if r.expectedInput != "" {
input, err := ioutil.ReadAll(reader)
input, err := io.ReadAll(reader)
if !assert.NoError(r.t, err) {
r.t.FailNow()
}
@@ -1040,7 +1039,7 @@ metadata:
// results file setup
if len(tt.expectedResults) > 0 && !tt.noMakeResultsFile {
// expect result files to be written -- create a directory for them
f, err := ioutil.TempFile("", "test-kyaml-*.yaml")
f, err := os.CreateTemp("", "test-kyaml-*.yaml")
if !assert.NoError(t, err) {
t.FailNow()
}
@@ -1123,7 +1122,7 @@ metadata:
t.FailNow()
}
b, err := ioutil.ReadFile(tt.instance.ResultsFile)
b, err := os.ReadFile(tt.instance.ResultsFile)
writtenResults := strings.TrimSpace(string(b))
if !assert.NoError(t, err) {
t.FailNow()

View File

@@ -6,7 +6,6 @@ package starlark_test
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@@ -200,13 +199,13 @@ run(ctx.resource_list["items"], ctx.resource_list["functionConfig"]["spec"]["val
// resource configuration read from a directory.
func ExampleFilter_Filter_file() {
// setup the configuration
d, err := ioutil.TempDir("", "")
d, err := os.MkdirTemp("", "")
if err != nil {
log.Println(err)
}
defer os.RemoveAll(d)
err = ioutil.WriteFile(filepath.Join(d, "deploy1.yaml"), []byte(`
err = os.WriteFile(filepath.Join(d, "deploy1.yaml"), []byte(`
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -222,7 +221,7 @@ spec:
log.Println(err)
}
err = ioutil.WriteFile(filepath.Join(d, "deploy2.yaml"), []byte(`
err = os.WriteFile(filepath.Join(d, "deploy2.yaml"), []byte(`
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -238,7 +237,7 @@ spec:
log.Println(err)
}
err = ioutil.WriteFile(filepath.Join(d, "annotate.star"), []byte(`
err = os.WriteFile(filepath.Join(d, "annotate.star"), []byte(`
def run(items):
for item in items:
item["metadata"]["annotations"]["foo"] = "bar"

View File

@@ -7,8 +7,8 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"go.starlark.net/starlark"
"sigs.k8s.io/kustomize/kyaml/errors"
@@ -57,7 +57,7 @@ func (sf *Filter) setup() error {
// read the program from a file
if sf.Path != "" {
b, err := ioutil.ReadFile(sf.Path)
b, err := os.ReadFile(sf.Path)
if err != nil {
return err
}
@@ -72,7 +72,7 @@ func (sf *Filter) setup() error {
return err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return err
}