diff --git a/cmd/flux/bootstrap.go b/cmd/flux/bootstrap.go index 1c1dc1c259ae5392e468f8f1e2c8e7d7115238c5..9d7d3161a62d4a30e9af54de082892aff50a55e5 100644 --- a/cmd/flux/bootstrap.go +++ b/cmd/flux/bootstrap.go @@ -19,7 +19,7 @@ package main import ( "crypto/elliptic" "fmt" - "io/ioutil" + "os" "github.com/spf13/cobra" @@ -145,7 +145,7 @@ func buildEmbeddedManifestBase() (string, error) { if !isEmbeddedVersion(bootstrapArgs.version) { return "", nil } - tmpBaseDir, err := ioutil.TempDir("", "flux-manifests-") + tmpBaseDir, err := os.MkdirTemp("", "flux-manifests-") if err != nil { return "", err } diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index 92485f34374d7b711c33efdb6ce1f0fe828cf794..1a583a2a4e432264a92ed657b430caea8dc40f6b 100644 --- a/cmd/flux/bootstrap_git.go +++ b/cmd/flux/bootstrap_git.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "io/ioutil" "net/url" "os" "strings" @@ -118,7 +117,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { defer os.RemoveAll(manifestsBase) // Lazy go-git repository - tmpDir, err := ioutil.TempDir("", "flux-bootstrap-") + tmpDir, err := os.MkdirTemp("", "flux-bootstrap-") if err != nil { return fmt.Errorf("failed to create temporary working dir: %w", err) } diff --git a/cmd/flux/bootstrap_github.go b/cmd/flux/bootstrap_github.go index d5e5a7a2150af669f5cddc50abac42443f344559..88a89d52c70f79ed4329cdf4bd7d93395d868c21 100644 --- a/cmd/flux/bootstrap_github.go +++ b/cmd/flux/bootstrap_github.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "io/ioutil" "os" "time" @@ -146,7 +145,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { } // Lazy go-git repository - tmpDir, err := ioutil.TempDir("", "flux-bootstrap-") + tmpDir, err := os.MkdirTemp("", "flux-bootstrap-") if err != nil { return fmt.Errorf("failed to create temporary working dir: %w", err) } diff --git a/cmd/flux/bootstrap_gitlab.go b/cmd/flux/bootstrap_gitlab.go index 02a7f4ec34a3086de2addf1a481c20cd501ded68..09bde7f3ebe3f0a8991d15e0d793b3f45a946a73 100644 --- a/cmd/flux/bootstrap_gitlab.go +++ b/cmd/flux/bootstrap_gitlab.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "io/ioutil" "os" "regexp" "strings" @@ -159,7 +158,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { } // Lazy go-git repository - tmpDir, err := ioutil.TempDir("", "flux-bootstrap-") + tmpDir, err := os.MkdirTemp("", "flux-bootstrap-") if err != nil { return fmt.Errorf("failed to create temporary working dir: %w", err) } diff --git a/cmd/flux/create_helmrelease.go b/cmd/flux/create_helmrelease.go index fae63bd3246cadfc526e84020f42e3c59fc0ba37..f337369654602f68b59ef3dae129497e4fcd87da 100644 --- a/cmd/flux/create_helmrelease.go +++ b/cmd/flux/create_helmrelease.go @@ -20,7 +20,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "os" "github.com/fluxcd/flux2/internal/flags" "github.com/fluxcd/flux2/internal/utils" @@ -201,7 +201,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error { if len(helmReleaseArgs.valuesFiles) > 0 { valuesMap := make(map[string]interface{}) for _, v := range helmReleaseArgs.valuesFiles { - data, err := ioutil.ReadFile(v) + data, err := os.ReadFile(v) if err != nil { return fmt.Errorf("reading values from %s failed: %w", v, err) } diff --git a/cmd/flux/create_source_bucket.go b/cmd/flux/create_source_bucket.go index d0b67d431c3d3bb1c66f12fa0f112bfc88d9fb55..ea5f3e28cbb04d4adb17c0e446fdf86784542d8d 100644 --- a/cmd/flux/create_source_bucket.go +++ b/cmd/flux/create_source_bucket.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "io/ioutil" "os" "github.com/spf13/cobra" @@ -112,7 +111,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error { return err } - tmpDir, err := ioutil.TempDir("", name) + tmpDir, err := os.MkdirTemp("", name) if err != nil { return err } diff --git a/cmd/flux/create_source_git.go b/cmd/flux/create_source_git.go index e434a1e04bbf13239df1bbf673fb215179815b50..65790c0f38f5337867ae44923a54e50926531b84 100644 --- a/cmd/flux/create_source_git.go +++ b/cmd/flux/create_source_git.go @@ -20,7 +20,6 @@ import ( "context" "crypto/elliptic" "fmt" - "io/ioutil" "net/url" "os" @@ -178,7 +177,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("recurse submodules requires --git-implementation=%s", sourcev1.GoGitImplementation) } - tmpDir, err := ioutil.TempDir("", name) + tmpDir, err := os.MkdirTemp("", name) if err != nil { return err } diff --git a/cmd/flux/create_source_helm.go b/cmd/flux/create_source_helm.go index 27d48d3ccd89e127bbc8bc3f0e06e8acdd29416e..b2d0b01fb1a2ccee549d1a819b3fb88db6dd2a1d 100644 --- a/cmd/flux/create_source_helm.go +++ b/cmd/flux/create_source_helm.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "io/ioutil" "net/url" "os" @@ -106,7 +105,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error { return err } - tmpDir, err := ioutil.TempDir("", name) + tmpDir, err := os.MkdirTemp("", name) if err != nil { return err } diff --git a/cmd/flux/install.go b/cmd/flux/install.go index ed2d3cf17cc4e45672adb73c5a1403829f35dffe..436189b87310deccb5d500c64c80840917c0a930 100644 --- a/cmd/flux/install.go +++ b/cmd/flux/install.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -132,7 +131,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error { logger.Generatef("generating manifests") } - tmpDir, err := ioutil.TempDir("", rootArgs.namespace) + tmpDir, err := os.MkdirTemp("", rootArgs.namespace) if err != nil { return err } diff --git a/internal/bootstrap/bootstrap_plain_git.go b/internal/bootstrap/bootstrap_plain_git.go index c932375d488f41144aba5488dcb44705b190fa2a..e0018b8907b71db343743e199bce024bc3f766c6 100644 --- a/internal/bootstrap/bootstrap_plain_git.go +++ b/internal/bootstrap/bootstrap_plain_git.go @@ -19,7 +19,6 @@ package bootstrap import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -160,7 +159,7 @@ func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifest // Apply components using any existing customisations kfile := filepath.Join(filepath.Dir(componentsYAML), konfig.DefaultKustomizationFileName()) if _, err := os.Stat(kfile); err == nil { - tmpDir, err := ioutil.TempDir("", "gotk-crds") + tmpDir, err := os.MkdirTemp("", "gotk-crds") defer os.RemoveAll(tmpDir) // Extract the CRDs from the components manifest diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 2299562a5f38b43ad4297279174f231a8937398e..50b903fa06e4c78a40515d315292cbd3a3401db5 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -21,7 +21,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -304,7 +303,7 @@ func CompatibleVersion(binary, target string) bool { } func ExtractCRDs(inManifestPath, outManifestPath string) error { - manifests, err := ioutil.ReadFile(inManifestPath) + manifests, err := os.ReadFile(inManifestPath) if err != nil { return err } @@ -338,5 +337,5 @@ func ExtractCRDs(inManifestPath, outManifestPath string) error { return fmt.Errorf("no CRDs found in %s", inManifestPath) } - return ioutil.WriteFile(outManifestPath, []byte(crds), os.ModePerm) + return os.WriteFile(outManifestPath, []byte(crds), os.ModePerm) } diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index f316e8cde1567a038321bfab4469f035aef20c8d..59ec97ae87d80fc4a288e8eab12336f56835d793 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -17,7 +17,6 @@ limitations under the License. package utils import ( - "io/ioutil" "os" "path/filepath" "reflect" @@ -134,7 +133,7 @@ func TestExtractCRDs(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Create temporary directory to write the result in. - dir, err := ioutil.TempDir("", "flux-TestExtractCRDs") + dir, err := os.MkdirTemp("", "flux-TestExtractCRDs") if err != nil { t.Fatalf("failed to create temporary directory: %v", err) } diff --git a/pkg/manifestgen/install/install.go b/pkg/manifestgen/install/install.go index e1b8403773cdbe9869da8c6e4f2c9f62770c4e60..373b19e48e757754387ae6392fd4288c7eb4af9e 100644 --- a/pkg/manifestgen/install/install.go +++ b/pkg/manifestgen/install/install.go @@ -20,7 +20,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "net/http" "os" "path" @@ -55,7 +54,7 @@ func Generate(options Options, manifestsBase string) (*manifestgen.Manifest, err } else { // download the manifests base from GitHub if manifestsBase == "" { - manifestsBase, err = ioutil.TempDir("", options.Namespace) + manifestsBase, err = os.MkdirTemp("", options.Namespace) if err != nil { return nil, fmt.Errorf("temp dir error: %w", err) } @@ -78,7 +77,7 @@ func Generate(options Options, manifestsBase string) (*manifestgen.Manifest, err } } - content, err := ioutil.ReadFile(output) + content, err := os.ReadFile(output) if err != nil { return nil, err } diff --git a/pkg/manifestgen/install/manifests.go b/pkg/manifestgen/install/manifests.go index c1e2c62d9201693b773f339a90ba43aea35178ea..a864d8c9b134158bed1521e82fafaf37a0219a40 100644 --- a/pkg/manifestgen/install/manifests.go +++ b/pkg/manifestgen/install/manifests.go @@ -20,7 +20,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "net/http" "os" "path" @@ -103,12 +102,12 @@ func generate(base string, options Options) error { // workaround for kustomize not being able to patch the SA in ClusterRoleBindings defaultNS := MakeDefaultOptions().Namespace if defaultNS != options.Namespace { - rbac, err := ioutil.ReadFile(rbacFile) + rbac, err := os.ReadFile(rbacFile) if err != nil { return fmt.Errorf("reading rbac file failed: %w", err) } rbac = bytes.ReplaceAll(rbac, []byte(defaultNS), []byte(options.Namespace)) - if err := ioutil.WriteFile(rbacFile, rbac, os.ModePerm); err != nil { + if err := os.WriteFile(rbacFile, rbac, os.ModePerm); err != nil { return fmt.Errorf("replacing service account namespace in rbac failed: %w", err) } } diff --git a/pkg/manifestgen/kustomization/kustomization.go b/pkg/manifestgen/kustomization/kustomization.go index 79506c06170b99980f6423101975312906a163c6..bdce9fb237f986967409b1ffa238439c872013e6 100644 --- a/pkg/manifestgen/kustomization/kustomization.go +++ b/pkg/manifestgen/kustomization/kustomization.go @@ -17,7 +17,6 @@ limitations under the License. package kustomization import ( - "io/ioutil" "os" "path/filepath" @@ -113,7 +112,7 @@ func Generate(options Options) (*manifestgen.Manifest, error) { }, nil } - kd, err := ioutil.ReadFile(abskfile) + kd, err := os.ReadFile(abskfile) if err != nil { return nil, err } diff --git a/pkg/manifestgen/manifest.go b/pkg/manifestgen/manifest.go index 114c10a3e965a1dac6321b6b86001f81458c9e7b..9509e0b1e251adf0dc639719608b1696fcb30123 100644 --- a/pkg/manifestgen/manifest.go +++ b/pkg/manifestgen/manifest.go @@ -18,7 +18,6 @@ package manifestgen import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -46,7 +45,7 @@ func (m *Manifest) WriteFile(rootDir string) (string, error) { return "", fmt.Errorf("unable to create dir, error: %w", err) } - if err := ioutil.WriteFile(output, []byte(m.Content), os.ModePerm); err != nil { + if err := os.WriteFile(output, []byte(m.Content), os.ModePerm); err != nil { return "", fmt.Errorf("unable to write file, error: %w", err) } return output, nil diff --git a/pkg/manifestgen/sourcesecret/sourcesecret.go b/pkg/manifestgen/sourcesecret/sourcesecret.go index 8d7fb865ce8dd6345f74020492b8bb1907176ef8..91effffd1440a9a31a6387def2fde6556bdcaa1f 100644 --- a/pkg/manifestgen/sourcesecret/sourcesecret.go +++ b/pkg/manifestgen/sourcesecret/sourcesecret.go @@ -19,8 +19,8 @@ package sourcesecret import ( "bytes" "fmt" - "io/ioutil" "net" + "os" "path" "time" @@ -62,17 +62,17 @@ func Generate(options Options) (*manifestgen.Manifest, error) { var caFile []byte if options.CAFilePath != "" { - if caFile, err = ioutil.ReadFile(options.CAFilePath); err != nil { + if caFile, err = os.ReadFile(options.CAFilePath); err != nil { return nil, fmt.Errorf("failed to read CA file: %w", err) } } var certFile, keyFile []byte if options.CertFilePath != "" && options.KeyFilePath != "" { - if certFile, err = ioutil.ReadFile(options.CertFilePath); err != nil { + if certFile, err = os.ReadFile(options.CertFilePath); err != nil { return nil, fmt.Errorf("failed to read cert file: %w", err) } - if keyFile, err = ioutil.ReadFile(options.KeyFilePath); err != nil { + if keyFile, err = os.ReadFile(options.KeyFilePath); err != nil { return nil, fmt.Errorf("failed to read key file: %w", err) } } @@ -129,7 +129,7 @@ func buildSecret(keypair *ssh.KeyPair, hostKey, caFile, certFile, keyFile []byte } func loadKeyPair(path string, password string) (*ssh.KeyPair, error) { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to open private key file: %w", err) } diff --git a/pkg/manifestgen/sourcesecret/sourcesecret_test.go b/pkg/manifestgen/sourcesecret/sourcesecret_test.go index 618b86cfdac0f725c1bcacb9d97a77a41b7aacde..24ab8057925b3ec29ed1f232d5375811282ac290 100644 --- a/pkg/manifestgen/sourcesecret/sourcesecret_test.go +++ b/pkg/manifestgen/sourcesecret/sourcesecret_test.go @@ -17,7 +17,6 @@ limitations under the License. package sourcesecret import ( - "io/ioutil" "os" "reflect" "testing" @@ -43,8 +42,8 @@ func Test_passwordLoadKeyPair(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - pk, _ := ioutil.ReadFile(tt.privateKeyPath) - ppk, _ := ioutil.ReadFile(tt.publicKeyPath) + pk, _ := os.ReadFile(tt.privateKeyPath) + ppk, _ := os.ReadFile(tt.publicKeyPath) got, err := loadKeyPair(tt.privateKeyPath, tt.password) if err != nil { @@ -65,7 +64,7 @@ func Test_passwordLoadKeyPair(t *testing.T) { func Test_PasswordlessLoadKeyPair(t *testing.T) { for algo, privateKey := range testdata.PEMBytes { t.Run(algo, func(t *testing.T) { - f, err := ioutil.TempFile("", "test-private-key-") + f, err := os.CreateTemp("", "test-private-key-") if err != nil { t.Fatalf("unable to create temporary file. err: %s", err) } @@ -81,7 +80,7 @@ func Test_PasswordlessLoadKeyPair(t *testing.T) { return } - pk, _ := ioutil.ReadFile(f.Name()) + pk, _ := os.ReadFile(f.Name()) if !reflect.DeepEqual(got.PrivateKey, pk) { t.Errorf("PrivateKey %s != %s", got.PrivateKey, string(privateKey)) }