Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

chore: remove refs to deprecated io/ioutil #1097

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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 pkg/apis/pmemcsi/v1beta1/deployment_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ SPDX-License-Identifier: Apache-2.0
package v1beta1_test

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

Expand Down Expand Up @@ -135,7 +134,7 @@ spec:
It("should have valid json schema", func() {

crdFile := os.Getenv("REPO_ROOT") + "/deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml"
data, err := ioutil.ReadFile(crdFile)
data, err := os.ReadFile(crdFile)
Expect(err).ShouldNot(HaveOccurred(), "load crd data")
crd := &apiextensions.CustomResourceDefinition{}

Expand Down
3 changes: 1 addition & 2 deletions pkg/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package coverage

import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"syscall"
Expand All @@ -32,7 +31,7 @@ func Run(main func() int) {
if err != nil {
klog.Fatalf("cover profile %q: %s", *coverage, err)
}
f, err := ioutil.TempFile(filepath.Dir(abspath), filepath.Base(abspath))
f, err := os.CreateTemp(filepath.Dir(abspath), filepath.Base(abspath))
if err != nil {
klog.Fatalf("temporary cover profile %q: %s", abspath, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/imagefile/imagefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -258,7 +257,7 @@ func Create(filename string, size Bytes, fs FsType) error {

// We write MBRs and rootfs into temporary files, then copy into the
// final image file at the end.
tmp, err := ioutil.TempDir("", "pmem-csi-imagefile")
tmp, err := os.MkdirTemp("", "pmem-csi-imagefile")
if err != nil {
return fmt.Errorf("temp dir: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/imagefile/imagefile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"syscall"
Expand Down Expand Up @@ -99,7 +98,7 @@ func rmTmpfile(file *os.File) {
}

func TestExtents(t *testing.T) {
file, err := ioutil.TempFile("", "extents")
file, err := os.CreateTemp("", "extents")
if err != nil {
t.Fatalf("create temp file: %v", err)
}
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestExtents(t *testing.T) {

// Now create a sparse copy. This should be almost
// instantaneous, despite the nominally large file.
copy, err := ioutil.TempFile(".", "copy")
copy, err := os.CreateTemp(".", "copy")
if err != nil {
t.Fatalf("create temp file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/imagefile/test/imagefiletest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -77,7 +76,7 @@ func testImageFile(t TInterface, fs imagefile.FsType, size imagefile.Bytes, expe
t.Skipf("parted not found: %v", err)
}

file, err := ioutil.TempFile("", "image")
file, err := os.CreateTemp("", "image")
if err != nil {
t.Fatalf("create temp file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/k8sutil/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package k8sutil

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

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -29,7 +28,7 @@ func GetNamespace(ctx context.Context) string {
if ns == "" {
// If environment variable not set, give it a try to fetch it from
// mounted filesystem by Kubernetes
data, err := ioutil.ReadFile(namespaceFile)
data, err := os.ReadFile(namespaceFile)
if err != nil {
logger.Info("Could not read namespace from secret, using fallback "+defaultOperatorNamespace,
"error", err,
Expand Down
3 changes: 1 addition & 2 deletions pkg/pmem-state/pmem-state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package pmemstate
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (fs *fileState) Get(id string, dataPtr interface{}) error {
// GetAll retrieves the names of all .json files found in fileState.location directory
func (fs *fileState) GetAll() ([]string, error) {
fs.stateDirLock.Lock()
files, err := ioutil.ReadDir(fs.location)
files, err := os.ReadDir(fs.location)
fs.stateDirLock.Unlock()
if err != nil {
return nil, fmt.Errorf("failed to read metadata from %q: %w", fs.location, err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/pmem-state/pmem-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package pmemstate_test

import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -59,7 +58,7 @@ var _ = Describe("pmem state", func() {

BeforeEach(func() {
var err error
stateDir, err = ioutil.TempDir("", "pmemstate-")
stateDir, err = os.MkdirTemp("", "pmemstate-")
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -88,7 +87,7 @@ var _ = Describe("pmem state", func() {
_, err = pmemstate.NewFileState("/unknown/base/directory/")
Expect(err).To(HaveOccurred())

file, err := ioutil.TempFile("", "pmemstate-file")
file, err := os.CreateTemp("", "pmemstate-file")
Expect(err).NotTo(HaveOccurred())
_, err = pmemstate.NewFileState(file.Name())
os.Remove(file.Name()) //nolint: errcheck
Expand Down
3 changes: 1 addition & 2 deletions pkg/volumepathhandler/volume_path_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package volumepathhandler
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -294,7 +293,7 @@ func (v VolumePathHandler) IsDeviceBindMountExist(ctx context.Context, mapPath s
func (v VolumePathHandler) GetDeviceBindMountRefs(ctx context.Context, devPath string, mapPath string) ([]string, error) {
ctx, logger := pmemlog.WithName(ctx, "GetDeviceBindMountRefs")
var refs []string
files, err := ioutil.ReadDir(mapPath)
files, err := os.ReadDir(mapPath)
if err != nil {
return nil, fmt.Errorf("directory cannot read %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"bufio"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -138,7 +138,7 @@ func GetMetrics(ctx context.Context, c *Cluster, url string) (map[string]*cm.Met
return nil, fmt.Errorf("get controller metrics: %v", err)
}
if resp.StatusCode != 200 {
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
suffix := ""
if len(body) > 0 {
suffix = "\n" + string(body)
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/filesource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package e2e

import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -40,7 +39,7 @@ func (r RootFileSource) ReadTestFile(filePath string) ([]byte, error) {
} else {
fullPath = filepath.Join(r.Root, filePath)
}
data, err := ioutil.ReadFile(fullPath)
data, err := os.ReadFile(fullPath)
if os.IsNotExist(err) {
// Not an error (yet), some other provider may have the file.
return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package gotests
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -90,7 +90,7 @@ var _ = deploy.Describe("direct-testing", "direct-testing-metrics", "", func(d *
if err != nil {
return
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
framework.ExpectNoError(err, "read GET response for pod %s and url %s", pod, url)
name := pod.Name + "/" + container.Name
if isPmemCSI {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/pod/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"regexp"
Expand Down Expand Up @@ -112,7 +112,7 @@ func (d *Dialer) DialContainerPort(ctx context.Context, addr Addr) (conn net.Con
}
errorStream.Close()
go func() {
message, err := ioutil.ReadAll(errorStream)
message, err := io.ReadAll(errorStream)
switch {
case err != nil:
logger.Error(err, "error reading from error stream")
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/pod/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package pod
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
Expand All @@ -31,7 +30,7 @@ func RunInPod(f *framework.Framework, rootdir string, files []string, command st
for _, file := range files {
base := path.Base(file)
full := path.Join(rootdir, file)
data, err := ioutil.ReadFile(full)
data, err := os.ReadFile(full)
framework.ExpectNoError(err, "read input file %q", full)
input.Write(data)
// Somehow count=1 bs=<total size> resulted in truncated data transfers.
Expand Down