Skip to content
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
6 changes: 3 additions & 3 deletions cmd/nodeproblemdetector/node_problem_detector_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !disable_system_log_monitor
// +build !disable_system_log_monitor

/*
Expand All @@ -21,7 +22,6 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -91,14 +91,14 @@ func TestNPDMain(t *testing.T) {
}

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

fileName := f.Name()

if err := ioutil.WriteFile(fileName, []byte(contents), 0644); err != nil {
if err := os.WriteFile(fileName, []byte(contents), 0644); err != nil {
os.Remove(fileName)
return "", fmt.Errorf("cannot write config to temp file %s, %v", fileName, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/custompluginmonitor/custom_plugin_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package custompluginmonitor

import (
"encoding/json"
"io/ioutil"
"os"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -57,7 +57,7 @@ func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
configPath: configPath,
tomb: tomb.NewTomb(),
}
f, err := ioutil.ReadFile(configPath)
f, err := os.ReadFile(configPath)
if err != nil {
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/custompluginmonitor/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os/exec"
"strings"
"sync"
Expand Down Expand Up @@ -132,12 +131,12 @@ func (p *Plugin) runRules() {
// readFromReader reads the maxBytes from the reader and drains the rest.
func readFromReader(reader io.ReadCloser, maxBytes int64) ([]byte, error) {
limitReader := io.LimitReader(reader, maxBytes)
data, err := ioutil.ReadAll(limitReader)
data, err := io.ReadAll(limitReader)
if err != nil {
return []byte{}, err
}
// Drain the reader
if _, err := io.Copy(ioutil.Discard, reader); err != nil {
if _, err := io.Copy(io.Discard, reader); err != nil {
return []byte{}, err
}
return data, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/exporters/k8sexporter/problemclient/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package problemclient

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"strconv"

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

if useServiceAccount {
// If a readable service account token exists, then use it
if contents, err := ioutil.ReadFile(defaultServiceAccountFile); err == nil {
if contents, err := os.ReadFile(defaultServiceAccountFile); err == nil {
kubeConfig.BearerToken = string(contents)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/exporters/stackdriver/stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package stackdriverexporter

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"time"
Expand Down Expand Up @@ -209,7 +209,7 @@ func NewExporterOrDie(clo types.CommandLineOptions) types.Exporter {
se := stackdriverExporter{}

// Apply configurations.
f, err := ioutil.ReadFile(options.configPath)
f, err := os.ReadFile(options.configPath)
if err != nil {
glog.Fatalf("Failed to read configuration file %q: %v", options.configPath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/systemlogmonitor/log_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package systemlogmonitor

import (
"encoding/json"
"io/ioutil"
"os"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -62,7 +62,7 @@ func NewLogMonitorOrDie(configPath string) types.Monitor {
tomb: tomb.NewTomb(),
}

f, err := ioutil.ReadFile(configPath)
f, err := os.ReadFile(configPath)
if err != nil {
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package filelog

import (
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -139,7 +138,7 @@ Jan 2 03:04:05 kernel: [2.000000] 3
}
for c, test := range testCases {
t.Logf("TestCase #%d: %#v", c+1, test)
f, err := ioutil.TempFile("", "log_watcher_test")
f, err := os.CreateTemp("", "log_watcher_test")
assert.NoError(t, err)
defer func() {
f.Close()
Expand Down
9 changes: 2 additions & 7 deletions pkg/systemstatsmonitor/net_collector_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package systemstatsmonitor

import (
"io/ioutil"
"os"
"path"
"regexp"
Expand Down Expand Up @@ -48,12 +47,8 @@ func newFakeInt64Metric(metricID metrics.MetricID, viewName string, description
// testCollectAux is a test auxiliary function used for testing netCollector.Collect
func testCollectAux(t *testing.T, name string, excludeInterfaceRegexp ssmtypes.NetStatsInterfaceRegexp, validate func(*testing.T, *netCollector)) {
// mkdir /tmp/proc-X
procDir, err := ioutil.TempDir(os.TempDir(), "proc-")
if err != nil {
t.Fatalf("Failed to create temp proc directory: %v", err)
}
// rm -r /tmp/proc-X
defer os.RemoveAll(procDir)
procDir := t.TempDir()

// mkdir -C /tmp/proc-X/net
procNetDir := path.Join(procDir, "net")
if err := os.Mkdir(procNetDir, 0777); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/systemstatsmonitor/osfeature_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package systemstatsmonitor

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (ofc *osFeatureCollector) recordFeaturesFromCmdline(cmdlineArgs []system.Cm
func (ofc *osFeatureCollector) recordFeaturesFromModules(modules []system.Module) {
// Collect known modules (default modules based on guest OS present in known-modules.json)
var knownModules []system.Module
f, err := ioutil.ReadFile(ofc.config.KnownModulesConfigPath)
f, err := os.ReadFile(ofc.config.KnownModulesConfigPath)
if err != nil {
glog.Warningf("Failed to read configuration file %s: %v",
ofc.config.KnownModulesConfigPath, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/systemstatsmonitor/system_stats_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package systemstatsmonitor

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"time"

Expand Down Expand Up @@ -58,7 +58,7 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
}

// Apply configurations.
f, err := ioutil.ReadFile(configPath)
f, err := os.ReadFile(configPath)
if err != nil {
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/metrics/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
package metrics

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

Expand Down Expand Up @@ -121,7 +121,7 @@ func TestPrometheusMetricsParsingAndMatching(t *testing.T) {

for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
b, err := ioutil.ReadFile(test.metricsTextPath)
b, err := os.ReadFile(test.metricsTextPath)
if err != nil {
t.Errorf("Unexpected error reading file %s: %v", test.metricsTextPath, err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/nethealth/nethealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"crypto/sha512"
"encoding/hex"
"flag"
"io/ioutil"
"io"
"log"
"net/http"
"strings"
Expand Down Expand Up @@ -92,7 +92,7 @@ func main() {
if res.ContentLength != objectLength {
log.Fatalf("Length reported (%d) is not equal to expected length (%d)", res.ContentLength, objectLength)
}
blobData, err := ioutil.ReadAll(res.Body)
blobData, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal("Failed to read full content", err)
Expand All @@ -110,7 +110,7 @@ func main() {
if err != nil {
log.Fatalf("Failure (%s) while reading %s", err, objectHashUrl)
}
content, err := ioutil.ReadAll(res.Body)
content, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal("Failed to read full content of hash file", err)
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/lib/npd/npd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package npd

import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"time"
Expand All @@ -32,11 +32,11 @@ import (
// SetupNPD installs NPD from the test tarball onto the provided GCE instance.
//
// Here is how it works:
// 1. SetupNPD will SCP the NPD build tarball onto the VM.
// 2. SetupNPD will extract the tarball in the VM, to expose the test/e2e-install.sh on the VM.
// 3. SetupNPD will then call the e2e-install.sh script, and feed the NPD build tarball as input.
// 4. Finally, the e2e-install.sh script will do the heavy lifting of installing NPD (setting up
// binary/config directories, setting up systemd config file, etc).
// 1. SetupNPD will SCP the NPD build tarball onto the VM.
// 2. SetupNPD will extract the tarball in the VM, to expose the test/e2e-install.sh on the VM.
// 3. SetupNPD will then call the e2e-install.sh script, and feed the NPD build tarball as input.
// 4. Finally, the e2e-install.sh script will do the heavy lifting of installing NPD (setting up
// binary/config directories, setting up systemd config file, etc).
func SetupNPD(ins gce.Instance, npdBuildTar string) error {
tmpDirCmd := ins.RunCommand("mktemp -d")
if tmpDirCmd.SSHError != nil || tmpDirCmd.Code != 0 {
Expand Down Expand Up @@ -152,7 +152,7 @@ func saveCommandResultAsArtifact(ins gce.Instance, artifactDirectory string, tes
if result.SSHError != nil || result.Code != 0 {
return fmt.Errorf("Error running command: %v\n", result)
}
if err := ioutil.WriteFile(artifactPath, []byte(result.Stdout), 0644); err != nil {
if err := os.WriteFile(artifactPath, []byte(result.Stdout), 0644); err != nil {
return fmt.Errorf("Error writing artifact to %v: %v\n", artifactPath, err)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/problemmaker/makers/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package makers

import (
"io/ioutil"
"os"

"github.com/golang/glog"
)
Expand All @@ -30,7 +30,7 @@ const ext4ErrorTrigger = "/sys/fs/ext4/sda1/trigger_fs_error"

func makeFilesystemError() {
msg := []byte("fake filesystem error from problem-maker")
err := ioutil.WriteFile(ext4ErrorTrigger, msg, 0200)
err := os.WriteFile(ext4ErrorTrigger, msg, 0200)
if err != nil {
glog.Fatalf("Failed writing log to %q: %v", ext4ErrorTrigger, err)
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/problemmaker/makers/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package makers

import (
"io/ioutil"
"os"
"strings"

"github.com/golang/glog"
Expand All @@ -38,7 +38,7 @@ Killed process 1012 (heapster) total-vm:327128kB, anon-rss:306328kB, file-rss:11

func writeKernelMessageOrDie(msg string) {
for _, line := range strings.Split(msg, "\n") {
err := ioutil.WriteFile(kmsgPath, []byte(line), 0644)
err := os.WriteFile(kmsgPath, []byte(line), 0644)
if err != nil {
glog.Fatalf("Failed writing to %q: %v", kmsgPath, err)
}
Expand Down