Skip to content

Commit

Permalink
refactor: move from io/ioutil to io and os packages (kubernetes#27674)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Juneezee authored Oct 10, 2022
1 parent 017a771 commit 3da4a9c
Show file tree
Hide file tree
Showing 180 changed files with 533 additions and 635 deletions.
4 changes: 2 additions & 2 deletions config/tests/mergelists/mergelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package mergelist_test

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

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

for _, filename := range files {
t.Run(filename, func(t *testing.T) {
file, err := ioutil.ReadFile(filename)
file, err := os.ReadFile(filename)
if err != nil {
t.Errorf("Can't read file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions config/tests/testgrids/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"net/mail"
"os"
"path"
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestMain(m *testing.M) {
inputs = defaultInputs
}
// Generate proto from testgrid config
tmpDir, err := ioutil.TempDir("", "testgrid-config-test")
tmpDir, err := os.MkdirTemp("", "testgrid-config-test")
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
5 changes: 2 additions & 3 deletions def/configmap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -91,7 +90,7 @@ func buildConfigMap(name, namespace string, labels map[string]string, data map[s
if len(data) > 0 {
cm.Data = map[string]string{}
for key, value := range data {
buf, err := ioutil.ReadFile(value)
buf, err := os.ReadFile(value)
if err != nil {
wd, _ := os.Getwd()
return nil, fmt.Errorf("could not read %s/%s: %w", wd, value, err)
Expand Down Expand Up @@ -119,7 +118,7 @@ func main() {
fmt.Print(string(buf))
return
}
err = ioutil.WriteFile(opt.output, buf, 0644)
err = os.WriteFile(opt.output, buf, 0644)
if err != nil {
log.Fatalf("Failed to write %s: %v", opt.output, err)
}
Expand Down
7 changes: 3 additions & 4 deletions experiment/bumpmonitoring/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -65,7 +64,7 @@ func parseOptions() (*options, error) {
flag.Parse()

var o options
data, err := ioutil.ReadFile(config)
data, err := os.ReadFile(config)
if err != nil {
return nil, fmt.Errorf("read %q: %w", config, err)
}
Expand Down Expand Up @@ -167,11 +166,11 @@ func (c *client) copyFiles() error {
for _, subPath := range c.paths {
SrcPath := path.Join(c.srcPath, subPath)
DstPath := path.Join(c.dstPath, subPath)
content, err := ioutil.ReadFile(SrcPath)
content, err := os.ReadFile(SrcPath)
if err != nil {
return fmt.Errorf("failed reading file %q: %w", SrcPath, err)
}
if err := ioutil.WriteFile(DstPath, content, 0755); err != nil {
if err := os.WriteFile(DstPath, content, 0755); err != nil {
return fmt.Errorf("failed writing file %q: %w", DstPath, err)
}
}
Expand Down
9 changes: 4 additions & 5 deletions experiment/bumpmonitoring/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package main

import (
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -87,7 +86,7 @@ func TestFindConfigToUpdate(t *testing.T) {

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

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", tc.name)
tmpDir, err := os.MkdirTemp("", tc.name)
if err != nil {
t.Fatalf("Failed creating temp dir: %v", err)
}
Expand Down Expand Up @@ -207,7 +206,7 @@ func pathToNode(t *testing.T, root, p string) node {
if info.IsDir() {
n.IsDir = true
} else {
bs, err := ioutil.ReadFile(p)
bs, err := os.ReadFile(p)
if err != nil {
t.Fatalf("Failed to read %q: %v", p, err)
}
Expand All @@ -233,7 +232,7 @@ func seedTempDir(t *testing.T, root string, srcNodes, dstNodes []node) (string,
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatalf("Failed creating dir %q: %v", dir, err)
}
if err := ioutil.WriteFile(p, []byte(n.Content), 0777); err != nil {
if err := os.WriteFile(p, []byte(n.Content), 0777); err != nil {
t.Fatalf("Failed creating file %q: %v", p, err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions experiment/coverage/apicoverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -93,7 +92,7 @@ func getOpenAPISpec(url string) apiArray {
if err != nil {
log.Fatal(err)
}
bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
Expand Down
13 changes: 6 additions & 7 deletions experiment/gerrit-onboarder/onboarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"os/exec"
Expand Down Expand Up @@ -164,7 +163,7 @@ func ensureUUID(groupsFile, uuid, group string) (string, error) {
}

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

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

func updatePojectConfig(workDir, host, cur_branch, groupName string) error {
data, err := ioutil.ReadFile(path.Join(workDir, projectConfigFile))
data, err := os.ReadFile(path.Join(workDir, projectConfigFile))
if err != nil {
return fmt.Errorf("failed to read project.config file: %w", err)
}
Expand All @@ -364,7 +363,7 @@ func updatePojectConfig(workDir, host, cur_branch, groupName string) error {
if err != nil {
return fmt.Errorf("failed to ensure updated project config: %w", err)
}
err = ioutil.WriteFile(path.Join(workDir, projectConfigFile), []byte(newData), 0755)
err = os.WriteFile(path.Join(workDir, projectConfigFile), []byte(newData), 0755)
if err != nil {
return fmt.Errorf("failed to write groups file: %w", err)
}
Expand Down Expand Up @@ -453,7 +452,7 @@ func main() {
logrus.Fatal(err)
}
} else {
workDir, err = ioutil.TempDir("", "gerrit_onboarding")
workDir, err = os.MkdirTemp("", "gerrit_onboarding")
if err != nil {
logrus.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions experiment/image-bumper/bumper/bumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package bumper
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -262,14 +262,14 @@ func updateAllTags(tagPicker func(host, image, tag string) (string, error), cont
// UpdateFile updates a file in place.
func (cli *Client) UpdateFile(tagPicker func(imageHost, imageName, currentTag string) (string, error),
path string, imageFilter *regexp.Regexp) error {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("failed to read %s: %w", path, err)
}

newContent := updateAllTags(tagPicker, content, imageFilter)

if err := ioutil.WriteFile(path, newContent, 0644); err != nil {
if err := os.WriteFile(path, newContent, 0644); err != nil {
return fmt.Errorf("failed to write %s: %w", path, err)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions experiment/ml/analyze/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -71,7 +71,7 @@ func processRequest(ctx context.Context, storageClient *storage.Client, predicto
if r.ContentLength > maxRequestLen {
return http.StatusBadRequest, "Request too long", fmt.Errorf("%d byte request", r.ContentLength)
}
bytes, err := ioutil.ReadAll(r.Body)
bytes, err := io.ReadAll(r.Body)
if err != nil {
return http.StatusBadRequest, "Could not read request", fmt.Errorf("read request: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions experiment/ml/prowlog/csv/generate-dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -103,7 +102,7 @@ func main() {
continue
}
defer zf.Close()
b, err := ioutil.ReadAll(zf)
b, err := io.ReadAll(zf)
if err != nil {
log.Println("Failed to read eample", f.Name, err)
continue
Expand Down
5 changes: 2 additions & 3 deletions experiment/ml/prowlog/generate-dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -753,11 +752,11 @@ func (bc *buildCache) open(ctx context.Context, client gcs.ConditionalClient, pa
if bc.archivePath == "" {
return r, nil, nil
}
buf, err := ioutil.ReadAll(r)
buf, err := io.ReadAll(r)
if err != nil {
return nil, nil, fmt.Errorf("read: %v", err)
}
f = ioutil.NopCloser(bytes.NewBuffer(buf))
f = io.NopCloser(bytes.NewBuffer(buf))
when = &attrs.LastModified
if err := bc.initAdditional(); err != nil {
return nil, nil, fmt.Errorf("init additional: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions experiment/slack-oncall-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func updateGroupMembership(token, groupID, userID string) error {
}

func getTokenFromPath(path string) (string, error) {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return "", fmt.Errorf("couldn't open file: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions gcsweb/cmd/gcsweb/gcsweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -152,7 +151,7 @@ func getStorageClient(o options) (*storage.Client, error) {
}

if o.oauthTokenFile != "" {
b, err := ioutil.ReadFile(o.oauthTokenFile)
b, err := os.ReadFile(o.oauthTokenFile)
if err != nil {
return nil, fmt.Errorf("error reading oauth token file %s: %w", o.oauthTokenFile, err)
}
Expand Down
9 changes: 4 additions & 5 deletions gencred/cmd/gencred/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -143,7 +142,7 @@ func (o *options) defaultAndValidateFlags() (*config, error) {
var c config
if len(o.config) > 0 {
// Load from config yaml file
body, err := ioutil.ReadFile(o.config)
body, err := os.ReadFile(o.config)
if err != nil {
util.PrintErrAndExit(err)
}
Expand Down Expand Up @@ -194,13 +193,13 @@ func (o *options) defaultAndValidateFlags() (*config, error) {

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

err = ioutil.WriteFile(tmpFile.Name(), kubeconfig, 0644)
err = os.WriteFile(tmpFile.Name(), kubeconfig, 0644)
if err != nil {
return nil, &util.ExitError{Message: err.Error(), Code: 1}
}
Expand Down Expand Up @@ -257,7 +256,7 @@ func writeConfig(c clusterConfig, clientset kubernetes.Interface) error {
}
}

if err = ioutil.WriteFile(*c.Output, kubeconfig, 0644); err != nil {
if err = os.WriteFile(*c.Output, kubeconfig, 0644); err != nil {
return &util.ExitError{Message: fmt.Sprintf("unable to write to file %v: %v.", file, err), Code: 1}
}
}
Expand Down
3 changes: 1 addition & 2 deletions gencred/cmd/gencred/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package gencred

import (
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestValidateFlags(t *testing.T) {
if len(test.config) > 0 {
tmpDir := t.TempDir()
tmpFile := path.Join(tmpDir, test.name+".yaml")
if err := ioutil.WriteFile(tmpFile, []byte(test.config), 0644); err != nil {
if err := os.WriteFile(tmpFile, []byte(test.config), 0644); err != nil {
t.Fatalf("Failed writing tmp file: %v", err)
}
os.Args = append(os.Args, "--config="+tmpFile)
Expand Down
Loading

0 comments on commit 3da4a9c

Please sign in to comment.