remove ioutil usage in all project
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
1aa87538a7
commit
303ef9cd80
|
|
@ -3,7 +3,6 @@ package app
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
@ -87,7 +86,7 @@ func New(conf ConfigProvider) *App {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(app *App) *App {
|
func Init(app *App) *App {
|
||||||
app.readFile = ioutil.ReadFile
|
app.readFile = os.ReadFile
|
||||||
app.deleteFile = os.Remove
|
app.deleteFile = os.Remove
|
||||||
app.glob = filepath.Glob
|
app.glob = filepath.Glob
|
||||||
app.abs = filepath.Abs
|
app.abs = filepath.Abs
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -52,7 +51,7 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
|
||||||
// Create tmp directory and bail immediately if it fails
|
// Create tmp directory and bail immediately if it fails
|
||||||
var dir string
|
var dir string
|
||||||
if len(opts.OutputDir) == 0 {
|
if len(opts.OutputDir) == 0 {
|
||||||
tempDir, err := ioutil.TempDir("", "helmfile*")
|
tempDir, err := os.MkdirTemp("", "helmfile*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -24,7 +23,7 @@ func assertEqualsToSnapshot(t *testing.T, name string, data string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wantData, err := ioutil.ReadFile(snapshotFileName)
|
wantData, err := os.ReadFile(snapshotFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
"Snapshot file %q does not exist. Rerun this test with `HELMFILE_UPDATE_SNAPSHOT=1 go test -v -run %s %s` to create the snapshot",
|
"Snapshot file %q does not exist. Rerun this test with `HELMFILE_UPDATE_SNAPSHOT=1 go test -v -run %s %s` to create the snapshot",
|
||||||
|
|
@ -53,7 +52,7 @@ func update(t *testing.T, snapshotFileName string, data []byte) {
|
||||||
t.Fatalf("%v", err)
|
t.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(snapshotFileName, data, 0644); err != nil {
|
if err := os.WriteFile(snapshotFileName, data, 0644); err != nil {
|
||||||
t.Fatalf("%v", err)
|
t.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -293,7 +292,7 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
||||||
decFilename = absPath + decSuffix
|
decFilename = absPath + decSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
secretBytes, err := ioutil.ReadFile(decFilename)
|
secretBytes, err := os.ReadFile(decFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
secret.err = err
|
secret.err = err
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -323,7 +322,7 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
||||||
tempFile = func(content []byte) (string, error) {
|
tempFile = func(content []byte) (string, error) {
|
||||||
dir := filepath.Dir(name)
|
dir := filepath.Dir(name)
|
||||||
extension := filepath.Ext(name)
|
extension := filepath.Ext(name)
|
||||||
tmpFile, err := ioutil.TempFile(dir, "secret*"+extension)
|
tmpFile, err := os.CreateTemp(dir, "secret*"+extension)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -442,7 +441,7 @@ func (helm *execer) ChartPull(chart string, flags ...string) error {
|
||||||
ociChartURLSplit := strings.Split(chart, ":")
|
ociChartURLSplit := strings.Split(chart, ":")
|
||||||
ociChartURL := fmt.Sprintf("oci://%s", ociChartURLSplit[0])
|
ociChartURL := fmt.Sprintf("oci://%s", ociChartURLSplit[0])
|
||||||
ociChartTag := ociChartURLSplit[1]
|
ociChartTag := ociChartURLSplit[1]
|
||||||
tempDir, err := ioutil.TempDir("", "chart*")
|
tempDir, err := os.MkdirTemp("", "chart*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ type Remote struct {
|
||||||
Getter Getter
|
Getter Getter
|
||||||
|
|
||||||
// ReadFile is the implementation of the file reader that reads a local file from the specified path.
|
// ReadFile is the implementation of the file reader that reads a local file from the specified path.
|
||||||
// Inject any implementation of your choice, like an im-memory impl for testing, ioutil.ReadFile for the real-world use.
|
// Inject any implementation of your choice, like an im-memory impl for testing, os.ReadFile for the real-world use.
|
||||||
ReadFile func(string) ([]byte, error)
|
ReadFile func(string) ([]byte, error)
|
||||||
DirExists func(string) bool
|
DirExists func(string) bool
|
||||||
FileExists func(string) bool
|
FileExists func(string) bool
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -273,8 +272,8 @@ type chartDependencyManager struct {
|
||||||
func NewChartDependencyManager(name string, logger *zap.SugaredLogger) *chartDependencyManager {
|
func NewChartDependencyManager(name string, logger *zap.SugaredLogger) *chartDependencyManager {
|
||||||
return &chartDependencyManager{
|
return &chartDependencyManager{
|
||||||
Name: name,
|
Name: name,
|
||||||
readFile: ioutil.ReadFile,
|
readFile: os.ReadFile,
|
||||||
writeFile: ioutil.WriteFile,
|
writeFile: os.WriteFile,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -20,7 +19,7 @@ import (
|
||||||
func createFromYaml(content []byte, file string, env string, logger *zap.SugaredLogger) (*HelmState, error) {
|
func createFromYaml(content []byte, file string, env string, logger *zap.SugaredLogger) (*HelmState, error) {
|
||||||
c := &StateCreator{
|
c := &StateCreator{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
readFile: ioutil.ReadFile,
|
readFile: os.ReadFile,
|
||||||
abs: filepath.Abs,
|
abs: filepath.Abs,
|
||||||
|
|
||||||
DeleteFile: os.Remove,
|
DeleteFile: os.Remove,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ func newLoader() *EnvironmentValuesLoader {
|
||||||
readFile := func(s string) ([]byte, error) { return []byte{}, nil }
|
readFile := func(s string) ([]byte, error) { return []byte{}, nil }
|
||||||
dirExists := func(d string) bool { return false }
|
dirExists := func(d string) bool { return false }
|
||||||
fileExists := func(f string) bool { return false }
|
fileExists := func(f string) bool { return false }
|
||||||
return NewEnvironmentValuesLoader(storage, ioutil.ReadFile, sugar, remote.NewRemote(sugar, "/tmp", readFile, dirExists, fileExists))
|
return NewEnvironmentValuesLoader(storage, os.ReadFile, sugar, remote.NewRemote(sugar, "/tmp", readFile, dirExists, fileExists))
|
||||||
}
|
}
|
||||||
|
|
||||||
// See https://github.com/roboll/helmfile/pull/1169
|
// See https://github.com/roboll/helmfile/pull/1169
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -1499,7 +1498,7 @@ func (st *HelmState) WriteReleasesValues(helm helmexec.Interface, additionalValu
|
||||||
return []error{err}
|
return []error{err}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(outputValuesFile, buf.Bytes(), 0644); err != nil {
|
if err := os.WriteFile(outputValuesFile, buf.Bytes(), 0644); err != nil {
|
||||||
return []error{fmt.Errorf("writing values file %s: %w", outputValuesFile, err)}
|
return []error{fmt.Errorf("writing values file %s: %w", outputValuesFile, err)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2285,7 +2284,7 @@ func (st *HelmState) UpdateDeps(helm helmexec.Interface, includeTransitiveNeeds
|
||||||
if len(errs) == 0 {
|
if len(errs) == 0 {
|
||||||
tempDir := st.tempDir
|
tempDir := st.tempDir
|
||||||
if tempDir == nil {
|
if tempDir == nil {
|
||||||
tempDir = ioutil.TempDir
|
tempDir = os.MkdirTemp
|
||||||
}
|
}
|
||||||
_, err := st.updateDependenciesInTempDir(helm, tempDir)
|
_, err := st.updateDependenciesInTempDir(helm, tempDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -2785,7 +2784,7 @@ func (st *HelmState) generateSecretValuesFiles(helm helmexec.Interface, release
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err := ioutil.TempFile(os.TempDir(), "helmfile-embdedded-secrets-*.yaml.enc")
|
path, err := os.CreateTemp(os.TempDir(), "helmfile-embdedded-secrets-*.yaml.enc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -2794,7 +2793,7 @@ func (st *HelmState) generateSecretValuesFiles(helm helmexec.Interface, release
|
||||||
_ = os.Remove(path.Name())
|
_ = os.Remove(path.Name())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := ioutil.WriteFile(path.Name(), bs, 0644); err != nil {
|
if err := os.WriteFile(path.Name(), bs, 0644); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -31,7 +30,7 @@ func TestGoGetter(t *testing.T) {
|
||||||
for i, tc := range testcases {
|
for i, tc := range testcases {
|
||||||
test := tc
|
test := tc
|
||||||
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
||||||
d, err := ioutil.TempDir("", "testgogetter")
|
d, err := os.MkdirTemp("", "testgogetter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +38,7 @@ func TestGoGetter(t *testing.T) {
|
||||||
|
|
||||||
st := &HelmState{
|
st := &HelmState{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
readFile: ioutil.ReadFile,
|
readFile: os.ReadFile,
|
||||||
basePath: d,
|
basePath: d,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -1798,7 +1797,7 @@ func TestHelmState_UpdateDeps(t *testing.T) {
|
||||||
var generatedDir string
|
var generatedDir string
|
||||||
tempDir := func(dir, prefix string) (string, error) {
|
tempDir := func(dir, prefix string) (string, error) {
|
||||||
var err error
|
var err error
|
||||||
generatedDir, err = ioutil.TempDir(dir, prefix)
|
generatedDir, err = os.MkdirTemp(dir, prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -1815,7 +1814,7 @@ generated: 2019-05-16T15:42:45.50486+09:00
|
||||||
`)
|
`)
|
||||||
filename := filepath.Join(generatedDir, "requirements.lock")
|
filename := filepath.Join(generatedDir, "requirements.lock")
|
||||||
logger.Debugf("test: writing %s: %s", filename, content)
|
logger.Debugf("test: writing %s: %s", filename, content)
|
||||||
return ioutil.WriteFile(filename, content, 0644)
|
return os.WriteFile(filename, content, 0644)
|
||||||
}
|
}
|
||||||
return generatedDir, nil
|
return generatedDir, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -34,7 +33,7 @@ func tempValuesFilePath(release *ReleaseSpec, data interface{}) (*string, error)
|
||||||
|
|
||||||
workDir := os.Getenv("HELMFILE_TEMPDIR")
|
workDir := os.Getenv("HELMFILE_TEMPDIR")
|
||||||
if workDir == "" {
|
if workDir == "" {
|
||||||
workDir, err = ioutil.TempDir(os.TempDir(), "helmfile")
|
workDir, err = os.MkdirTemp(os.TempDir(), "helmfile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package tmpl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -27,11 +27,11 @@ func NewFileRenderer(readFile func(filename string) ([]byte, error), basePath st
|
||||||
|
|
||||||
func NewFirstPassRenderer(basePath string, data interface{}) *FileRenderer {
|
func NewFirstPassRenderer(basePath string, data interface{}) *FileRenderer {
|
||||||
return &FileRenderer{
|
return &FileRenderer{
|
||||||
ReadFile: ioutil.ReadFile,
|
ReadFile: os.ReadFile,
|
||||||
Context: &Context{
|
Context: &Context{
|
||||||
preRender: true,
|
preRender: true,
|
||||||
basePath: basePath,
|
basePath: basePath,
|
||||||
readFile: ioutil.ReadFile,
|
readFile: os.ReadFile,
|
||||||
},
|
},
|
||||||
Data: data,
|
Data: data,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -79,9 +79,9 @@ func unmarshal(filename string) (interface{}, error) {
|
||||||
var contents []byte
|
var contents []byte
|
||||||
var err error
|
var err error
|
||||||
if filename == "-" {
|
if filename == "-" {
|
||||||
contents, err = ioutil.ReadAll(os.Stdin)
|
contents, err = io.ReadAll(os.Stdin)
|
||||||
} else {
|
} else {
|
||||||
contents, err = ioutil.ReadFile(filename)
|
contents, err = os.ReadFile(filename)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue