Skip to content

Commit

Permalink
backport of commit b3d2781
Browse files Browse the repository at this point in the history
  • Loading branch information
lhaig committed Mar 4, 2023
1 parent a2cc449 commit 2637f3b
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 64 deletions.
3 changes: 1 addition & 2 deletions demo/digitalocean/app/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -30,7 +29,7 @@ func main() {
return
}

fh, err := ioutil.TempFile("", "bench")
fh, err := os.CreateTemp("", "bench")
if err != nil {
fmt.Println(err.Error())
return
Expand Down
6 changes: 3 additions & 3 deletions e2e/clientstate/clientstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package clientstate
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -60,7 +60,7 @@ func getPID(client *api.Client, alloc *api.Allocation, path string) (int, error)
}
defer r.Close()

out, err := ioutil.ReadAll(r)
out, err := io.ReadAll(r)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -453,7 +453,7 @@ func (tc *ClientStateTC) TestClientState_Corrupt(f *framework.F) {
}
defer r.Close()

out, err := ioutil.ReadAll(r)
out, err := io.ReadAll(r)
if err != nil {
return false, err
}
Expand Down
3 changes: 1 addition & 2 deletions e2e/csi/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -232,7 +231,7 @@ func volumeRegister(volID, volFilePath, createOrRegister string) error {
return fmt.Errorf("could not open stdin?: %w", err)
}

