Skip to content

Commit cc836bd

Browse files
committed
Switch from deprecated ioutil to io/os
Signed-off-by: LogicalShark <maralder@google.com>
1 parent 5efae2d commit cc836bd

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

cmd/auth-provider-gcp/app/getcredentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package app
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
22+
"io"
2323
"net/http"
2424
"os"
2525

@@ -112,7 +112,7 @@ func getCredentials(authFlow string) error {
112112
if err != nil {
113113
return err
114114
}
115-
unparsedRequest, err := ioutil.ReadAll(os.Stdin)
115+
unparsedRequest, err := io.ReadAll(os.Stdin)
116116
if err != nil {
117117
return err
118118
}

cmd/gke-gcloud-auth-plugin/cred.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"encoding/json"
1212
"flag"
1313
"fmt"
14-
"io/ioutil"
14+
"os"
1515
"os/exec"
1616
"path/filepath"
1717
"strings"
@@ -369,7 +369,7 @@ func executeCommand(name string, arg ...string) ([]byte, error) {
369369
}
370370

371371
func readFile(filename string) ([]byte, error) {
372-
return ioutil.ReadFile(filename)
372+
return os.ReadFile(filename)
373373
}
374374

375375
func timeNow() time.Time {

pkg/clientauthplugin/gcp/gcp_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package gcp
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"net/http"
2322
"os"
2423
"os/exec"
@@ -160,7 +159,7 @@ func Test_tokenSource_cmdCannotBeUsedWithScopes(t *testing.T) {
160159

161160
func Test_tokenSource_applicationDefaultCredentials_fails(t *testing.T) {
162161
// try to use empty ADC file
163-
fakeTokenFile, err := ioutil.TempFile("", "adctoken")
162+
fakeTokenFile, err := os.CreateTemp("", "adctoken")
164163
if err != nil {
165164
t.Fatalf("failed to create fake token file: +%v", err)
166165
}
@@ -175,13 +174,13 @@ func Test_tokenSource_applicationDefaultCredentials_fails(t *testing.T) {
175174
}
176175

177176
func Test_tokenSource_applicationDefaultCredentials(t *testing.T) {
178-
fakeTokenFile, err := ioutil.TempFile("", "adctoken")
177+
fakeTokenFile, err := os.CreateTemp("", "adctoken")
179178
if err != nil {
180179
t.Fatalf("failed to create fake token file: +%v", err)
181180
}
182181
fakeTokenFile.Close()
183182
defer os.Remove(fakeTokenFile.Name())
184-
if err := ioutil.WriteFile(fakeTokenFile.Name(), []byte(`{"type":"service_account"}`), 0600); err != nil {
183+
if err := os.WriteFile(fakeTokenFile.Name(), []byte(`{"type":"service_account"}`), 0600); err != nil {
185184
t.Fatalf("failed to write to fake token file: %+v", err)
186185
}
187186

pkg/credentialconfig/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"net/http"
2726
"os"
2827
"path/filepath"
@@ -108,7 +107,7 @@ func ReadDockercfgFile(searchPaths []string) (cfg DockerConfig, err error) {
108107
continue
109108
}
110109
klog.V(4).Infof("looking for .dockercfg at %s", absDockerConfigFileLocation)
111-
contents, err := ioutil.ReadFile(absDockerConfigFileLocation)
110+
contents, err := os.ReadFile(absDockerConfigFileLocation)
112111
if os.IsNotExist(err) {
113112
continue
114113
}
@@ -160,7 +159,7 @@ func ReadDockerConfigJSONFile(searchPaths []string) (cfg DockerConfig, err error
160159
func ReadSpecificDockerConfigJSONFile(filePath string) (cfg DockerConfig, err error) {
161160
var contents []byte
162161

163-
if contents, err = ioutil.ReadFile(filePath); err != nil {
162+
if contents, err = os.ReadFile(filePath); err != nil {
164163
return nil, err
165164
}
166165
return readDockerConfigJSONFileFromBytes(contents)
@@ -212,7 +211,7 @@ func ReadURL(url string, client *http.Client, header *http.Header) (body []byte,
212211
}
213212

214213
limitedReader := &io.LimitedReader{R: resp.Body, N: maxReadLength}
215-
contents, err := ioutil.ReadAll(limitedReader)
214+
contents, err := io.ReadAll(limitedReader)
216215
if err != nil {
217216
return nil, err
218217
}

pkg/credentialconfig/config_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package credentialconfig
1919
import (
2020
"encoding/base64"
2121
"encoding/json"
22-
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524
"reflect"
@@ -33,7 +32,7 @@ func TestReadDockerConfigFile(t *testing.T) {
3332
//test dockerconfig json
3433
inputDockerconfigJSONFile := "{ \"auths\": { \"http://foo.example.com\":{\"auth\":\"Zm9vOmJhcgo=\",\"email\":\"foo@example.com\"}}}"
3534

36-
preferredPath, err := ioutil.TempDir("", "test_foo_bar_dockerconfigjson_")
35+
preferredPath, err := os.MkdirTemp("", "test_foo_bar_dockerconfigjson_")
3736
if err != nil {
3837
t.Fatalf("Creating tmp dir fail: %v", err)
3938
return

pkg/gcpcredential/gcpcredential.go

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

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
2221
"net/http"
22+
"os"
2323
"os/exec"
2424
"runtime"
2525
"strings"
@@ -102,7 +102,7 @@ func onGCEVM() bool {
102102
}
103103
name = fields[1]
104104
} else {
105-
data, err := ioutil.ReadFile(GCEProductNameFile)
105+
data, err := os.ReadFile(GCEProductNameFile)
106106
if err != nil {
107107
klog.V(2).Infof("Error while reading product_name: %v", err)
108108
return false

providers/gce/gcpcredential/credentialutil.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"errors"
2222
"fmt"
2323
"io"
24-
"io/ioutil"
2524
"net/http"
2625

2726
"k8s.io/cloud-provider/credentialconfig"
@@ -68,7 +67,7 @@ func ReadURL(url string, client *http.Client, header *http.Header) (body []byte,
6867
}
6968

7069
limitedReader := &io.LimitedReader{R: resp.Body, N: maxReadLength}
71-
contents, err := ioutil.ReadAll(limitedReader)
70+
contents, err := io.ReadAll(limitedReader)
7271
if err != nil {
7372
return nil, err
7473
}

0 commit comments

Comments
 (0)