diff --git a/alpha/action/init.go b/alpha/action/init.go index 910b882cd..242d8f818 100644 --- a/alpha/action/init.go +++ b/alpha/action/init.go @@ -3,7 +3,6 @@ package action import ( "fmt" "io" - "io/ioutil" "github.com/h2non/filetype" @@ -25,7 +24,7 @@ func (i Init) Run() (*declcfg.Package, error) { DefaultChannel: i.DefaultChannel, } if i.DescriptionReader != nil { - descriptionData, err := ioutil.ReadAll(i.DescriptionReader) + descriptionData, err := io.ReadAll(i.DescriptionReader) if err != nil { return nil, fmt.Errorf("read description: %v", err) } @@ -33,7 +32,7 @@ func (i Init) Run() (*declcfg.Package, error) { } if i.IconReader != nil { - iconData, err := ioutil.ReadAll(i.IconReader) + iconData, err := io.ReadAll(i.IconReader) if err != nil { return nil, fmt.Errorf("read icon: %v", err) } diff --git a/alpha/action/migrate.go b/alpha/action/migrate.go index 3012c2a0e..3a502300f 100644 --- a/alpha/action/migrate.go +++ b/alpha/action/migrate.go @@ -3,7 +3,6 @@ package action import ( "context" "fmt" - "io/ioutil" "os" "github.com/operator-framework/operator-registry/alpha/declcfg" @@ -20,7 +19,7 @@ type Migrate struct { } func (m Migrate) Run(ctx context.Context) error { - entries, err := ioutil.ReadDir(m.OutputDir) + entries, err := os.ReadDir(m.OutputDir) if err != nil && !os.IsNotExist(err) { return err } diff --git a/alpha/action/render.go b/alpha/action/render.go index 98aca0c03..465f54db9 100644 --- a/alpha/action/render.go +++ b/alpha/action/render.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "sort" @@ -60,7 +60,7 @@ type Render struct { func nullLogger() *logrus.Entry { logger := logrus.New() - logger.SetOutput(ioutil.Discard) + logger.SetOutput(io.Discard) return logrus.NewEntry(logger) } @@ -155,7 +155,7 @@ func (r Render) imageToDeclcfg(ctx context.Context, imageRef string) (*declcfg.D if err != nil { return nil, err } - tmpDir, err := ioutil.TempDir("", "render-unpack-") + tmpDir, err := os.MkdirTemp("", "render-unpack-") if err != nil { return nil, err } diff --git a/cmd/opm/alpha/bundle/unpack.go b/cmd/opm/alpha/bundle/unpack.go index 59ccab379..82bddff77 100644 --- a/cmd/opm/alpha/bundle/unpack.go +++ b/cmd/opm/alpha/bundle/unpack.go @@ -4,7 +4,6 @@ import ( "context" "crypto/x509" "fmt" - "io/ioutil" "os" "path/filepath" @@ -99,7 +98,7 @@ func unpackBundle(cmd *cobra.Command, args []string) error { } if rootCA != "" { rootCAs := x509.NewCertPool() - certs, err := ioutil.ReadFile(rootCA) + certs, err := os.ReadFile(rootCA) if err != nil { return err } @@ -129,7 +128,7 @@ func unpackBundle(cmd *cobra.Command, args []string) error { return err } - dir, err := ioutil.TempDir("", "bundle-") + dir, err := os.MkdirTemp("", "bundle-") if err != nil { return err } diff --git a/cmd/opm/alpha/bundle/validate.go b/cmd/opm/alpha/bundle/validate.go index 1bc844238..c1044c05c 100644 --- a/cmd/opm/alpha/bundle/validate.go +++ b/cmd/opm/alpha/bundle/validate.go @@ -2,7 +2,6 @@ package bundle import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -80,7 +79,7 @@ func validateFunc(cmd *cobra.Command, _ []string) error { } imageValidator := bundle.NewImageValidator(registry, logger, optional) - dir, err := ioutil.TempDir("", "bundle-") + dir, err := os.MkdirTemp("", "bundle-") logger.Infof("Create a temp directory at %s", dir) if err != nil { return err diff --git a/cmd/opm/alpha/template/basic.go b/cmd/opm/alpha/template/basic.go index 2510a4fa7..5d34ec2cd 100644 --- a/cmd/opm/alpha/template/basic.go +++ b/cmd/opm/alpha/template/basic.go @@ -2,7 +2,6 @@ package template import ( "io" - "io/ioutil" "log" "os" @@ -50,7 +49,7 @@ When FILE is '-' or not provided, the template is read from standard input`, // The bundle loading impl is somewhat verbose, even on the happy path, // so discard all logrus default logger logs. Any important failures will be // returned from template.Render and logged as fatal errors. - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) reg, err := util.CreateCLIRegistry(cmd) if err != nil { diff --git a/cmd/opm/alpha/template/semver.go b/cmd/opm/alpha/template/semver.go index dd27fda07..f67f9596c 100644 --- a/cmd/opm/alpha/template/semver.go +++ b/cmd/opm/alpha/template/semver.go @@ -3,7 +3,6 @@ package template import ( "fmt" "io" - "io/ioutil" "log" "os" @@ -53,7 +52,7 @@ When FILE is '-' or not provided, the template is read from standard input`, // The bundle loading impl is somewhat verbose, even on the happy path, // so discard all logrus default logger logs. Any important failures will be // returned from template.Render and logged as fatal errors. - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) reg, err := util.CreateCLIRegistry(cmd) if err != nil { diff --git a/cmd/opm/internal/util/util.go b/cmd/opm/internal/util/util.go index 3f908981a..5b0f06f27 100644 --- a/cmd/opm/internal/util/util.go +++ b/cmd/opm/internal/util/util.go @@ -2,7 +2,7 @@ package util import ( "errors" - "io/ioutil" + "io" "os" "github.com/operator-framework/operator-registry/pkg/image/containerdregistry" @@ -69,6 +69,6 @@ func CreateCLIRegistry(cmd *cobra.Command) (*containerdregistry.Registry, error) func nullLogger() *logrus.Entry { logger := logrus.New() - logger.SetOutput(ioutil.Discard) + logger.SetOutput(io.Discard) return logrus.NewEntry(logger) } diff --git a/cmd/opm/render/cmd.go b/cmd/opm/render/cmd.go index 75be06189..e624ab197 100644 --- a/cmd/opm/render/cmd.go +++ b/cmd/opm/render/cmd.go @@ -2,7 +2,6 @@ package render import ( "io" - "io/ioutil" "log" "os" @@ -45,7 +44,7 @@ database files. // The bundle loading impl is somewhat verbose, even on the happy path, // so discard all logrus default logger logs. Any important failures will be // returned from render.Run and logged as fatal errors. - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) reg, err := util.CreateCLIRegistry(cmd) if err != nil { @@ -72,6 +71,6 @@ database files. func nullLogger() *logrus.Entry { logger := logrus.New() - logger.SetOutput(ioutil.Discard) + logger.SetOutput(io.Discard) return logrus.NewEntry(logger) } diff --git a/pkg/configmap/configmap_writer.go b/pkg/configmap/configmap_writer.go index c2c5e42f2..580aeaeb0 100644 --- a/pkg/configmap/configmap_writer.go +++ b/pkg/configmap/configmap_writer.go @@ -3,7 +3,6 @@ package configmap import ( "context" "fmt" - "io/ioutil" "os" "regexp" @@ -85,7 +84,7 @@ func (c *ConfigMapWriter) Populate(maxDataSizeLimit uint64) error { var totalSize uint64 for _, dir := range subDirs { completePath := c.manifestsDir + dir - files, err := ioutil.ReadDir(completePath) + files, err := os.ReadDir(completePath) if err != nil { logrus.Errorf("read dir failed: %v", err) return err @@ -95,7 +94,7 @@ func (c *ConfigMapWriter) Populate(maxDataSizeLimit uint64) error { log := logrus.WithField("file", completePath+file.Name()) log.Info("Reading file") - content, err := ioutil.ReadFile(completePath + file.Name()) + content, err := os.ReadFile(completePath + file.Name()) if err != nil { log.Errorf("read failed: %v", err) return err diff --git a/pkg/image/mock.go b/pkg/image/mock.go index 6f856c30e..f46d58516 100644 --- a/pkg/image/mock.go +++ b/pkg/image/mock.go @@ -4,7 +4,6 @@ import ( "context" "errors" "io/fs" - "io/ioutil" "os" "path/filepath" "sync" @@ -40,7 +39,7 @@ func (i *MockImage) unpack(dir string) error { if err := os.MkdirAll(pathDir, 0777); err != nil { return err } - return ioutil.WriteFile(path, data, 0666) + return os.WriteFile(path, data, 0666) }) } diff --git a/pkg/image/registry_test.go b/pkg/image/registry_test.go index 3577ff1d3..c8eb04269 100644 --- a/pkg/image/registry_test.go +++ b/pkg/image/registry_test.go @@ -5,7 +5,6 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" "math" "math/rand" "net/http" @@ -35,7 +34,7 @@ type newRegistryFunc func(t *testing.T, cafile string) (image.Registry, cleanupF func poolForCertFile(t *testing.T, file string) *x509.CertPool { rootCAs := x509.NewCertPool() - certs, err := ioutil.ReadFile(file) + certs, err := os.ReadFile(file) require.NoError(t, err) require.True(t, rootCAs.AppendCertsFromPEM(certs)) return rootCAs diff --git a/pkg/lib/bundle/chartutil.go b/pkg/lib/bundle/chartutil.go index 42418ce1b..f7090446a 100644 --- a/pkg/lib/bundle/chartutil.go +++ b/pkg/lib/bundle/chartutil.go @@ -19,7 +19,6 @@ limitations under the License. package bundle import ( - "io/ioutil" "os" "path/filepath" @@ -125,7 +124,7 @@ func IsChartDir(dirName string) (bool, error) { return false, errors.Errorf("no %s exists in directory %q", ChartfileName, dirName) } - chartYamlContent, err := ioutil.ReadFile(chartYaml) + chartYamlContent, err := os.ReadFile(chartYaml) if err != nil { return false, errors.Errorf("cannot read %s in directory %q", ChartfileName, dirName) } diff --git a/pkg/lib/bundle/exporter.go b/pkg/lib/bundle/exporter.go index be9f36312..043aac1ac 100644 --- a/pkg/lib/bundle/exporter.go +++ b/pkg/lib/bundle/exporter.go @@ -2,7 +2,6 @@ package bundle import ( "context" - "io/ioutil" "os" "path/filepath" @@ -34,7 +33,7 @@ func (i *BundleExporter) Export(skipTLSVerify, plainHTTP bool) error { log := logrus.WithField("img", i.image) - tmpDir, err := ioutil.TempDir("./", "bundle_tmp") + tmpDir, err := os.MkdirTemp("./", "bundle_tmp") if err != nil { return err } diff --git a/pkg/lib/bundle/generate.go b/pkg/lib/bundle/generate.go index 0e480c41a..5b9d82153 100644 --- a/pkg/lib/bundle/generate.go +++ b/pkg/lib/bundle/generate.go @@ -3,7 +3,6 @@ package bundle import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -180,7 +179,7 @@ func CopyYamlOutput(annotationsContent []byte, manifestDir, outputDir, workingDi } // Now, generate the `metadata/` dir and write the annotations - file, err := ioutil.ReadFile(filepath.Join(copyDir, MetadataDir, AnnotationsFile)) + file, err := os.ReadFile(filepath.Join(copyDir, MetadataDir, AnnotationsFile)) if os.IsNotExist(err) || overwrite { writeDir := filepath.Join(copyDir, MetadataDir) err = WriteFile(AnnotationsFile, writeDir, annotationsContent) @@ -209,7 +208,7 @@ func GetMediaType(directory string) (string, error) { k8sFiles := make(map[string]*unstructured.Unstructured) // Read all file names in directory - items, _ := ioutil.ReadDir(directory) + items, _ := os.ReadDir(directory) for _, item := range items { if item.IsDir() { continue @@ -218,7 +217,7 @@ func GetMediaType(directory string) (string, error) { files = append(files, item.Name()) fileWithPath := filepath.Join(directory, item.Name()) - fileBlob, err := ioutil.ReadFile(fileWithPath) + fileBlob, err := os.ReadFile(fileWithPath) if err != nil { return "", fmt.Errorf("Unable to read file %s in bundle", fileWithPath) } @@ -367,7 +366,7 @@ func WriteFile(fileName, directory string, content []byte) error { } } log.Infof("Writing %s in %s", fileName, directory) - err := ioutil.WriteFile(filepath.Join(directory, fileName), content, DefaultPermission) + err := os.WriteFile(filepath.Join(directory, fileName), content, DefaultPermission) if err != nil { return err } @@ -376,7 +375,7 @@ func WriteFile(fileName, directory string, content []byte) error { // copy the contents of a potentially nested manifest dir into an output dir. func copyManifestDir(from, to string, overwrite bool) error { - fromFiles, err := ioutil.ReadDir(from) + fromFiles, err := os.ReadDir(from) if err != nil { return err } @@ -431,7 +430,11 @@ func copyManifestDir(from, to string, overwrite bool) error { return err } - err = os.Chmod(toFilePath, fromFile.Mode()) + info, err := fromFile.Info() + if err != nil { + return err + } + err = os.Chmod(toFilePath, info.Mode()) if err != nil { return err } diff --git a/pkg/lib/bundle/generate_test.go b/pkg/lib/bundle/generate_test.go index db00423b4..2727855a2 100644 --- a/pkg/lib/bundle/generate_test.go +++ b/pkg/lib/bundle/generate_test.go @@ -2,7 +2,6 @@ package bundle import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -194,12 +193,12 @@ func TestCopyYamlOutput(t *testing.T) { require.Equal(t, filepath.Join(testOutputDir, "metadata/"), resultMetadataDir) outputAnnotationsFile := filepath.Join(testOutputDir, "metadata/", "annotations.yaml") - annotationsBlob, err := ioutil.ReadFile(outputAnnotationsFile) + annotationsBlob, err := os.ReadFile(outputAnnotationsFile) require.NoError(t, err) require.Equal(t, testContent, annotationsBlob) csvFile := filepath.Join(testOutputDir, "manifests/", "prometheusoperator.0.14.0.clusterserviceversion.yaml") - _, err = ioutil.ReadFile(csvFile) + _, err = os.ReadFile(csvFile) require.NoError(t, err) } @@ -215,7 +214,7 @@ func TestCopyYamlOutput_NoOutputDir(t *testing.T) { require.Equal(t, filepath.Join(filepath.Dir(testManifestDir), "metadata/"), resultMetadataDir) outputAnnotationsFile := filepath.Join(resultMetadataDir, "annotations.yaml") - annotationsBlob, err := ioutil.ReadFile(outputAnnotationsFile) + annotationsBlob, err := os.ReadFile(outputAnnotationsFile) require.NoError(t, err) require.Equal(t, testContent, annotationsBlob) @@ -236,12 +235,12 @@ func TestCopyYamlOutput_NestedCopy(t *testing.T) { require.Equal(t, filepath.Join(testOutputDir, "metadata/"), resultMetadataDir) outputAnnotationsFile := filepath.Join(testOutputDir, "metadata/", "annotations.yaml") - annotationsBlob, err := ioutil.ReadFile(outputAnnotationsFile) + annotationsBlob, err := os.ReadFile(outputAnnotationsFile) require.NoError(t, err) require.Equal(t, testContent, annotationsBlob) csvFile := filepath.Join(testOutputDir, "manifests/nested_manifests/", "prometheusoperator.0.14.0.clusterserviceversion.yaml") - _, err = ioutil.ReadFile(csvFile) + _, err = os.ReadFile(csvFile) require.NoError(t, err) } @@ -261,7 +260,7 @@ func TestGenerateFunc(t *testing.T) { " operators.operatorframework.io.bundle.metadata.v1: metadata/\n" + " operators.operatorframework.io.bundle.package.v1: etcd\n") outputAnnotationsFile := filepath.Join(outputPath, "metadata/", "annotations.yaml") - annotationsBlob, err := ioutil.ReadFile(outputAnnotationsFile) + annotationsBlob, err := os.ReadFile(outputAnnotationsFile) require.NoError(t, err) require.EqualValues(t, output, string(annotationsBlob)) } diff --git a/pkg/lib/bundle/utils_test.go b/pkg/lib/bundle/utils_test.go index 86ed4b5d9..6757b6ac7 100644 --- a/pkg/lib/bundle/utils_test.go +++ b/pkg/lib/bundle/utils_test.go @@ -1,7 +1,6 @@ package bundle import ( - "io/ioutil" "os" "path/filepath" @@ -65,7 +64,7 @@ func buildTestAnnotations(key string, items map[string]string) []byte { } func clearDir(dir string) { - items, _ := ioutil.ReadDir(dir) + items, _ := os.ReadDir(dir) for _, item := range items { if item.IsDir() { diff --git a/pkg/lib/bundle/validate.go b/pkg/lib/bundle/validate.go index fb8ca0368..a11025c28 100644 --- a/pkg/lib/bundle/validate.go +++ b/pkg/lib/bundle/validate.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "os" "path/filepath" "strings" @@ -79,7 +79,7 @@ func (i imageValidator) ValidateBundleFormat(directory string) error { var metadataDir, manifestsDir string var validationErrors []error - items, err := ioutil.ReadDir(directory) + items, err := os.ReadDir(directory) if err != nil { validationErrors = append(validationErrors, err) } @@ -118,7 +118,7 @@ func (i imageValidator) ValidateBundleFormat(directory string) error { } // Validate annotations file - files, err := ioutil.ReadDir(metadataDir) + files, err := os.ReadDir(metadataDir) if err != nil { validationErrors = append(validationErrors, err) } @@ -282,14 +282,14 @@ func (i imageValidator) ValidateBundleContent(manifestDir string) error { crdValidator := v.CustomResourceDefinitionValidator // Read all files in manifests directory - items, err := ioutil.ReadDir(manifestDir) + items, err := os.ReadDir(manifestDir) if err != nil { validationErrors = append(validationErrors, err) } for _, item := range items { fileWithPath := filepath.Join(manifestDir, item.Name()) - data, err := ioutil.ReadFile(fileWithPath) + data, err := os.ReadFile(fileWithPath) if err != nil { validationErrors = append(validationErrors, fmt.Errorf("Unable to read file %s in supported types", fileWithPath)) continue diff --git a/pkg/lib/certs/certs.go b/pkg/lib/certs/certs.go index 2d1c8f519..3317d5766 100644 --- a/pkg/lib/certs/certs.go +++ b/pkg/lib/certs/certs.go @@ -3,7 +3,7 @@ package certs import ( "crypto/x509" "fmt" - "io/ioutil" + "os" ) // RootCAs gets root CAs from system store and the given file @@ -13,7 +13,7 @@ func RootCAs(CaFile string) (*x509.CertPool, error) { rootCAs = x509.NewCertPool() } if len(CaFile) > 0 { - certs, err := ioutil.ReadFile(CaFile) + certs, err := os.ReadFile(CaFile) if err != nil { return nil, fmt.Errorf("failed to append %q to RootCAs: %v", certs, err) } diff --git a/pkg/lib/dns/nsswitch.go b/pkg/lib/dns/nsswitch.go index 0e69f7e79..1693272fd 100644 --- a/pkg/lib/dns/nsswitch.go +++ b/pkg/lib/dns/nsswitch.go @@ -1,7 +1,6 @@ package dns import ( - "io/ioutil" "os" "runtime" ) @@ -24,5 +23,5 @@ func EnsureNsswitch() error { return nil } - return ioutil.WriteFile(NsswitchFilename, NsswitchContents, 0644) + return os.WriteFile(NsswitchFilename, NsswitchContents, 0644) } diff --git a/pkg/lib/dns/nsswitch_test.go b/pkg/lib/dns/nsswitch_test.go index 02eb12eb9..c49bc6b0e 100644 --- a/pkg/lib/dns/nsswitch_test.go +++ b/pkg/lib/dns/nsswitch_test.go @@ -1,7 +1,6 @@ package dns import ( - "io/ioutil" "os" "testing" @@ -50,7 +49,7 @@ func TestEnsureNsswitch(t *testing.T) { NsswitchFilename = "testfile" if tt.existingFile { - require.NoError(t, ioutil.WriteFile(NsswitchFilename, []byte("test"), 0644)) + require.NoError(t, os.WriteFile(NsswitchFilename, []byte("test"), 0644)) } if err := EnsureNsswitch(); (err != nil) != tt.wantErr { @@ -58,13 +57,13 @@ func TestEnsureNsswitch(t *testing.T) { } if tt.wantFile { - contents, err := ioutil.ReadFile(NsswitchFilename) + contents, err := os.ReadFile(NsswitchFilename) require.NoError(t, err) require.Equal(t, NsswitchContents, contents) os.Remove(NsswitchFilename) } if tt.existingFile { - contents, err := ioutil.ReadFile(NsswitchFilename) + contents, err := os.ReadFile(NsswitchFilename) require.NoError(t, err) require.NotEqual(t, NsswitchContents, contents) os.Remove(NsswitchFilename) diff --git a/pkg/lib/image/registry.go b/pkg/lib/image/registry.go index 84c49f94f..8e0aca841 100644 --- a/pkg/lib/image/registry.go +++ b/pkg/lib/image/registry.go @@ -12,7 +12,6 @@ import ( "encoding/pem" "fmt" "io" - "io/ioutil" "math/big" "net" "net/http" @@ -40,15 +39,15 @@ func RunDockerRegistry(ctx context.Context, rootDir string, configOpts ...Config host := fmt.Sprintf("localhost:%d", dockerPort) certPool := x509.NewCertPool() - cafile, err := ioutil.TempFile("", "ca") + cafile, err := os.CreateTemp("", "ca") if err != nil { return "", "", err } - certfile, err := ioutil.TempFile("", "cert") + certfile, err := os.CreateTemp("", "cert") if err != nil { return "", "", err } - keyfile, err := ioutil.TempFile("", "key") + keyfile, err := os.CreateTemp("", "key") if err != nil { return "", "", err } diff --git a/pkg/lib/indexer/indexer.go b/pkg/lib/indexer/indexer.go index 81fbc414a..b3e5c1848 100644 --- a/pkg/lib/indexer/indexer.go +++ b/pkg/lib/indexer/indexer.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/rand" "os" "path" @@ -303,7 +302,7 @@ func (i ImageIndexer) PruneFromIndex(request PruneFromIndexRequest) error { // ExtractDatabase sets a temp directory for unpacking an image func (i ImageIndexer) ExtractDatabase(buildDir, fromIndex, caFile string, skipTLSVerify, plainHTTP bool) (string, error) { - tmpDir, err := ioutil.TempDir("./", tmpDirPrefix) + tmpDir, err := os.MkdirTemp("./", tmpDirPrefix) if err != nil { return "", err } @@ -426,7 +425,7 @@ func buildContext(generate bool, requestedDockerfile string) (buildDir, outDocke } // set a temp directory for building the new image - buildDir, err = ioutil.TempDir(".", tmpBuildDirPrefix) + buildDir, err = os.MkdirTemp(".", tmpBuildDirPrefix) if err != nil { return } @@ -440,7 +439,7 @@ func buildContext(generate bool, requestedDockerfile string) (buildDir, outDocke } // generate a temp dockerfile if needed - tempDockerfile, err := ioutil.TempFile(".", defaultDockerfileName) + tempDockerfile, err := os.CreateTemp(".", defaultDockerfileName) if err != nil { defer cleanup() return @@ -504,7 +503,7 @@ type ExportFromIndexRequest struct { // an index image func (i ImageIndexer) ExportFromIndex(request ExportFromIndexRequest) error { // set a temp directory - workingDir, err := ioutil.TempDir("./", tmpDirPrefix) + workingDir, err := os.MkdirTemp("./", tmpDirPrefix) if err != nil { return err } diff --git a/pkg/lib/indexer/indexer_test.go b/pkg/lib/indexer/indexer_test.go index 6797d0e0d..a5da2c972 100644 --- a/pkg/lib/indexer/indexer_test.go +++ b/pkg/lib/indexer/indexer_test.go @@ -1,7 +1,6 @@ package indexer import ( - "io/ioutil" "os" "reflect" "sort" @@ -64,14 +63,14 @@ func TestGeneratePackageYaml(t *testing.T) { } var expected pregistry.PackageManifest - expectedBytes, _ := ioutil.ReadFile("./testdata/package.yaml") + expectedBytes, _ := os.ReadFile("./testdata/package.yaml") err = yaml.Unmarshal(expectedBytes, &expected) if err != nil { t.Fatalf("unmarshaling: %s", err) } var actual pregistry.PackageManifest - actualBytes, _ := ioutil.ReadFile("./package.yaml") + actualBytes, _ := os.ReadFile("./package.yaml") err = yaml.Unmarshal(actualBytes, &actual) if err != nil { t.Fatalf("unmarshaling: %s", err) diff --git a/pkg/lib/log/writerhook.go b/pkg/lib/log/writerhook.go index 7609ae27f..a67dc675f 100644 --- a/pkg/lib/log/writerhook.go +++ b/pkg/lib/log/writerhook.go @@ -2,7 +2,6 @@ package log import ( "io" - "io/ioutil" "os" "github.com/sirupsen/logrus" @@ -36,7 +35,7 @@ func (hook *WriterHook) Levels() []logrus.Level { // AddHooks adds hooks to send logs to different destinations depending on level func AddHooks(hooks ...*WriterHook) { // Send all logs to nowhere by default - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) for _, hook := range hooks { logrus.AddHook(hook) diff --git a/pkg/lib/registry/registry.go b/pkg/lib/registry/registry.go index a923cbd5e..a4174197b 100644 --- a/pkg/lib/registry/registry.go +++ b/pkg/lib/registry/registry.go @@ -3,7 +3,6 @@ package registry import ( "context" "fmt" - "io/ioutil" "os" "github.com/sirupsen/logrus" @@ -106,7 +105,7 @@ func (r RegistryUpdater) AddToRegistry(request AddToRegistryRequest) error { func unpackImage(ctx context.Context, reg image.Registry, ref image.Reference) (image.Reference, string, func(), error) { var errs []error - workingDir, err := ioutil.TempDir("./", "bundle_tmp") + workingDir, err := os.MkdirTemp("./", "bundle_tmp") if err != nil { errs = append(errs, err) } diff --git a/pkg/lib/registry/registry_test.go b/pkg/lib/registry/registry_test.go index 43f4d3998..13e72f700 100644 --- a/pkg/lib/registry/registry_test.go +++ b/pkg/lib/registry/registry_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -350,7 +349,7 @@ func newUnpackedTestBundle(dir, name string, csvSpec json.RawMessage, annotation if err != nil { return bundleDir, cleanup, err } - if err := ioutil.WriteFile(filepath.Join(bundleDir, bundle.ManifestsDir, "csv.yaml"), out, 0666); err != nil { + if err := os.WriteFile(filepath.Join(bundleDir, bundle.ManifestsDir, "csv.yaml"), out, 0666); err != nil { return bundleDir, cleanup, err } @@ -358,7 +357,7 @@ func newUnpackedTestBundle(dir, name string, csvSpec json.RawMessage, annotation if err != nil { return bundleDir, cleanup, err } - if err := ioutil.WriteFile(filepath.Join(bundleDir, bundle.MetadataDir, "annotations.yaml"), out, 0666); err != nil { + if err := os.WriteFile(filepath.Join(bundleDir, bundle.MetadataDir, "annotations.yaml"), out, 0666); err != nil { return bundleDir, cleanup, err } return bundleDir, cleanup, nil diff --git a/pkg/lib/tmp/copy.go b/pkg/lib/tmp/copy.go index 52a247f41..a48a3e219 100644 --- a/pkg/lib/tmp/copy.go +++ b/pkg/lib/tmp/copy.go @@ -3,13 +3,12 @@ package tmp import ( "fmt" "io" - "io/ioutil" "os" ) // CopyTmpDB reads the file at the given path and copies it to a tmp directory, returning the copied file path or an err func CopyTmpDB(original string) (path string, err error) { - dst, err := ioutil.TempFile("", "db-") + dst, err := os.CreateTemp("", "db-") if err != nil { return "", err } diff --git a/pkg/lib/validation/bundle_test.go b/pkg/lib/validation/bundle_test.go index ce65cd964..a0e31eef5 100644 --- a/pkg/lib/validation/bundle_test.go +++ b/pkg/lib/validation/bundle_test.go @@ -1,7 +1,7 @@ package validation import ( - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -43,12 +43,12 @@ func TestValidateBundle(t *testing.T) { unstObjs := []*unstructured.Unstructured{} // Read all files in manifests directory - items, err := ioutil.ReadDir(tt.directory) + items, err := os.ReadDir(tt.directory) require.NoError(t, err, "Unable to read directory: %s", tt.description) for _, item := range items { fileWithPath := filepath.Join(tt.directory, item.Name()) - data, err := ioutil.ReadFile(fileWithPath) + data, err := os.ReadFile(fileWithPath) require.NoError(t, err, "Unable to read file: %s", fileWithPath) dec := k8syaml.NewYAMLOrJSONDecoder(strings.NewReader(string(data)), 30) diff --git a/pkg/registry/bundle_test.go b/pkg/registry/bundle_test.go index b2fd3b549..682d56938 100644 --- a/pkg/registry/bundle_test.go +++ b/pkg/registry/bundle_test.go @@ -2,7 +2,7 @@ package registry import ( "encoding/json" - "io/ioutil" + "os" "path/filepath" "reflect" "strings" @@ -31,7 +31,7 @@ func TestV1CRDsInBundle(t *testing.T) { }) // Read all files in manifests directory - items, err := ioutil.ReadDir(manifestDir) + items, err := os.ReadDir(manifestDir) if err != nil { t.Fatalf("reading manifests directory: %s", err) } @@ -40,7 +40,7 @@ func TestV1CRDsInBundle(t *testing.T) { unstObjs := []*unstructured.Unstructured{} for _, item := range items { fileWithPath := filepath.Join(manifestDir, item.Name()) - data, err := ioutil.ReadFile(fileWithPath) + data, err := os.ReadFile(fileWithPath) if err != nil { t.Fatalf("reading manifests directory file %s: %s", fileWithPath, err) } diff --git a/pkg/registry/directoryGraphLoader.go b/pkg/registry/directoryGraphLoader.go index b639c08b5..a899f01e0 100644 --- a/pkg/registry/directoryGraphLoader.go +++ b/pkg/registry/directoryGraphLoader.go @@ -2,7 +2,6 @@ package registry import ( "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -36,7 +35,7 @@ func (c csvs) Swap(i, j int) { c[i], c[j] = c[j], c[i] } // NewPackageGraphLoaderFromDir takes the root directory of the package in the file system. func NewPackageGraphLoaderFromDir(packageDir string) (*DirGraphLoader, error) { - _, err := ioutil.ReadDir(packageDir) + _, err := os.ReadDir(packageDir) if err != nil { return nil, fmt.Errorf("error reading from %s directory, %v", packageDir, err) } @@ -71,7 +70,7 @@ func (g *DirGraphLoader) Generate() (*Package, error) { // loadBundleCsvPathMap loads the CsvNameAndReplaceMap and SortedCSVs in the Package Struct. func (g *DirGraphLoader) loadBundleCsvPathMap() error { - bundleDirs, err := ioutil.ReadDir(g.PackageDir) + bundleDirs, err := os.ReadDir(g.PackageDir) if err != nil { return fmt.Errorf("error reading from %s directory, %v", g.PackageDir, err) } @@ -156,7 +155,7 @@ func (g *DirGraphLoader) getChannelNodes(channelHeadCsv string) *map[BundleKey]m // parsePackageYAMLFile parses the *.package.yaml file and fills the information in Package including name, // defaultchannel, and head of all Channels. It returns parsing error if any. func (g *DirGraphLoader) parsePackageYAMLFile() (*Package, error) { - files, err := ioutil.ReadDir(g.PackageDir) + files, err := os.ReadDir(g.PackageDir) if err != nil { return nil, fmt.Errorf("error reading bundle parent directory, %v", err) } diff --git a/pkg/registry/populator_test.go b/pkg/registry/populator_test.go index b7b83a27f..d7dc4f5d7 100644 --- a/pkg/registry/populator_test.go +++ b/pkg/registry/populator_test.go @@ -5,7 +5,6 @@ import ( "database/sql" "encoding/json" "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -3072,7 +3071,7 @@ func newUnpackedTestBundle(root, dir, name string, csvSpec json.RawMessage, anno if err != nil { return bundleDir, cleanup, err } - if err := ioutil.WriteFile(filepath.Join(bundleDir, bundle.ManifestsDir, "csv.yaml"), out, 0666); err != nil { + if err := os.WriteFile(filepath.Join(bundleDir, bundle.ManifestsDir, "csv.yaml"), out, 0666); err != nil { return bundleDir, cleanup, err } @@ -3080,7 +3079,7 @@ func newUnpackedTestBundle(root, dir, name string, csvSpec json.RawMessage, anno if err != nil { return bundleDir, cleanup, err } - if err := ioutil.WriteFile(filepath.Join(bundleDir, bundle.MetadataDir, "annotations.yaml"), out, 0666); err != nil { + if err := os.WriteFile(filepath.Join(bundleDir, bundle.MetadataDir, "annotations.yaml"), out, 0666); err != nil { return bundleDir, cleanup, err } return bundleDir, cleanup, nil diff --git a/pkg/sqlite/configmap_test.go b/pkg/sqlite/configmap_test.go index a40c9fef9..88786edc2 100644 --- a/pkg/sqlite/configmap_test.go +++ b/pkg/sqlite/configmap_test.go @@ -5,7 +5,6 @@ import ( "context" "database/sql" "fmt" - "io/ioutil" "math/rand" "os" "strings" @@ -70,7 +69,7 @@ func TestReplaceCycle(t *testing.T) { require.NoError(t, err) path := "../../configmap.example.yaml" - cmap, err := ioutil.ReadFile(path) + cmap, err := os.ReadFile(path) require.NoError(t, err, "unable to load configmap from file %s", path) diff --git a/pkg/sqlite/directory.go b/pkg/sqlite/directory.go index f4b2e3e6c..2ed0c595e 100644 --- a/pkg/sqlite/directory.go +++ b/pkg/sqlite/directory.go @@ -2,7 +2,6 @@ package sqlite import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -181,7 +180,7 @@ func (d *DirectoryLoader) LoadPackagesWalkFunc(path string, f os.FileInfo, err e // are part of the bundle. func loadBundle(csvName string, dir string) (*registry.Bundle, error) { log := logrus.WithFields(logrus.Fields{"dir": dir, "load": "bundle", "name": csvName}) - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return nil, err } diff --git a/test/e2e/bundle_image_test.go b/test/e2e/bundle_image_test.go index c72359087..cf48dd35e 100644 --- a/test/e2e/bundle_image_test.go +++ b/test/e2e/bundle_image_test.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "os/exec" "regexp" @@ -188,7 +187,7 @@ var _ = Describe("Launch bundle", func() { for _, pod := range pl.Items { logs, err := kubeclient.CoreV1().Pods(namespace).GetLogs(pod.GetName(), &corev1.PodLogOptions{}).Stream(context.Background()) Expect(err).NotTo(HaveOccurred()) - logData, err := ioutil.ReadAll(logs) + logData, err := io.ReadAll(logs) Expect(err).NotTo(HaveOccurred()) Logf("Pod logs for unpack job pod %q:\n%s", pod.GetName(), string(logData)) } diff --git a/test/e2e/opm_bundle_test.go b/test/e2e/opm_bundle_test.go index d129d3192..18464b9bb 100644 --- a/test/e2e/opm_bundle_test.go +++ b/test/e2e/opm_bundle_test.go @@ -3,7 +3,7 @@ package e2e_test import ( "bytes" "context" - "io/ioutil" + "io" "os" "path/filepath" @@ -60,7 +60,7 @@ var _ = Describe("opm alpha bundle", func() { Expect(err).ToNot(HaveOccurred()) // Set up a temporary directory that we can use for testing - tmpDir, err = ioutil.TempDir("", "opm-alpha-bundle-") + tmpDir, err = os.MkdirTemp("", "opm-alpha-bundle-") Expect(err).ToNot(HaveOccurred()) }) @@ -89,7 +89,7 @@ var _ = Describe("opm alpha bundle", func() { }) Expect(opm.Execute()).ToNot(Succeed()) - result, err := ioutil.ReadAll(&out) + result, err := io.ReadAll(&out) Expect(err).ToNot(HaveOccurred()) Expect(string(result)).To(ContainSubstring("bundle content validation failed")) }) @@ -111,7 +111,7 @@ var _ = Describe("opm alpha bundle", func() { }) Expect(opm.Execute()).To(Succeed()) - result, err := ioutil.ReadAll(&out) + result, err := io.ReadAll(&out) Expect(err).ToNot(HaveOccurred()) Expect(result).ToNot(ContainSubstring("bundle content validation failed")) diff --git a/test/e2e/opm_test.go b/test/e2e/opm_test.go index ad39e461b..7a1dcf548 100644 --- a/test/e2e/opm_test.go +++ b/test/e2e/opm_test.go @@ -4,7 +4,6 @@ import ( "context" "database/sql" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -72,7 +71,7 @@ func (bl bundleLocations) images() []string { } func inTemporaryBuildContext(f func() error, fromDir, toDir string) (rerr error) { - td, err := ioutil.TempDir(".", "opm-") + td, err := os.MkdirTemp(".", "opm-") if err != nil { return err } @@ -246,7 +245,7 @@ func exportIndexImageWith(containerTool string) error { } func initialize() error { - tmpDB, err := ioutil.TempFile("./", "index_tmp.db") + tmpDB, err := os.CreateTemp("./", "index_tmp.db") if err != nil { return err } @@ -306,7 +305,7 @@ var _ = Describe("opm", func() { } Expect(err).NotTo(HaveOccurred()) - unpackDir, err := ioutil.TempDir(".", bundleTag3) + unpackDir, err := os.MkdirTemp(".", bundleTag3) Expect(err).NotTo(HaveOccurred()) validator := bundle.NewImageValidator(registry, logger) Expect(validator.PullBundleImage(img, unpackDir)).To(Succeed()) @@ -420,7 +419,7 @@ var _ = Describe("opm", func() { By("building bundles") for _, b := range bundles { - td, err := ioutil.TempDir(".", "opm-") + td, err := os.MkdirTemp(".", "opm-") Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(td) @@ -456,7 +455,7 @@ var _ = Describe("opm", func() { } for _, b := range bundles { - td, err := ioutil.TempDir(".", "opm-") + td, err := os.MkdirTemp(".", "opm-") Expect(err).NotTo(HaveOccurred()) defer os.RemoveAll(td)