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

refactor: move from io/ioutil to io and os package #827

Merged
merged 1 commit into from
Oct 27, 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
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -167,7 +166,7 @@ func initLogging() {
l.Log().SetLevel(logrus.InfoLevel)
}
}
l.Log().SetOutput(ioutil.Discard)
l.Log().SetOutput(io.Discard)
l.Log().AddHook(&writer.Hook{
Writer: os.Stderr,
LogLevels: []logrus.Level{
Expand Down
3 changes: 1 addition & 2 deletions cmd/util/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -58,7 +57,7 @@ func InitViperWithConfigFile(cfgViper *viper.Viper, configFile string) error {
}
defer tmpfile.Close()

originalcontent, err := ioutil.ReadFile(configFile)
originalcontent, err := os.ReadFile(configFile)
if err != nil {
l.Log().Fatalf("error reading config file %s: %v", configFile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/actions/nodehooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/rancher/k3d/v5/pkg/runtimes"
Expand Down Expand Up @@ -59,7 +59,7 @@ func (act RewriteFileAction) Run(ctx context.Context, node *k3d.Node) error {
}
defer reader.Close()

file, err := ioutil.ReadAll(reader)
file, err := io.ReadAll(reader)
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
_ "embed"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -1078,7 +1078,7 @@ func corednsAddHost(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clu
} else {
msg := fmt.Sprintf("(try %d/%d) error patching the CoreDNS ConfigMap to include entry '%s': %+v", i, retries, hostsEntry, err)
if logreader != nil {
readlogs, err := ioutil.ReadAll(logreader)
readlogs, err := io.ReadAll(logreader)
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)
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -147,7 +147,7 @@ func KubeconfigGet(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.C
}
defer reader.Close()

readBytes, err := ioutil.ReadAll(reader)
readBytes, err := io.ReadAll(reader)
if err != nil {
return nil, fmt.Errorf("failed to read kubeconfig file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"strings"
"time"

Expand Down Expand Up @@ -134,7 +134,7 @@ func GetLoadbalancerConfig(ctx context.Context, runtime runtimes.Runtime, cluste
}
defer reader.Close()

file, err := ioutil.ReadAll(reader)
file, err := io.ReadAll(reader)
if err != nil {
return cfg, fmt.Errorf("failed to read loadbalancer config file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"reflect"
"strconv"
Expand Down Expand Up @@ -156,7 +156,7 @@ func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N
defer registryConfigReader.Close()

var err error
registryConfigBytes, err = ioutil.ReadAll(registryConfigReader)
registryConfigBytes, err = io.ReadAll(registryConfigReader)
if err != nil {
l.Log().Warnf("Failed to read registry config from node %s: %+v", node.Name, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/client/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package client

import (
"context"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -178,7 +177,7 @@ func Test_findRuntimeImage(T *testing.T) {

func Test_findImages(t *testing.T) {
// given
tarImage, err := ioutil.TempFile("", "images.tgz")
tarImage, err := os.CreateTemp("", "images.tgz")
if err != nil {
t.Fatal("Failed to create temporary file")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"sigs.k8s.io/yaml"
Expand All @@ -39,7 +39,7 @@ import (
func ValidateSchemaFile(filepath string, schema []byte) error {
l.Log().Debugf("Validating file %s against default JSONSchema...", filepath)

fileContents, err := ioutil.ReadFile(filepath)
fileContents, err := os.ReadFile(filepath)
if err != nil {
return fmt.Errorf("Failed to read file %s: %+v", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package config
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -336,7 +336,7 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
if err != nil {
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 {
return nil, fmt.Errorf("failed to read registry config file at %s: %w", registryConfigFile.Name(), err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/runtimes/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -119,7 +118,7 @@ func pullImage(ctx context.Context, docker *client.Client, image string) error {
l.Log().Infof("Pulling image '%s'", image)

// 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 {
writer = os.Stdout
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/runtimes/docker/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"time"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -331,7 +330,7 @@ func (d Docker) ExecInNode(ctx context.Context, node *k3d.Node, cmd []string) er
}
if err != nil {
if execConnection != nil && execConnection.Reader != nil {
logs, err := ioutil.ReadAll(execConnection.Reader)
logs, err := io.ReadAll(execConnection.Reader)
if err != nil {
return fmt.Errorf("failed to get logs from errored exec process in node '%s': %w", node.Name, err)
}
Expand Down