From a4ca44470bf97a29d78e5a642cbb42933eee71bc Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Mon, 24 Nov 2025 12:27:14 -0600 Subject: [PATCH] Migrate away from deprecated ioutil --- pkg/profiling/config/config.go | 4 ++-- staging/api/pkg/manifests/bundleloader.go | 3 +-- staging/api/pkg/validation/internal/community.go | 3 +-- staging/api/pkg/validation/internal/crd_test.go | 4 ++-- staging/api/pkg/validation/internal/csv_test.go | 4 ++-- staging/api/pkg/validation/internal/object_test.go | 4 ++-- staging/api/pkg/validation/internal/operatorgroup_test.go | 4 ++-- staging/api/pkg/validation/internal/operatorhub.go | 4 ++-- .../operator-registry/pkg/image/buildahregistry/_options.go | 3 +-- staging/operator-registry/test/e2e/ctx/provisioner_kind.go | 3 +-- 10 files changed, 16 insertions(+), 20 deletions(-) diff --git a/pkg/profiling/config/config.go b/pkg/profiling/config/config.go index e7111ea12f..a1a9526f21 100644 --- a/pkg/profiling/config/config.go +++ b/pkg/profiling/config/config.go @@ -1,7 +1,7 @@ package config import ( - "io/ioutil" + "os" "path/filepath" "gopkg.in/yaml.v2" @@ -44,7 +44,7 @@ type config struct { } func GetConfig(path string) (*config, error) { - data, err := ioutil.ReadFile(filepath.Join(path, "pprof-config.yaml")) + data, err := os.ReadFile(filepath.Join(path, "pprof-config.yaml")) if err != nil { return nil, err } diff --git a/staging/api/pkg/manifests/bundleloader.go b/staging/api/pkg/manifests/bundleloader.go index 397190a6a1..24cfb5de02 100644 --- a/staging/api/pkg/manifests/bundleloader.go +++ b/staging/api/pkg/manifests/bundleloader.go @@ -2,7 +2,6 @@ package manifests import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -180,7 +179,7 @@ func (b *bundleLoader) LoadBundleWalkFunc(path string, f os.FileInfo, err error) // loadBundle takes the directory that a CSV is in and assumes the rest of the objects in that directory // are part of the bundle. func loadBundle(csvName string, dir string) (*Bundle, error) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return nil, err } diff --git a/staging/api/pkg/validation/internal/community.go b/staging/api/pkg/validation/internal/community.go index debaae2bab..37473fd311 100644 --- a/staging/api/pkg/validation/internal/community.go +++ b/staging/api/pkg/validation/internal/community.go @@ -3,7 +3,6 @@ package internal import ( "encoding/json" "fmt" - "io/ioutil" "os" "strings" @@ -225,7 +224,7 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string) return checks } - b, err := ioutil.ReadFile(checks.indexImagePath) + b, err := os.ReadFile(checks.indexImagePath) if err != nil { checks.errs = append(checks.errs, fmt.Errorf("unable to read the index image in the path "+ "(%s). Error : %s", checks.indexImagePath, err)) diff --git a/staging/api/pkg/validation/internal/crd_test.go b/staging/api/pkg/validation/internal/crd_test.go index f28804fcfa..19f1255376 100644 --- a/staging/api/pkg/validation/internal/crd_test.go +++ b/staging/api/pkg/validation/internal/crd_test.go @@ -1,7 +1,7 @@ package internal import ( - "io/ioutil" + "os" "testing" "github.com/operator-framework/api/pkg/validation/errors" @@ -57,7 +57,7 @@ func TestValidateCRD(t *testing.T) { }, } for _, tt := range table { - b, err := ioutil.ReadFile(tt.filePath) + b, err := os.ReadFile(tt.filePath) if err != nil { t.Fatalf("Error reading CRD path %s: %v", tt.filePath, err) } diff --git a/staging/api/pkg/validation/internal/csv_test.go b/staging/api/pkg/validation/internal/csv_test.go index 440cbcf3c7..dd80f318a3 100644 --- a/staging/api/pkg/validation/internal/csv_test.go +++ b/staging/api/pkg/validation/internal/csv_test.go @@ -2,7 +2,7 @@ package internal import ( "fmt" - "io/ioutil" + "os" "path/filepath" "testing" @@ -121,7 +121,7 @@ func TestValidateCSV(t *testing.T) { } for _, c := range cases { - b, err := ioutil.ReadFile(c.csvPath) + b, err := os.ReadFile(c.csvPath) if err != nil { t.Fatalf("Error reading CSV path %s: %v", c.csvPath, err) } diff --git a/staging/api/pkg/validation/internal/object_test.go b/staging/api/pkg/validation/internal/object_test.go index 573497c6ad..7f93be1522 100644 --- a/staging/api/pkg/validation/internal/object_test.go +++ b/staging/api/pkg/validation/internal/object_test.go @@ -1,7 +1,7 @@ package internal import ( - "io/ioutil" + "os" "testing" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -66,7 +66,7 @@ func TestValidateObject(t *testing.T) { for _, tt := range table { u := unstructured.Unstructured{} - o, err := ioutil.ReadFile(tt.path) + o, err := os.ReadFile(tt.path) if err != nil { t.Fatalf("reading yaml object file: %s", err) } diff --git a/staging/api/pkg/validation/internal/operatorgroup_test.go b/staging/api/pkg/validation/internal/operatorgroup_test.go index b6eddac53e..ee4d2ea8c8 100644 --- a/staging/api/pkg/validation/internal/operatorgroup_test.go +++ b/staging/api/pkg/validation/internal/operatorgroup_test.go @@ -1,7 +1,7 @@ package internal import ( - "io/ioutil" + "os" "path/filepath" "testing" @@ -33,7 +33,7 @@ func TestValidateOperatorGroup(t *testing.T) { }, } for _, c := range cases { - b, err := ioutil.ReadFile(c.operatorGroupPath) + b, err := os.ReadFile(c.operatorGroupPath) if err != nil { t.Fatalf("Error reading OperatorGroup path %s: %v", c.operatorGroupPath, err) } diff --git a/staging/api/pkg/validation/internal/operatorhub.go b/staging/api/pkg/validation/internal/operatorhub.go index 2f5926cb95..fe0edee3ae 100644 --- a/staging/api/pkg/validation/internal/operatorhub.go +++ b/staging/api/pkg/validation/internal/operatorhub.go @@ -3,9 +3,9 @@ package internal import ( "encoding/json" "fmt" - "io/ioutil" "net/mail" "net/url" + "os" "path/filepath" "strings" @@ -313,7 +313,7 @@ func extractCategories(path string) (map[string]struct{}, error) { return nil, fmt.Errorf("finding category file: %w", err) } - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("reading category file: %w", err) } diff --git a/staging/operator-registry/pkg/image/buildahregistry/_options.go b/staging/operator-registry/pkg/image/buildahregistry/_options.go index 1061dea08a..f6510564fe 100644 --- a/staging/operator-registry/pkg/image/buildahregistry/_options.go +++ b/staging/operator-registry/pkg/image/buildahregistry/_options.go @@ -4,7 +4,6 @@ package buildahregistry import ( - "io/ioutil" "os" "path" "path/filepath" @@ -95,7 +94,7 @@ func NewRegistry(options ...RegistryOption) (registry *Registry, destroy func() } // TODO: probably don't want the signature policy to be here - ioutil.WriteFile(path.Join(config.CacheDir, "policy.json"), []byte(` + os.WriteFile(path.Join(config.CacheDir, "policy.json"), []byte(` { "default": [ { diff --git a/staging/operator-registry/test/e2e/ctx/provisioner_kind.go b/staging/operator-registry/test/e2e/ctx/provisioner_kind.go index c50c69d2d5..23f7883c76 100644 --- a/staging/operator-registry/test/e2e/ctx/provisioner_kind.go +++ b/staging/operator-registry/test/e2e/ctx/provisioner_kind.go @@ -8,7 +8,6 @@ import ( "encoding/csv" "flag" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -69,7 +68,7 @@ func (kl kindLogAdapter) V(log.Level) log.InfoLogger { } func Provision(ctx *TestContext) (func(), error) { - dir, err := ioutil.TempDir("", "kind.") + dir, err := os.MkdirTemp("", "kind.") if err != nil { return nil, fmt.Errorf("failed to create temporary directory: %s", err.Error()) }