refactor: move from io/ioutil to io and os package (#827)
This commit is contained in:
parent
f8f17caf78
commit
5e5a35c67c
@ -25,7 +25,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -167,7 +166,7 @@ func initLogging() {
|
|||||||
l.Log().SetLevel(logrus.InfoLevel)
|
l.Log().SetLevel(logrus.InfoLevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l.Log().SetOutput(ioutil.Discard)
|
l.Log().SetOutput(io.Discard)
|
||||||
l.Log().AddHook(&writer.Hook{
|
l.Log().AddHook(&writer.Hook{
|
||||||
Writer: os.Stderr,
|
Writer: os.Stderr,
|
||||||
LogLevels: []logrus.Level{
|
LogLevels: []logrus.Level{
|
||||||
|
@ -23,7 +23,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -58,7 +57,7 @@ func InitViperWithConfigFile(cfgViper *viper.Viper, configFile string) error {
|
|||||||
}
|
}
|
||||||
defer tmpfile.Close()
|
defer tmpfile.Close()
|
||||||
|
|
||||||
originalcontent, err := ioutil.ReadFile(configFile)
|
originalcontent, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log().Fatalf("error reading config file %s: %v", configFile, err)
|
l.Log().Fatalf("error reading config file %s: %v", configFile, err)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/rancher/k3d/v5/pkg/runtimes"
|
"github.com/rancher/k3d/v5/pkg/runtimes"
|
||||||
@ -59,7 +59,7 @@ func (act RewriteFileAction) Run(ctx context.Context, node *k3d.Node) error {
|
|||||||
}
|
}
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
file, err := ioutil.ReadAll(reader)
|
file, err := io.ReadAll(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read file: %w", err)
|
return fmt.Errorf("failed to read file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -1078,7 +1078,7 @@ func corednsAddHost(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clu
|
|||||||
} else {
|
} else {
|
||||||
msg := fmt.Sprintf("(try %d/%d) error patching the CoreDNS ConfigMap to include entry '%s': %+v", i, retries, hostsEntry, err)
|
msg := fmt.Sprintf("(try %d/%d) error patching the CoreDNS ConfigMap to include entry '%s': %+v", i, retries, hostsEntry, err)
|
||||||
if logreader != nil {
|
if logreader != nil {
|
||||||
readlogs, err := ioutil.ReadAll(logreader)
|
readlogs, err := io.ReadAll(logreader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log().Debugf("(try %d/%d) error reading the logs from failed CoreDNS patch exec process in node %s: %v", i, retries, node.Name, err)
|
l.Log().Debugf("(try %d/%d) error reading the logs from failed CoreDNS patch exec process in node %s: %v", i, retries, node.Name, err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@ -147,7 +147,7 @@ func KubeconfigGet(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.C
|
|||||||
}
|
}
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
readBytes, err := ioutil.ReadAll(reader)
|
readBytes, err := io.ReadAll(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read kubeconfig file: %w", err)
|
return nil, fmt.Errorf("failed to read kubeconfig file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ func GetLoadbalancerConfig(ctx context.Context, runtime runtimes.Runtime, cluste
|
|||||||
}
|
}
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
file, err := ioutil.ReadAll(reader)
|
file, err := io.ReadAll(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, fmt.Errorf("failed to read loadbalancer config file: %w", err)
|
return cfg, fmt.Errorf("failed to read loadbalancer config file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -156,7 +156,7 @@ func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N
|
|||||||
defer registryConfigReader.Close()
|
defer registryConfigReader.Close()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
registryConfigBytes, err = ioutil.ReadAll(registryConfigReader)
|
registryConfigBytes, err = io.ReadAll(registryConfigReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Log().Warnf("Failed to read registry config from node %s: %+v", node.Name, err)
|
l.Log().Warnf("Failed to read registry config from node %s: %+v", node.Name, err)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -178,7 +177,7 @@ func Test_findRuntimeImage(T *testing.T) {
|
|||||||
|
|
||||||
func Test_findImages(t *testing.T) {
|
func Test_findImages(t *testing.T) {
|
||||||
// given
|
// given
|
||||||
tarImage, err := ioutil.TempFile("", "images.tgz")
|
tarImage, err := os.CreateTemp("", "images.tgz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Failed to create temporary file")
|
t.Fatal("Failed to create temporary file")
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
@ -39,7 +39,7 @@ import (
|
|||||||
func ValidateSchemaFile(filepath string, schema []byte) error {
|
func ValidateSchemaFile(filepath string, schema []byte) error {
|
||||||
l.Log().Debugf("Validating file %s against default JSONSchema...", filepath)
|
l.Log().Debugf("Validating file %s against default JSONSchema...", filepath)
|
||||||
|
|
||||||
fileContents, err := ioutil.ReadFile(filepath)
|
fileContents, err := os.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to read file %s: %+v", filepath, err)
|
return fmt.Errorf("Failed to read file %s: %+v", filepath, err)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open registry config file at %s: %w", simpleConfig.Registries.Config, err)
|
return nil, fmt.Errorf("failed to open registry config file at %s: %w", simpleConfig.Registries.Config, err)
|
||||||
}
|
}
|
||||||
configBytes, err := ioutil.ReadAll(registryConfigFile)
|
configBytes, err := io.ReadAll(registryConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read registry config file at %s: %w", registryConfigFile.Name(), err)
|
return nil, fmt.Errorf("failed to read registry config file at %s: %w", registryConfigFile.Name(), err)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
@ -119,7 +118,7 @@ func pullImage(ctx context.Context, docker *client.Client, image string) error {
|
|||||||
l.Log().Infof("Pulling image '%s'", image)
|
l.Log().Infof("Pulling image '%s'", image)
|
||||||
|
|
||||||
// in debug mode (--verbose flag set), output pull progress
|
// in debug mode (--verbose flag set), output pull progress
|
||||||
var writer io.Writer = ioutil.Discard
|
var writer io.Writer = io.Discard
|
||||||
if l.Log().GetLevel() == logrus.DebugLevel {
|
if l.Log().GetLevel() == logrus.DebugLevel {
|
||||||
writer = os.Stdout
|
writer = os.Stdout
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
@ -331,7 +330,7 @@ func (d Docker) ExecInNode(ctx context.Context, node *k3d.Node, cmd []string) er
|
|||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if execConnection != nil && execConnection.Reader != nil {
|
if execConnection != nil && execConnection.Reader != nil {
|
||||||
logs, err := ioutil.ReadAll(execConnection.Reader)
|
logs, err := io.ReadAll(execConnection.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get logs from errored exec process in node '%s': %w", node.Name, err)
|
return fmt.Errorf("failed to get logs from errored exec process in node '%s': %w", node.Name, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user