content, err := ioutil.ReadFile(volFilePath)
content, err := os.ReadFile(volFilePath)
if err != nil {
return fmt.Errorf("could not open vol file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2eutil/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"regexp"
"strconv"
Expand Down Expand Up @@ -50,7 +50,7 @@ func execCmd(jobID, jobFilePath string, cmd *exec.Cmd) error {
return fmt.Errorf("could not open stdin?: %w", err)
}

content, err := ioutil.ReadFile(jobFilePath)
content, err := os.ReadFile(jobFilePath)
if err != nil {
return fmt.Errorf("could not open job file: %w", err)
}
Expand Down
7 changes: 3 additions & 4 deletions e2e/execagent/execagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package execagent
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -126,7 +125,7 @@ func NewMixedAgent(bin string) (*NomadAgent, error) {
if err := os.MkdirAll(BaseDir, 0755); err != nil {
return nil, err
}
dir, err := ioutil.TempDir(BaseDir, "agent")
dir, err := os.MkdirTemp(BaseDir, "agent")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -161,7 +160,7 @@ func NewClientServerPair(bin string, serverOut, clientOut io.Writer) (
return nil, nil, err
}

sdir, err := ioutil.TempDir(BaseDir, "server")
sdir, err := os.MkdirTemp(BaseDir, "server")
if err != nil {
return nil, nil, err
}
Expand All @@ -188,7 +187,7 @@ func NewClientServerPair(bin string, serverOut, clientOut io.Writer) (
server.Cmd.Stdout = serverOut
server.Cmd.Stderr = serverOut

cdir, err := ioutil.TempDir(BaseDir, "client")
cdir, err := os.MkdirTemp(BaseDir, "client")
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metrics
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"

Expand Down Expand Up @@ -70,7 +70,7 @@ func (tc *MetricsTest) promQuery(query string) (model.Vector, error) {
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("HTTP status: %v", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions e2e/vaultcompat/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -233,7 +232,7 @@ func createBinDir(binDir string) error {
// missingVault returns the binaries that must be downloaded. versions key must
// be the Vault version.
func missingVault(binDir string, versions map[string]string) (map[string]string, error) {
files, err := ioutil.ReadDir(binDir)
files, err := os.ReadDir(binDir)
if err != nil {
if os.IsNotExist(err) {
return versions, nil
Expand Down
5 changes: 2 additions & 3 deletions e2e/vaultsecrets/vaultsecrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -220,7 +219,7 @@ func (tc *VaultSecretsTest) TestVaultSecrets(f *framework.F) {
// We need to namespace the keys in the policy, so read it in and replace the
// values of the policy names
func writePolicy(policyID, policyPath, testID string) (string, error) {
raw, err := ioutil.ReadFile(policyPath)
raw, err := os.ReadFile(policyPath)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -248,7 +247,7 @@ func writePolicy(policyID, policyPath, testID string) (string, error) {
// and replace the values of the template and vault fields
func runJob(jobID, testID string, index int) error {

raw, err := ioutil.ReadFile("./vaultsecrets/input/secrets.nomad")
raw, err := os.ReadFile("./vaultsecrets/input/secrets.nomad")
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions helper/escapingfs/escapes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package escapingfs

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -11,7 +10,7 @@ import (
)

func write(t *testing.T, file, data string) {
err := ioutil.WriteFile(file, []byte(data), 0600)
err := os.WriteFile(file, []byte(data), 0600)
require.NoError(t, err)
}

Expand Down
3 changes: 1 addition & 2 deletions helper/pluginutils/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package loader

import (
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -1214,7 +1213,7 @@ func TestPluginLoader_External_SkipBadFiles(t *testing.T) {
require.NoError(os.Symlink(selfExe, filepath.Join(h.pluginDir(), plugins[0])))

// Create a non-executable file
require.NoError(ioutil.WriteFile(filepath.Join(h.pluginDir(), "some.yaml"), []byte("hcl > yaml"), 0666))
require.NoError(os.WriteFile(filepath.Join(h.pluginDir(), "some.yaml"), []byte("hcl > yaml"), 0666))

logger := testlog.HCLogger(t)
logger.SetLevel(log.Trace)
Expand Down
3 changes: 1 addition & 2 deletions helper/snapshot/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"time"

"github.com/hashicorp/raft"
Expand Down Expand Up @@ -202,7 +201,7 @@ func read(in io.Reader, metadata *raft.SnapshotMeta, snap io.Writer) error {
// turn made the snapshot verification fail. By explicitly reading the
// whole thing first we ensure that we calculate the correct hash
// independent of how json.Decode works internally.
buf, err := ioutil.ReadAll(io.TeeReader(archive, metaHash))
buf, err := io.ReadAll(io.TeeReader(archive, metaHash))
if err != nil {
return fmt.Errorf("failed to read snapshot metadata: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions helper/snapshot/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/rand"
"fmt"
"io"
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -75,7 +74,7 @@ func TestArchive_GoodData(t *testing.T) {
defer f.Close()

var metadata raft.SnapshotMeta
err = read(f, &metadata, ioutil.Discard)
err = read(f, &metadata, io.Discard)
if err != nil {
t.Fatalf("case %d: should've read the snapshot, but didn't: %v", i, err)
}
Expand Down Expand Up @@ -104,7 +103,7 @@ func TestArchive_BadData(t *testing.T) {
defer f.Close()

var metadata raft.SnapshotMeta
err = read(f, &metadata, ioutil.Discard)
err = read(f, &metadata, io.Discard)
if err == nil || !strings.Contains(err.Error(), c.Error) {
t.Fatalf("case %d (%s): %v", i, c.Name, err)
}
Expand Down
7 changes: 3 additions & 4 deletions helper/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -50,7 +49,7 @@ func New(logger hclog.Logger, r *raft.Raft) (*Snapshot, error) {
// Make a scratch file to receive the contents so that we don't buffer
// everything in memory. This gets deleted in Close() since we keep it
// around for re-reading.
archive, err := ioutil.TempFile("", "snapshot")
archive, err := os.CreateTemp("", "snapshot")
if err != nil {
return nil, fmt.Errorf("failed to create snapshot file: %v", err)
}
Expand Down Expand Up @@ -180,7 +179,7 @@ func CopySnapshot(in io.Reader, dest io.WriteCloser) (*raft.SnapshotMeta, error)
// The docs for gzip.Reader say: "Clients should treat data returned by Read as
// tentative until they receive the io.EOF marking the end of the data."
func concludeGzipRead(decomp *gzip.Reader) error {
extra, err := ioutil.ReadAll(decomp) // ReadAll consumes the EOF
extra, err := io.ReadAll(decomp) // ReadAll consumes the EOF
if err != nil {
return err
} else if len(extra) != 0 {
Expand Down Expand Up @@ -219,7 +218,7 @@ func Restore(logger hclog.Logger, in io.Reader, r *raft.Raft) error {

// Make a scratch file to receive the contents of the snapshot data so
// we can avoid buffering in memory.
snap, err := ioutil.TempFile("", "snapshot")
snap, err := os.CreateTemp("", "snapshot")
if err != nil {
return fmt.Errorf("failed to create temp snapshot file: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions helper/testtask/testtask.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package testtask

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"time"
Expand Down Expand Up @@ -110,7 +109,7 @@ func execute() {
}
msg := popArg()
file := popArg()
ioutil.WriteFile(file, []byte(msg), 0666)
os.WriteFile(file, []byte(msg), 0666)

case "pgrp":
if len(args) < 1 {
Expand All @@ -135,7 +134,7 @@ func execute() {
os.Exit(1)
}

if err := ioutil.WriteFile(pidFile, []byte(fmt.Sprintf("%d", cmd.Process.Pid)), 0777); err != nil {
if err := os.WriteFile(pidFile, []byte(fmt.Sprintf("%d", cmd.Process.Pid)), 0777); err != nil {
fmt.Fprintf(os.Stderr, "failed to write pid file: %v\n", err)
os.Exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions jobspec2/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -127,7 +126,7 @@ func decode(c *jobConfig) error {
}

func parseFile(path string) (*hcl.File, hcl.Diagnostics) {
body, err := ioutil.ReadFile(path)
body, err := os.ReadFile(path)
if err != nil {
return nil, hcl.Diagnostics{
&hcl.Diagnostic{
Expand Down
9 changes: 4 additions & 5 deletions jobspec2/parse_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jobspec2

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -19,7 +18,7 @@ func TestEquivalentToHCL1(t *testing.T) {
ci.Parallel(t)

hclSpecDir := "../jobspec/test-fixtures/"
fis, err := ioutil.ReadDir(hclSpecDir)
fis, err := os.ReadDir(hclSpecDir)
require.NoError(t, err)

for _, fi := range fis {
Expand Down Expand Up @@ -168,7 +167,7 @@ job "example" {
})

t.Run("set via var-files", func(t *testing.T) {
varFile, err := ioutil.TempFile("", "")
varFile, err := os.CreateTemp("", "")
require.NoError(t, err)
defer os.Remove(varFile.Name())

Expand Down Expand Up @@ -328,7 +327,7 @@ job "example" {
})
require.NoError(t, err)

expected, err := ioutil.ReadFile("parse_test.go")
expected, err := os.ReadFile("parse_test.go")
require.NoError(t, err)

require.NotNil(t, out.Region)
Expand Down Expand Up @@ -426,7 +425,7 @@ func TestParse_InvalidHCL(t *testing.T) {
})

t.Run("invalid vars file", func(t *testing.T) {
tmp, err := ioutil.TempFile("", "nomad-jobspec2-")
tmp, err := os.CreateTemp("", "nomad-jobspec2-")
require.NoError(t, err)
defer os.Remove(tmp.Name())

Expand Down
3 changes: 1 addition & 2 deletions nomad/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -554,7 +553,7 @@ func (a *ACL) fileBootstrapResetIndex() uint64 {
path := filepath.Join(a.srv.config.DataDir, aclBootstrapReset)

// Read the file
raw, err := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
if !os.IsNotExist(err) {
a.logger.Error("failed to read bootstrap file", "path", path, "error", err)
Expand Down
Loading

0 comments on commit 2637f3b

Please sign in to comment.