Skip to content

Commit 3da4a9c

Browse files
authored
refactor: move from io/ioutil to io and os packages (#27674)
* config/tests: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * def/configmap: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * experiment: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * gcsweb: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * genred: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * ghproxy: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * gopherage: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * greenhouse/diskcache: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * hack: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * images/builder: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * kubetest: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * label_sync: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * linkcheck: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * logexporter: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * pkg: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/bugzilla: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/clonerefs: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/cmd: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/config: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/crier: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/deck: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/entrypoint: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/external-plugins: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/flagutil: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/gcsupload: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/gerrit: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/ghhook: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/git: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/github: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/githubeventserver: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/hook: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/initupload: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/interrupts: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/io: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/jenkins: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/jira: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/kube: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/metrics: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/phony: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/pjutil: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/pluginhelp: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/plugins: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/pod-utils: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/prstatus: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/repoowners: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/sidecar: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/slack: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/spyglass: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/statusreconciler: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/test: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/testutil: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * prow/tide: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * releng: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * robots: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * testgrid: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> * triage/summarize: move from io/ioutil to io and os packages Signed-off-by: Eng Zer Jun <[email protected]> Signed-off-by: Eng Zer Jun <[email protected]>
1 parent 017a771 commit 3da4a9c

File tree

180 files changed

+533
-635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+533
-635
lines changed

config/tests/mergelists/mergelist_test.go

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

1919
import (
2020
"flag"
21-
"io/ioutil"
21+
"os"
2222
"strings"
2323
"testing"
2424

@@ -32,7 +32,7 @@ func TestMergelist(t *testing.T) {
3232

3333
for _, filename := range files {
3434
t.Run(filename, func(t *testing.T) {
35-
file, err := ioutil.ReadFile(filename)
35+
file, err := os.ReadFile(filename)
3636
if err != nil {
3737
t.Errorf("Can't read file: %v", err)
3838
}

config/tests/testgrids/config_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"flag"
2222
"fmt"
23-
"io/ioutil"
2423
"net/mail"
2524
"os"
2625
"path"
@@ -102,7 +101,7 @@ func TestMain(m *testing.M) {
102101
inputs = defaultInputs
103102
}
104103
// Generate proto from testgrid config
105-
tmpDir, err := ioutil.TempDir("", "testgrid-config-test")
104+
tmpDir, err := os.MkdirTemp("", "testgrid-config-test")
106105
if err != nil {
107106
fmt.Println(err)
108107
os.Exit(1)

def/configmap/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"bytes"
2222
"flag"
2323
"fmt"
24-
"io/ioutil"
2524
"log"
2625
"os"
2726
"strings"
@@ -91,7 +90,7 @@ func buildConfigMap(name, namespace string, labels map[string]string, data map[s
9190
if len(data) > 0 {
9291
cm.Data = map[string]string{}
9392
for key, value := range data {
94-
buf, err := ioutil.ReadFile(value)
93+
buf, err := os.ReadFile(value)
9594
if err != nil {
9695
wd, _ := os.Getwd()
9796
return nil, fmt.Errorf("could not read %s/%s: %w", wd, value, err)
@@ -119,7 +118,7 @@ func main() {
119118
fmt.Print(string(buf))
120119
return
121120
}
122-
err = ioutil.WriteFile(opt.output, buf, 0644)
121+
err = os.WriteFile(opt.output, buf, 0644)
123122
if err != nil {
124123
log.Fatalf("Failed to write %s: %v", opt.output, err)
125124
}

experiment/bumpmonitoring/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"io/ioutil"
2423
"os"
2524
"path"
2625
"path/filepath"
@@ -65,7 +64,7 @@ func parseOptions() (*options, error) {
6564
flag.Parse()
6665

6766
var o options
68-
data, err := ioutil.ReadFile(config)
67+
data, err := os.ReadFile(config)
6968
if err != nil {
7069
return nil, fmt.Errorf("read %q: %w", config, err)
7170
}
@@ -167,11 +166,11 @@ func (c *client) copyFiles() error {
167166
for _, subPath := range c.paths {
168167
SrcPath := path.Join(c.srcPath, subPath)
169168
DstPath := path.Join(c.dstPath, subPath)
170-
content, err := ioutil.ReadFile(SrcPath)
169+
content, err := os.ReadFile(SrcPath)
171170
if err != nil {
172171
return fmt.Errorf("failed reading file %q: %w", SrcPath, err)
173172
}
174-
if err := ioutil.WriteFile(DstPath, content, 0755); err != nil {
173+
if err := os.WriteFile(DstPath, content, 0755); err != nil {
175174
return fmt.Errorf("failed writing file %q: %w", DstPath, err)
176175
}
177176
}

experiment/bumpmonitoring/main_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"io/ioutil"
2120
"os"
2221
"path"
2322
"testing"
@@ -87,7 +86,7 @@ func TestFindConfigToUpdate(t *testing.T) {
8786

8887
for _, tc := range tests {
8988
t.Run(tc.name, func(t *testing.T) {
90-
tmpDir, err := ioutil.TempDir("", tc.name)
89+
tmpDir, err := os.MkdirTemp("", tc.name)
9190
if err != nil {
9291
t.Fatalf("Failed creating temp dir: %v", err)
9392
}
@@ -161,7 +160,7 @@ func TestCopyFiles(t *testing.T) {
161160

162161
for _, tc := range tests {
163162
t.Run(tc.name, func(t *testing.T) {
164-
tmpDir, err := ioutil.TempDir("", tc.name)
163+
tmpDir, err := os.MkdirTemp("", tc.name)
165164
if err != nil {
166165
t.Fatalf("Failed creating temp dir: %v", err)
167166
}
@@ -207,7 +206,7 @@ func pathToNode(t *testing.T, root, p string) node {
207206
if info.IsDir() {
208207
n.IsDir = true
209208
} else {
210-
bs, err := ioutil.ReadFile(p)
209+
bs, err := os.ReadFile(p)
211210
if err != nil {
212211
t.Fatalf("Failed to read %q: %v", p, err)
213212
}
@@ -233,7 +232,7 @@ func seedTempDir(t *testing.T, root string, srcNodes, dstNodes []node) (string,
233232
if err := os.MkdirAll(dir, 0755); err != nil {
234233
t.Fatalf("Failed creating dir %q: %v", dir, err)
235234
}
236-
if err := ioutil.WriteFile(p, []byte(n.Content), 0777); err != nil {
235+
if err := os.WriteFile(p, []byte(n.Content), 0777); err != nil {
237236
t.Fatalf("Failed creating file %q: %v", p, err)
238237
}
239238
}

experiment/coverage/apicoverage.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"flag"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"log"
2726
"net/http"
2827
"net/url"
@@ -93,7 +92,7 @@ func getOpenAPISpec(url string) apiArray {
9392
if err != nil {
9493
log.Fatal(err)
9594
}
96-
bytes, err := ioutil.ReadAll(resp.Body)
95+
bytes, err := io.ReadAll(resp.Body)
9796
if err != nil {
9897
log.Fatal(err)
9998
}

experiment/gerrit-onboarder/onboarder.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"flag"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"math/rand"
2726
"os"
2827
"os/exec"
@@ -164,7 +163,7 @@ func ensureUUID(groupsFile, uuid, group string) (string, error) {
164163
}
165164

166165
func updateGroups(workDir, uuid, group string) error {
167-
data, err := ioutil.ReadFile(path.Join(workDir, groupsFile))
166+
data, err := os.ReadFile(path.Join(workDir, groupsFile))
168167
if err != nil {
169168
return fmt.Errorf("failed to read groups file: %w", err)
170169
}
@@ -174,7 +173,7 @@ func updateGroups(workDir, uuid, group string) error {
174173
return fmt.Errorf("failed to ensure group exists: %w", err)
175174
}
176175

177-
err = ioutil.WriteFile(path.Join(workDir, groupsFile), []byte(newData), 0755)
176+
err = os.WriteFile(path.Join(workDir, groupsFile), []byte(newData), 0755)
178177
if err != nil {
179178
return fmt.Errorf("failed to write groups file: %w", err)
180179
}
@@ -297,7 +296,7 @@ func verifyInTree(workDir, host, cur_branch string, configMap map[string][]strin
297296
// If it failed to fetch refs/meta/config for parent, or checkout the FETCH_HEAD, just catch the error and return False
298297
return false, nil
299298
}
300-
data, err := ioutil.ReadFile(path.Join(workDir, projectConfigFile))
299+
data, err := os.ReadFile(path.Join(workDir, projectConfigFile))
301300
if err != nil {
302301
return false, fmt.Errorf("failed to read project.config file: %w", err)
303302
}
@@ -355,7 +354,7 @@ func ensureProjectConfig(workDir, config, host, cur_branch, groupName string) (s
355354
}
356355

357356
func updatePojectConfig(workDir, host, cur_branch, groupName string) error {
358-
data, err := ioutil.ReadFile(path.Join(workDir, projectConfigFile))
357+
data, err := os.ReadFile(path.Join(workDir, projectConfigFile))
359358
if err != nil {
360359
return fmt.Errorf("failed to read project.config file: %w", err)
361360
}
@@ -364,7 +363,7 @@ func updatePojectConfig(workDir, host, cur_branch, groupName string) error {
364363
if err != nil {
365364
return fmt.Errorf("failed to ensure updated project config: %w", err)
366365
}
367-
err = ioutil.WriteFile(path.Join(workDir, projectConfigFile), []byte(newData), 0755)
366+
err = os.WriteFile(path.Join(workDir, projectConfigFile), []byte(newData), 0755)
368367
if err != nil {
369368
return fmt.Errorf("failed to write groups file: %w", err)
370369
}
@@ -453,7 +452,7 @@ func main() {
453452
logrus.Fatal(err)
454453
}
455454
} else {
456-
workDir, err = ioutil.TempDir("", "gerrit_onboarding")
455+
workDir, err = os.MkdirTemp("", "gerrit_onboarding")
457456
if err != nil {
458457
logrus.Fatal(err)
459458
}

experiment/image-bumper/bumper/bumper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package bumper
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
2322
"log"
2423
"net/http"
24+
"os"
2525
"regexp"
2626
"strconv"
2727
"strings"
@@ -262,14 +262,14 @@ func updateAllTags(tagPicker func(host, image, tag string) (string, error), cont
262262
// UpdateFile updates a file in place.
263263
func (cli *Client) UpdateFile(tagPicker func(imageHost, imageName, currentTag string) (string, error),
264264
path string, imageFilter *regexp.Regexp) error {
265-
content, err := ioutil.ReadFile(path)
265+
content, err := os.ReadFile(path)
266266
if err != nil {
267267
return fmt.Errorf("failed to read %s: %w", path, err)
268268
}
269269

270270
newContent := updateAllTags(tagPicker, content, imageFilter)
271271

272-
if err := ioutil.WriteFile(path, newContent, 0644); err != nil {
272+
if err := os.WriteFile(path, newContent, 0644); err != nil {
273273
return fmt.Errorf("failed to write %s: %w", path, err)
274274
}
275275
return nil

experiment/ml/analyze/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"log"
2626
"net/http"
2727
"net/url"
@@ -71,7 +71,7 @@ func processRequest(ctx context.Context, storageClient *storage.Client, predicto
7171
if r.ContentLength > maxRequestLen {
7272
return http.StatusBadRequest, "Request too long", fmt.Errorf("%d byte request", r.ContentLength)
7373
}
74-
bytes, err := ioutil.ReadAll(r.Body)
74+
bytes, err := io.ReadAll(r.Body)
7575
if err != nil {
7676
return http.StatusBadRequest, "Could not read request", fmt.Errorf("read request: %w", err)
7777
}

experiment/ml/prowlog/csv/generate-dataset.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"flag"
4343
"fmt"
4444
"io"
45-
"io/ioutil"
4645
"log"
4746
"os"
4847
"strings"
@@ -103,7 +102,7 @@ func main() {
103102
continue
104103
}
105104
defer zf.Close()
106-
b, err := ioutil.ReadAll(zf)
105+
b, err := io.ReadAll(zf)
107106
if err != nil {
108107
log.Println("Failed to read eample", f.Name, err)
109108
continue

experiment/ml/prowlog/generate-dataset.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"fmt"
2929
"io"
3030
"io/fs"
31-
"io/ioutil"
3231
"log"
3332
"math/rand"
3433
"os"
@@ -753,11 +752,11 @@ func (bc *buildCache) open(ctx context.Context, client gcs.ConditionalClient, pa
753752
if bc.archivePath == "" {
754753
return r, nil, nil
755754
}
756-
buf, err := ioutil.ReadAll(r)
755+
buf, err := io.ReadAll(r)
757756
if err != nil {
758757
return nil, nil, fmt.Errorf("read: %v", err)
759758
}
760-
f = ioutil.NopCloser(bytes.NewBuffer(buf))
759+
f = io.NopCloser(bytes.NewBuffer(buf))
761760
when = &attrs.LastModified
762761
if err := bc.initAdditional(); err != nil {
763762
return nil, nil, fmt.Errorf("init additional: %v", err)

experiment/slack-oncall-updater/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"encoding/json"
2121
"flag"
2222
"fmt"
23-
"io/ioutil"
2423
"log"
2524
"net/http"
25+
"os"
2626
"strings"
2727
)
2828

@@ -104,7 +104,7 @@ func updateGroupMembership(token, groupID, userID string) error {
104104
}
105105

106106
func getTokenFromPath(path string) (string, error) {
107-
content, err := ioutil.ReadFile(path)
107+
content, err := os.ReadFile(path)
108108
if err != nil {
109109
return "", fmt.Errorf("couldn't open file: %w", err)
110110
}

gcsweb/cmd/gcsweb/gcsweb.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"flag"
2525
"fmt"
2626
"io"
27-
"io/ioutil"
2827
"math/rand"
2928
"net/http"
3029
"os"
@@ -152,7 +151,7 @@ func getStorageClient(o options) (*storage.Client, error) {
152151
}
153152

154153
if o.oauthTokenFile != "" {
155-
b, err := ioutil.ReadFile(o.oauthTokenFile)
154+
b, err := os.ReadFile(o.oauthTokenFile)
156155
if err != nil {
157156
return nil, fmt.Errorf("error reading oauth token file %s: %w", o.oauthTokenFile, err)
158157
}

gencred/cmd/gencred/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/base64"
2222
"errors"
2323
"fmt"
24-
"io/ioutil"
2524
"log"
2625
"net/http"
2726
"os"
@@ -143,7 +142,7 @@ func (o *options) defaultAndValidateFlags() (*config, error) {
143142
var c config
144143
if len(o.config) > 0 {
145144
// Load from config yaml file
146-
body, err := ioutil.ReadFile(o.config)
145+
body, err := os.ReadFile(o.config)
147146
if err != nil {
148147
util.PrintErrAndExit(err)
149148
}
@@ -194,13 +193,13 @@ func (o *options) defaultAndValidateFlags() (*config, error) {
194193

195194
// mergeConfigs merges an existing kubeconfig file with a new entry with precedence given to the existing config.
196195
func mergeConfigs(c clusterConfig, kubeconfig []byte) ([]byte, error) {
197-
tmpFile, err := ioutil.TempFile("", "")
196+
tmpFile, err := os.CreateTemp("", "")
198197
if err != nil {
199198
return nil, &util.ExitError{Message: err.Error(), Code: 1}
200199
}
201200
defer os.Remove(tmpFile.Name())
202201

203-
err = ioutil.WriteFile(tmpFile.Name(), kubeconfig, 0644)
202+
err = os.WriteFile(tmpFile.Name(), kubeconfig, 0644)
204203
if err != nil {
205204
return nil, &util.ExitError{Message: err.Error(), Code: 1}
206205
}
@@ -257,7 +256,7 @@ func writeConfig(c clusterConfig, clientset kubernetes.Interface) error {
257256
}
258257
}
259258

260-
if err = ioutil.WriteFile(*c.Output, kubeconfig, 0644); err != nil {
259+
if err = os.WriteFile(*c.Output, kubeconfig, 0644); err != nil {
261260
return &util.ExitError{Message: fmt.Sprintf("unable to write to file %v: %v.", file, err), Code: 1}
262261
}
263262
}

gencred/cmd/gencred/main_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 gencred
1818

1919
import (
20-
"io/ioutil"
2120
"os"
2221
"path"
2322
"testing"
@@ -114,7 +113,7 @@ func TestValidateFlags(t *testing.T) {
114113
if len(test.config) > 0 {
115114
tmpDir := t.TempDir()
116115
tmpFile := path.Join(tmpDir, test.name+".yaml")
117-
if err := ioutil.WriteFile(tmpFile, []byte(test.config), 0644); err != nil {
116+
if err := os.WriteFile(tmpFile, []byte(test.config), 0644); err != nil {
118117
t.Fatalf("Failed writing tmp file: %v", err)
119118
}
120119
os.Args = append(os.Args, "--config="+tmpFile)

0 commit comments

Comments
 (0)