Skip to content

Commit 6dc23ca

Browse files
committed
chore: remove refs to deprecated io/ioutil
1 parent 339e243 commit 6dc23ca

File tree

15 files changed

+36
-43
lines changed

15 files changed

+36
-43
lines changed

cmd/nodeproblemdetector/node_problem_detector_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !disable_system_log_monitor
12
// +build !disable_system_log_monitor
23

34
/*
@@ -21,7 +22,6 @@ package main
2122
import (
2223
"errors"
2324
"fmt"
24-
"io/ioutil"
2525
"os"
2626
"strings"
2727
"testing"
@@ -91,14 +91,14 @@ func TestNPDMain(t *testing.T) {
9191
}
9292

9393
func writeTempFile(t *testing.T, ext string, contents string) (string, error) {
94-
f, err := ioutil.TempFile("", "*."+ext)
94+
f, err := os.CreateTemp("", "*."+ext)
9595
if err != nil {
9696
return "", fmt.Errorf("cannot create temp file, %v", err)
9797
}
9898

9999
fileName := f.Name()
100100

101-
if err := ioutil.WriteFile(fileName, []byte(contents), 0644); err != nil {
101+
if err := os.WriteFile(fileName, []byte(contents), 0644); err != nil {
102102
os.Remove(fileName)
103103
return "", fmt.Errorf("cannot write config to temp file %s, %v", fileName, err)
104104
}

pkg/custompluginmonitor/custom_plugin_monitor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package custompluginmonitor
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"os"
2222
"time"
2323

2424
"github.com/golang/glog"
@@ -57,7 +57,7 @@ func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
5757
configPath: configPath,
5858
tomb: tomb.NewTomb(),
5959
}
60-
f, err := ioutil.ReadFile(configPath)
60+
f, err := os.ReadFile(configPath)
6161
if err != nil {
6262
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
6363
}

pkg/custompluginmonitor/plugin/plugin.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"os/exec"
2524
"strings"
2625
"sync"
@@ -132,12 +131,12 @@ func (p *Plugin) runRules() {
132131
// readFromReader reads the maxBytes from the reader and drains the rest.
133132
func readFromReader(reader io.ReadCloser, maxBytes int64) ([]byte, error) {
134133
limitReader := io.LimitReader(reader, maxBytes)
135-
data, err := ioutil.ReadAll(limitReader)
134+
data, err := io.ReadAll(limitReader)
136135
if err != nil {
137136
return []byte{}, err
138137
}
139138
// Drain the reader
140-
if _, err := io.Copy(ioutil.Discard, reader); err != nil {
139+
if _, err := io.Copy(io.Discard, reader); err != nil {
141140
return []byte{}, err
142141
}
143142
return data, nil

pkg/exporters/k8sexporter/problemclient/configs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ package problemclient
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"net/url"
20+
"os"
2121
"strconv"
2222

2323
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -137,7 +137,7 @@ func getKubeClientConfig(uri *url.URL) (*kube_rest.Config, error) {
137137

138138
if useServiceAccount {
139139
// If a readable service account token exists, then use it
140-
if contents, err := ioutil.ReadFile(defaultServiceAccountFile); err == nil {
140+
if contents, err := os.ReadFile(defaultServiceAccountFile); err == nil {
141141
kubeConfig.BearerToken = string(contents)
142142
}
143143
}

pkg/exporters/stackdriver/stackdriver_exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package stackdriverexporter
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"os"
2222
"path/filepath"
2323
"reflect"
2424
"time"
@@ -209,7 +209,7 @@ func NewExporterOrDie(clo types.CommandLineOptions) types.Exporter {
209209
se := stackdriverExporter{}
210210

211211
// Apply configurations.
212-
f, err := ioutil.ReadFile(options.configPath)
212+
f, err := os.ReadFile(options.configPath)
213213
if err != nil {
214214
glog.Fatalf("Failed to read configuration file %q: %v", options.configPath, err)
215215
}

pkg/systemlogmonitor/log_monitor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package systemlogmonitor
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"os"
2222
"time"
2323

2424
"github.com/golang/glog"
@@ -62,7 +62,7 @@ func NewLogMonitorOrDie(configPath string) types.Monitor {
6262
tomb: tomb.NewTomb(),
6363
}
6464

65-
f, err := ioutil.ReadFile(configPath)
65+
f, err := os.ReadFile(configPath)
6666
if err != nil {
6767
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
6868
}

pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package filelog
1818

1919
import (
20-
"io/ioutil"
2120
"os"
2221
"testing"
2322
"time"
@@ -139,7 +138,7 @@ Jan 2 03:04:05 kernel: [2.000000] 3
139138
}
140139
for c, test := range testCases {
141140
t.Logf("TestCase #%d: %#v", c+1, test)
142-
f, err := ioutil.TempFile("", "log_watcher_test")
141+
f, err := os.CreateTemp("", "log_watcher_test")
143142
assert.NoError(t, err)
144143
defer func() {
145144
f.Close()

pkg/systemstatsmonitor/net_collector_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package systemstatsmonitor
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path"
76
"regexp"
@@ -48,12 +47,8 @@ func newFakeInt64Metric(metricID metrics.MetricID, viewName string, description
4847
// testCollectAux is a test auxiliary function used for testing netCollector.Collect
4948
func testCollectAux(t *testing.T, name string, excludeInterfaceRegexp ssmtypes.NetStatsInterfaceRegexp, validate func(*testing.T, *netCollector)) {
5049
// mkdir /tmp/proc-X
51-
procDir, err := ioutil.TempDir(os.TempDir(), "proc-")
52-
if err != nil {
53-
t.Fatalf("Failed to create temp proc directory: %v", err)
54-
}
55-
// rm -r /tmp/proc-X
56-
defer os.RemoveAll(procDir)
50+
procDir := t.TempDir()
51+
5752
// mkdir -C /tmp/proc-X/net
5853
procNetDir := path.Join(procDir, "net")
5954
if err := os.Mkdir(procNetDir, 0777); err != nil {

pkg/systemstatsmonitor/osfeature_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package systemstatsmonitor
1515

1616
import (
1717
"encoding/json"
18-
"io/ioutil"
18+
"os"
1919
"path/filepath"
2020
"strconv"
2121
"strings"
@@ -102,7 +102,7 @@ func (ofc *osFeatureCollector) recordFeaturesFromCmdline(cmdlineArgs []system.Cm
102102
func (ofc *osFeatureCollector) recordFeaturesFromModules(modules []system.Module) {
103103
// Collect known modules (default modules based on guest OS present in known-modules.json)
104104
var knownModules []system.Module
105-
f, err := ioutil.ReadFile(ofc.config.KnownModulesConfigPath)
105+
f, err := os.ReadFile(ofc.config.KnownModulesConfigPath)
106106
if err != nil {
107107
glog.Warningf("Failed to read configuration file %s: %v",
108108
ofc.config.KnownModulesConfigPath, err)

pkg/systemstatsmonitor/system_stats_monitor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package systemstatsmonitor
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"os"
2222
"path/filepath"
2323
"time"
2424

@@ -58,7 +58,7 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
5858
}
5959

6060
// Apply configurations.
61-
f, err := ioutil.ReadFile(configPath)
61+
f, err := os.ReadFile(configPath)
6262
if err != nil {
6363
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
6464
}

0 commit comments

Comments
 (0)