Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏃 remove usages of deprecated io/ioutil #847

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pkg/crd/gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package crd_test
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -93,7 +92,7 @@ var _ = Describe("CRD Generation proper defaulting", func() {
Expect(gen.Generate(ctx)).NotTo(HaveOccurred())

By("loading the desired YAML")
expectedFile, err := ioutil.ReadFile(filepath.Join(genDir, "bar.example.com_foos.yaml"))
expectedFile, err := os.ReadFile(filepath.Join(genDir, "bar.example.com_foos.yaml"))
Expect(err).NotTo(HaveOccurred())
expectedFile = fixAnnotations(expectedFile)

Expand All @@ -109,10 +108,10 @@ var _ = Describe("CRD Generation proper defaulting", func() {
Expect(gen.Generate(ctx2)).NotTo(HaveOccurred())

By("loading the desired YAMLs")
expectedFileFoos, err := ioutil.ReadFile(filepath.Join(genDir, "bar.example.com_foos.yaml"))
expectedFileFoos, err := os.ReadFile(filepath.Join(genDir, "bar.example.com_foos.yaml"))
Expect(err).NotTo(HaveOccurred())
expectedFileFoos = fixAnnotations(expectedFileFoos)
expectedFileZoos, err := ioutil.ReadFile(filepath.Join(genDir, "zoo", "bar.example.com_zoos.yaml"))
expectedFileZoos, err := os.ReadFile(filepath.Join(genDir, "zoo", "bar.example.com_zoos.yaml"))
Expect(err).NotTo(HaveOccurred())
expectedFileZoos = fixAnnotations(expectedFileZoos)

Expand Down
7 changes: 3 additions & 4 deletions pkg/crd/parser_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package crd_test

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

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -116,7 +115,7 @@ var _ = Describe("CRD Generation From Parsing to CustomResourceDefinition", func
ExpectWithOffset(1, parser.CustomResourceDefinitions).To(HaveKey(groupKind))

By(fmt.Sprintf("loading the desired %s YAML", kind))
expectedFile, err := ioutil.ReadFile(fileName)
expectedFile, err := os.ReadFile(fileName)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By(fmt.Sprintf("parsing the desired %s YAML", kind))
Expand Down Expand Up @@ -219,7 +218,7 @@ var _ = Describe("CRD Generation From Parsing to CustomResourceDefinition", func
crd.FixTopLevelMetadata(parser.CustomResourceDefinitions[groupKind])

By("loading the desired YAML")
expectedFile, err := ioutil.ReadFile("plural.example.com_testquotas.yaml")
expectedFile, err := os.ReadFile("plural.example.com_testquotas.yaml")
Expect(err).NotTo(HaveOccurred())

By("parsing the desired YAML")
Expand Down Expand Up @@ -301,7 +300,7 @@ var _ = Describe("CRD Generation From Parsing to CustomResourceDefinition", func
crd.FixTopLevelMetadata(parser.CustomResourceDefinitions[groupKind])

By("loading the desired YAML")
expectedFile, err := ioutil.ReadFile("testdata.kubebuilder.io_versionedresources.yaml")
expectedFile, err := os.ReadFile("testdata.kubebuilder.io_versionedresources.yaml")
Expect(err).NotTo(HaveOccurred())

By("parsing the desired YAML")
Expand Down
3 changes: 1 addition & 2 deletions pkg/deepcopy/deepcopy_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package deepcopy_test

import (
"io"
"io/ioutil"
"os"
"sort"

Expand Down Expand Up @@ -97,7 +96,7 @@ var _ = Describe("CRD Generation From Parsing to CustomResourceDefinition", func
Expect(outContents).NotTo(BeNil())

By("loading the desired code")
expectedFile, err := ioutil.ReadFile("zz_generated.deepcopy.go")
expectedFile, err := os.ReadFile("zz_generated.deepcopy.go")
Expect(err).NotTo(HaveOccurred())

By("comparing the two")
Expand Down
3 changes: 1 addition & 2 deletions pkg/genall/genall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"

"golang.org/x/tools/go/packages"
Expand Down Expand Up @@ -214,7 +213,7 @@ func (g GenerationContext) ReadFile(path string) ([]byte, error) {
return nil, err
}
defer file.Close()
return ioutil.ReadAll(file)
return io.ReadAll(file)
}

// ForRoots produces a Runtime to run the given generators against the
Expand Down
3 changes: 1 addition & 2 deletions pkg/genall/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package genall
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -92,7 +91,7 @@ var OutputToNothing = outputToNothing{}
type outputToNothing struct{}

func (o outputToNothing) Open(_ *loader.Package, _ string) (io.WriteCloser, error) {
return nopCloser{ioutil.Discard}, nil
return nopCloser{io.Discard}, nil
}

// +controllertools:marker:generateHelp:category=""
Expand Down
3 changes: 1 addition & 2 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"go/scanner"
"go/token"
"go/types"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -111,7 +110,7 @@ func (p *Package) NeedSyntax() {
for i, filename := range p.CompiledGoFiles {
go func(i int, filename string) {
defer wg.Done()
src, err := ioutil.ReadFile(filename)
src, err := os.ReadFile(filename)
if err != nil {
p.AddError(err)
return
Expand Down
3 changes: 1 addition & 2 deletions pkg/rbac/parser_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rbac_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -49,7 +48,7 @@ var _ = Describe("ClusterRole generated by the RBAC Generator", func() {
Expect(err).NotTo(HaveOccurred())

By("loading the desired YAML")
expectedFile, err := ioutil.ReadFile("role.yaml")
expectedFile, err := os.ReadFile("role.yaml")
Expect(err).NotTo(HaveOccurred())

By("parsing the desired YAML")
Expand Down
4 changes: 2 additions & 2 deletions pkg/schemapatcher/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package schemapatcher

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -335,7 +335,7 @@ func (e *partialCRD) setVersionedSchemata(newSchemata map[string]apiext.JSONSche
// minimally invasive. Returned CRDs are mapped by group-kind.
func crdsFromDirectory(ctx *genall.GenerationContext, dir string) (map[schema.GroupKind]*partialCRDSet, error) {
res := map[schema.GroupKind]*partialCRDSet{}
dirEntries, err := ioutil.ReadDir(dir)
dirEntries, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/schemapatcher/gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package schemapatcher_test

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -44,7 +43,7 @@ var _ = Describe("CRD Patching From Parsing to Editing", func() {
rt, err := genall.Generators{&crdSchemaGen}.ForRoots("./...")
Expect(err).NotTo(HaveOccurred())

outputDir, err := ioutil.TempDir("", "controller-tools-test")
outputDir, err := os.MkdirTemp("", "controller-tools-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
rt.OutputRules.Default = genall.OutputToDirectory(outputDir)
Expand All @@ -70,7 +69,7 @@ var _ = Describe("CRD Patching From Parsing to Editing", func() {
rt, err := genall.Generators{&crdSchemaGen}.ForRoots("./...")
Expect(err).NotTo(HaveOccurred())

outputDir, err := ioutil.TempDir("", "controller-tools-test")
outputDir, err := os.MkdirTemp("", "controller-tools-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
rt.OutputRules.Default = genall.OutputToDirectory(outputDir)
Expand All @@ -80,15 +79,15 @@ var _ = Describe("CRD Patching From Parsing to Editing", func() {
Expect(rt.Run()).To(BeFalse(), "unexpectedly had errors")

By("loading the output files")
expectedFiles, err := ioutil.ReadDir("expected")
expectedFiles, err := os.ReadDir("expected")
Expect(err).NotTo(HaveOccurred())

for _, expectedFile := range expectedFiles {
By("reading the expected and actual files for " + expectedFile.Name())
actualContents, err := ioutil.ReadFile(filepath.Join(outputDir, expectedFile.Name()))
actualContents, err := os.ReadFile(filepath.Join(outputDir, expectedFile.Name()))
Expect(err).NotTo(HaveOccurred())

expectedContents, err := ioutil.ReadFile(filepath.Join("expected", expectedFile.Name()))
expectedContents, err := os.ReadFile(filepath.Join("expected", expectedFile.Name()))
Expect(err).NotTo(HaveOccurred())

By("checking that the expected and actual files for " + expectedFile.Name() + " are identical")
Expand Down
29 changes: 14 additions & 15 deletions pkg/webhook/parser_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package webhook_test

import (
"bytes"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -59,7 +58,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
genCtx := &genall.GenerationContext{
Expand Down Expand Up @@ -88,7 +87,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
genCtx := &genall.GenerationContext{
Expand Down Expand Up @@ -119,7 +118,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
genCtx := &genall.GenerationContext{
Expand Down Expand Up @@ -148,7 +147,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
genCtx := &genall.GenerationContext{
Expand Down Expand Up @@ -177,7 +176,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
genCtx := &genall.GenerationContext{
Expand All @@ -191,12 +190,12 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
}

By("loading the generated v1 YAML")
actualFile, err := ioutil.ReadFile(path.Join(outputDir, "manifests.yaml"))
actualFile, err := os.ReadFile(path.Join(outputDir, "manifests.yaml"))
Expect(err).NotTo(HaveOccurred())
actualMutating, actualValidating := unmarshalBothV1(actualFile)

By("loading the desired v1 YAML")
expectedFile, err := ioutil.ReadFile("manifests.yaml")
expectedFile, err := os.ReadFile("manifests.yaml")
Expect(err).NotTo(HaveOccurred())
expectedMutating, expectedValidating := unmarshalBothV1(expectedFile)

Expand All @@ -222,7 +221,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)

Expand All @@ -238,13 +237,13 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
}

By("loading the generated v1 YAML")
actualFile, err := ioutil.ReadFile(path.Join(outputDir, "manifests.yaml"))
actualFile, err := os.ReadFile(path.Join(outputDir, "manifests.yaml"))
Expect(err).NotTo(HaveOccurred())
actualManifest := &admissionregv1.ValidatingWebhookConfiguration{}
Expect(yaml.UnmarshalStrict(actualFile, actualManifest)).To(Succeed())

By("loading the desired v1 YAML")
expectedFile, err := ioutil.ReadFile("manifests.yaml")
expectedFile, err := os.ReadFile("manifests.yaml")
Expect(err).NotTo(HaveOccurred())
expectedManifest := &admissionregv1.ValidatingWebhookConfiguration{}
Expect(yaml.UnmarshalStrict(expectedFile, expectedManifest)).To(Succeed())
Expand All @@ -271,7 +270,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
genCtx := &genall.GenerationContext{
Expand All @@ -285,12 +284,12 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
}

By("loading the generated v1 YAML")
actualFile, err := ioutil.ReadFile(path.Join(outputDir, "manifests.yaml"))
actualFile, err := os.ReadFile(path.Join(outputDir, "manifests.yaml"))
Expect(err).NotTo(HaveOccurred())
actualMutating, actualValidating := unmarshalBothV1(actualFile)

By("loading the desired v1 YAML")
expectedFile, err := ioutil.ReadFile("manifests.yaml")
expectedFile, err := os.ReadFile("manifests.yaml")
Expect(err).NotTo(HaveOccurred())
expectedMutating, expectedValidating := unmarshalBothV1(expectedFile)

Expand All @@ -316,7 +315,7 @@ var _ = Describe("Webhook Generation From Parsing to CustomResourceDefinition",
Expect(reg.Register(webhook.ConfigDefinition)).To(Succeed())

By("requesting that the manifest be generated")
outputDir, err := ioutil.TempDir("", "webhook-integration-test")
outputDir, err := os.MkdirTemp("", "webhook-integration-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(outputDir)
genCtx := &genall.GenerationContext{
Expand Down
Loading