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

chore: remove deprecated io/ioutil #1668

Merged
merged 1 commit into from
Jul 30, 2021
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
4 changes: 2 additions & 2 deletions cmd/flux/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package main
import (
"crypto/elliptic"
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/bootstrap_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/bootstrap_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"time"

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/bootstrap_gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/create_helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/fluxcd/flux2/internal/flags"
"github.com/fluxcd/flux2/internal/utils"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/create_source_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/create_source_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto/elliptic"
"fmt"
"io/ioutil"
"net/url"
"os"

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/create_source_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions internal/bootstrap/bootstrap_plain_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package bootstrap
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package utils

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/manifestgen/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/manifestgen/install/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -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)
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/manifestgen/kustomization/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package kustomization

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

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/manifestgen/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package manifestgen

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

Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/manifestgen/sourcesecret/sourcesecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package sourcesecret
import (
"bytes"
"fmt"
"io/ioutil"
"net"
"os"
"path"
"time"

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/manifestgen/sourcesecret/sourcesecret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package sourcesecret

import (
"io/ioutil"
"os"
"reflect"
"testing"
Expand All @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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))
}
Expand Down