diff --git a/api/agent.go b/api/agent.go index 742895806..61102e563 100644 --- a/api/agent.go +++ b/api/agent.go @@ -3,7 +3,7 @@ package api import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/url" "strconv" ) @@ -399,7 +399,7 @@ func (a *Agent) pprofRequest(req string, opts PprofOptions, q *QueryOptions) ([] return nil, err } - resp, err := ioutil.ReadAll(body) + resp, err := io.ReadAll(body) if err != nil { return nil, err } diff --git a/api/fs.go b/api/fs.go index 91baca3aa..0622aa708 100644 --- a/api/fs.go +++ b/api/fs.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" "strconv" "sync" @@ -291,7 +290,7 @@ func (a *AllocFS) Logs(alloc *Allocation, follow bool, task, logType, origin str if err == io.EOF || err == io.ErrClosedPipe { close(frames) } else { - buf, err2 := ioutil.ReadAll(dec.Buffered()) + buf, err2 := io.ReadAll(dec.Buffered()) if err2 != nil { errCh <- fmt.Errorf("failed to decode and failed to read buffered data: %w", multierror.Append(err, err2)) } else { diff --git a/api/ioutil_test.go b/api/ioutil_test.go index 0565bb140..c93e3e316 100644 --- a/api/ioutil_test.go +++ b/api/ioutil_test.go @@ -8,7 +8,6 @@ import ( "errors" "hash" "io" - "io/ioutil" "math/rand" "testing" "testing/iotest" @@ -41,10 +40,10 @@ func TestChecksumValidatingReader(t *testing.T) { digest := c.algo + "=" + base64.StdEncoding.EncodeToString(checksum) r := iotest.HalfReader(bytes.NewReader(data)) - cr, err := newChecksumValidatingReader(ioutil.NopCloser(r), digest) + cr, err := newChecksumValidatingReader(io.NopCloser(r), digest) must.NoError(t, err) - _, err = io.Copy(ioutil.Discard, cr) + _, err = io.Copy(io.Discard, cr) must.NoError(t, err) }) @@ -58,10 +57,10 @@ func TestChecksumValidatingReader(t *testing.T) { digest := c.algo + "=" + base64.StdEncoding.EncodeToString(checksum) r := iotest.HalfReader(bytes.NewReader(data)) - cr, err := newChecksumValidatingReader(ioutil.NopCloser(r), digest) + cr, err := newChecksumValidatingReader(io.NopCloser(r), digest) must.NoError(t, err) - _, err = io.Copy(ioutil.Discard, cr) + _, err = io.Copy(io.Discard, cr) must.ErrorIs(t, err, errMismatchChecksum) }) } @@ -84,6 +83,6 @@ func TestChecksumValidatingReader_PropagatesError(t *testing.T) { cr, err := newChecksumValidatingReader(pr, "sha-256=aaaa") must.NoError(t, err) - _, err = io.Copy(ioutil.Discard, cr) + _, err = io.Copy(io.Discard, cr) must.ErrorIs(t, err, expectedErr) } diff --git a/api/operator.go b/api/operator.go index 13d7d3439..579afc3f5 100644 --- a/api/operator.go +++ b/api/operator.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "strconv" "strings" "time" @@ -229,7 +228,7 @@ func (op *Operator) Snapshot(q *QueryOptions) (io.ReadCloser, error) { cr, err := newChecksumValidatingReader(resp.Body, digest) if err != nil { - io.Copy(ioutil.Discard, resp.Body) + io.Copy(io.Discard, resp.Body) resp.Body.Close() return nil, err diff --git a/api/operator_metrics.go b/api/operator_metrics.go index e64198194..b5577a547 100644 --- a/api/operator_metrics.go +++ b/api/operator_metrics.go @@ -1,7 +1,7 @@ package api import ( - "io/ioutil" + "io" "time" ) @@ -67,7 +67,7 @@ func (op *Operator) Metrics(q *QueryOptions) ([]byte, error) { return nil, err } - metricsBytes, err := ioutil.ReadAll(metricsReader) + metricsBytes, err := io.ReadAll(metricsReader) if err != nil { return nil, err } diff --git a/plugins/drivers/testutils/exec_testing.go b/plugins/drivers/testutils/exec_testing.go index c51099afd..68f1078d8 100644 --- a/plugins/drivers/testutils/exec_testing.go +++ b/plugins/drivers/testutils/exec_testing.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "reflect" "regexp" @@ -176,7 +175,7 @@ func TestExecFSIsolation(t *testing.T, driver *DriverHarness, taskID string) { t.Logf("created file in task: %v", tempfile) // read from host - b, err := ioutil.ReadFile(tempfile) + b, err := os.ReadFile(tempfile) if !isolated { require.NoError(t, err) require.Equal(t, text, strings.TrimSpace(string(b))) diff --git a/plugins/drivers/testutils/testing.go b/plugins/drivers/testutils/testing.go index d568db148..89ff1496d 100644 --- a/plugins/drivers/testutils/testing.go +++ b/plugins/drivers/testutils/testing.go @@ -3,7 +3,6 @@ package testutils import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -116,7 +115,7 @@ func (h *DriverHarness) cleanupCgroup() { // A cleanup func is returned and should be deferred so as to not leak dirs // between tests. func (h *DriverHarness) MkAllocDir(t *drivers.TaskConfig, enableLogs bool) func() { - dir, err := ioutil.TempDir("", "nomad_driver_harness-") + dir, err := os.MkdirTemp("", "nomad_driver_harness-") require.NoError(h.t, err) allocDir := allocdir.NewAllocDir(h.logger, dir, t.AllocID) diff --git a/plugins/shared/cmd/launcher/command/device.go b/plugins/shared/cmd/launcher/command/device.go index b2c9a9fa6..b93a844ca 100644 --- a/plugins/shared/cmd/launcher/command/device.go +++ b/plugins/shared/cmd/launcher/command/device.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -95,7 +94,7 @@ func (c *Device) Run(args []string) int { var config []byte if numArgs == 2 { var err error - config, err = ioutil.ReadFile(args[1]) + config, err = os.ReadFile(args[1]) if err != nil { c.logger.Error("failed to read config file", "error", err) return 1