Skip to content

Commit

Permalink
Merge pull request #4754 from KnVerey/ioutil
Browse files Browse the repository at this point in the history
Stop using deprecated ioutil functions
  • Loading branch information
k8s-ci-robot committed Aug 16, 2022
2 parents 1d44793 + 55a37de commit 2ec4b97
Show file tree
Hide file tree
Showing 70 changed files with 330 additions and 362 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Expand Up @@ -102,14 +102,14 @@ linters-settings:
arguments:
- [ "ID", "API", "JSON" ] # AllowList
- [ ] # DenyList
gomnd:
ignored-functions:
- os.WriteFile
gomoddirectives:
replace-local: true
gosec:
config:
G306: "0644"
gomnd:
ignored-functions:
- ioutil.WriteFile
wrapcheck:
ignoreSigs:
# defaults
Expand Down
5 changes: 2 additions & 3 deletions api/internal/builtins/HelmChartInflationGenerator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions api/internal/plugins/execplugin/execplugin.go
Expand Up @@ -6,7 +6,6 @@ package execplugin
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -150,7 +149,7 @@ func (p *ExecPlugin) Transform(rm resmap.ResMap) error {
// passes the full temp file path as the first arg to a process
// running the plugin binary. Process output is returned.
func (p *ExecPlugin) invokePlugin(input []byte) ([]byte, error) {
f, err := ioutil.TempFile("", tmpConfigFilePrefix)
f, err := os.CreateTemp("", tmpConfigFilePrefix)
if err != nil {
return nil, errors.Wrap(
err, "creating tmp plugin config file")
Expand Down
7 changes: 3 additions & 4 deletions api/krusty/openapitests/openapicustomschema_test.go
Expand Up @@ -7,7 +7,6 @@ package openapitests //nolint

import (
"fmt"
"io/ioutil"
"os"
"testing"

Expand All @@ -18,12 +17,12 @@ import (
)

func writeTestSchema(th kusttest_test.Harness, filepath string) {
bytes, _ := ioutil.ReadFile("../testdata/customschema.json")
bytes, _ := os.ReadFile("../testdata/customschema.json")
th.WriteF(filepath+"mycrd_schema.json", string(bytes))
}

func writeTestSchemaYaml(th kusttest_test.Harness, filepath string) {
bytes, _ := ioutil.ReadFile("../testdata/customschema.yaml")
bytes, _ := os.ReadFile("../testdata/customschema.yaml")
th.WriteF(filepath+"mycrd_schema.yaml", string(bytes))
}

Expand Down Expand Up @@ -486,7 +485,7 @@ spec:
`)

// openapi schema referred to by the component
bytes, _ := ioutil.ReadFile("../testdata/openshiftschema.json")
bytes, _ := os.ReadFile("../testdata/openshiftschema.json")
th.WriteF("components/dc-openapi/openapi.json", string(bytes))

// patch referred to by the component
Expand Down
4 changes: 2 additions & 2 deletions api/loader/fileloader.go
Expand Up @@ -5,7 +5,7 @@ package loader

import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -302,7 +302,7 @@ func (fl *fileLoader) Load(path string) ([]byte, error) {
}
return nil, fmt.Errorf("%w: status code %d (%s)", ErrHTTP, resp.StatusCode, http.StatusText(resp.StatusCode))
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/loader/fileloader_test.go
Expand Up @@ -5,7 +5,7 @@ package loader

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestLoaderHTTP(t *testing.T) {
require.Equal(x.path, u)
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString(x.expectedContent)),
Body: io.NopCloser(bytes.NewBufferString(x.expectedContent)),
Header: make(http.Header),
}
})
Expand Down
3 changes: 1 addition & 2 deletions api/testutils/kusttest/harnessenhanced.go
Expand Up @@ -4,7 +4,6 @@
package kusttest_test

import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -61,7 +60,7 @@ func MakeEnhancedHarnessWithTmpRoot(t *testing.T) *HarnessEnhanced {
r := makeBaseEnhancedHarness(t)
fSys := filesys.MakeFsOnDisk()
r.Harness = MakeHarnessWithFs(t, fSys)
tmpDir, err := ioutil.TempDir("", "kust-testing-")
tmpDir, err := os.MkdirTemp("", "kust-testing-")
if err != nil {
panic("test harness cannot make tmp dir: " + err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/config/internal/commands/annotate_test.go
Expand Up @@ -5,7 +5,7 @@ package commands

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -88,11 +88,11 @@ func TestAnnotateCommand(t *testing.T) {
func initTestDir(t *testing.T) string {
t.Helper()
d := t.TempDir()
err := ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(f1Input), 0600)
err := os.WriteFile(filepath.Join(d, "f1.yaml"), []byte(f1Input), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}
err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(f2Input), 0600)
err = os.WriteFile(filepath.Join(d, "f2.yaml"), []byte(f2Input), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
27 changes: 13 additions & 14 deletions cmd/config/internal/commands/cat_test.go
Expand Up @@ -5,7 +5,6 @@ package commands_test

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -22,7 +21,7 @@ import (
func TestCmd_files(t *testing.T) {
d := t.TempDir()

err := ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
err := os.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
kind: Deployment
metadata:
labels:
Expand All @@ -45,7 +44,7 @@ spec:
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
err = os.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
apiVersion: v1
kind: Abstraction
metadata:
Expand Down Expand Up @@ -119,7 +118,7 @@ spec:
func TestCmd_filesWithReconcilers(t *testing.T) {
d := t.TempDir()

err := ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
err := os.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
kind: Deployment
metadata:
labels:
Expand All @@ -142,7 +141,7 @@ spec:
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
err = os.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
apiVersion: v1
kind: Abstraction
metadata:
Expand Down Expand Up @@ -225,7 +224,7 @@ spec:
func TestCmd_filesWithoutNonReconcilers(t *testing.T) {
d := t.TempDir()

err := ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
err := os.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
kind: Deployment
metadata:
labels:
Expand All @@ -248,7 +247,7 @@ spec:
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
err = os.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
apiVersion: v1
kind: Abstraction
metadata:
Expand Down Expand Up @@ -303,7 +302,7 @@ spec:
func TestCmd_outputTruncateFile(t *testing.T) {
d := t.TempDir()

err := ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
err := os.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
kind: Deployment
metadata:
labels:
Expand All @@ -326,7 +325,7 @@ spec:
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
err = os.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
apiVersion: v1
kind: Abstraction
metadata:
Expand All @@ -353,7 +352,7 @@ spec:
return
}

f, err := ioutil.TempFile("", "kustomize-cat-test-dest")
f, err := os.CreateTemp("", "kustomize-cat-test-dest")
if !assert.NoError(t, err) {
return
}
Expand All @@ -372,7 +371,7 @@ spec:
return
}

actual, err := ioutil.ReadFile(f.Name())
actual, err := os.ReadFile(f.Name())
if !assert.NoError(t, err) {
return
}
Expand Down Expand Up @@ -413,7 +412,7 @@ spec:
func TestCmd_outputCreateFile(t *testing.T) {
d := t.TempDir()

err := ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
err := os.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
kind: Deployment
metadata:
labels:
Expand All @@ -436,7 +435,7 @@ spec:
if !assert.NoError(t, err) {
return
}
err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
err = os.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
apiVersion: v1
kind: Abstraction
metadata:
Expand Down Expand Up @@ -479,7 +478,7 @@ spec:
return
}

actual, err := ioutil.ReadFile(f)
actual, err := os.ReadFile(f)
if !assert.NoError(t, err) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/internal/commands/cmdcreatesetter.go
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -213,7 +213,7 @@ func schemaFromFile(schemaPath string) (*spec.Schema, error) {
if schemaPath == "" {
return sc, nil
}
sch, err := ioutil.ReadFile(schemaPath)
sch, err := os.ReadFile(schemaPath)
if err != nil {
return sc, err
}
Expand Down
15 changes: 7 additions & 8 deletions cmd/config/internal/commands/cmdcreatesetter_test.go
Expand Up @@ -5,7 +5,6 @@ package commands_test

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -702,13 +701,13 @@ spec:
baseDir := t.TempDir()

f := filepath.Join(baseDir, "Krmfile")
err := ioutil.WriteFile(f, []byte(test.inputOpenAPI), 0600)
err := os.WriteFile(f, []byte(test.inputOpenAPI), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}

if test.schema != "" {
sch, err := ioutil.TempFile("", "schema.json")
sch, err := os.CreateTemp("", "schema.json")
if !assert.NoError(t, err) {
t.FailNow()
}
Expand All @@ -717,20 +716,20 @@ spec:
os.Remove(sch.Name())
})

err = ioutil.WriteFile(sch.Name(), []byte(test.schema), 0600)
err = os.WriteFile(sch.Name(), []byte(test.schema), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}

test.args = append(test.args, "--schema-path", sch.Name())
}

r, err := ioutil.TempFile(baseDir, "k8s-cli-*.yaml")
r, err := os.CreateTemp(baseDir, "k8s-cli-*.yaml")
if !assert.NoError(t, err) {
t.FailNow()
}
t.Cleanup(func() { r.Close() })
err = ioutil.WriteFile(r.Name(), []byte(test.input), 0600)
err = os.WriteFile(r.Name(), []byte(test.input), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down Expand Up @@ -763,7 +762,7 @@ spec:
t.FailNow()
}

actualResources, err := ioutil.ReadFile(r.Name())
actualResources, err := os.ReadFile(r.Name())
if !assert.NoError(t, err) {
t.FailNow()
}
Expand All @@ -773,7 +772,7 @@ spec:
t.FailNow()
}

actualOpenAPI, err := ioutil.ReadFile(f)
actualOpenAPI, err := os.ReadFile(f)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down

0 comments on commit 2ec4b97

Please sign in to comment.