Skip to content

Commit fe25e0b

Browse files
authored
Merge pull request #151 from bells17/migrate-from-ioutil-to-io-os
Migrate from io/ioutil package to io and os packages
2 parents 32c3fb3 + 5c9c3c3 commit fe25e0b

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

connection/connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"io/ioutil"
2423
"net"
24+
"os"
2525
"strings"
2626
"time"
2727

@@ -107,7 +107,7 @@ func OnConnectionLoss(reconnect func() bool) Option {
107107
func ExitOnConnectionLoss() func() bool {
108108
return func() bool {
109109
terminationMsg := "Lost connection to CSI driver, exiting"
110-
if err := ioutil.WriteFile(terminationLogPath, []byte(terminationMsg), 0644); err != nil {
110+
if err := os.WriteFile(terminationLogPath, []byte(terminationMsg), 0644); err != nil {
111111
klog.Errorf("%s: %s", terminationLogPath, err)
112112
}
113113
klog.Exit(terminationMsg)

connection/connection_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package connection
1818

1919
import (
2020
"context"
21-
"io/ioutil"
2221
"net"
2322
"os"
2423
"path"
@@ -43,7 +42,7 @@ import (
4342
)
4443

4544
func tmpDir(t *testing.T) string {
46-
dir, err := ioutil.TempDir("", "connect")
45+
dir, err := os.MkdirTemp("", "connect")
4746
require.NoError(t, err, "creating temp directory")
4847
return dir
4948
}

leaderelection/leader_election.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package leaderelection
1919
import (
2020
"context"
2121
"fmt"
22-
"io/ioutil"
2322
"net/http"
2423
"os"
2524
"regexp"
@@ -219,7 +218,7 @@ func inClusterNamespace() string {
219218
return ns
220219
}
221220

222-
if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
221+
if data, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
223222
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
224223
return ns
225224
}

metrics/metrics_test.go

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

1919
import (
20-
"io/ioutil"
20+
"io"
2121
"net/http"
2222
"net/http/httptest"
2323
"strings"
@@ -506,7 +506,7 @@ func TestRegisterToServer_Noop(t *testing.T) {
506506
t.Fatalf("/metrics response status not 200. Response was: %+v", resp)
507507
}
508508

509-
contentBytes, err := ioutil.ReadAll(resp.Body)
509+
contentBytes, err := io.ReadAll(resp.Body)
510510
if err != nil {
511511
t.Fatalf("Failed to parse metrics response. Response was: %+v Error: %v", resp, err)
512512
}
@@ -572,7 +572,7 @@ func testRegisterPprofToServer_AllEndpointsAvailable(t *testing.T, endpoint stri
572572
t.Fatalf("%s response status not 200. Response was: %+v", endpoint, resp)
573573
}
574574

575-
contentBytes, err := ioutil.ReadAll(resp.Body)
575+
contentBytes, err := io.ReadAll(resp.Body)
576576
if err != nil {
577577
t.Fatalf("Failed to parse pprof index response. Response was: %+v Error: %v", resp, err)
578578
}

rpc/common_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package rpc
1919
import (
2020
"context"
2121
"fmt"
22-
"io/ioutil"
2322
"net"
2423
"os"
2524
"path"
@@ -40,7 +39,7 @@ import (
4039
)
4140

4241
func tmpDir(t *testing.T) string {
43-
dir, err := ioutil.TempDir("", "connect")
42+
dir, err := os.MkdirTemp("", "connect")
4443
require.NoError(t, err, "creating temp directory")
4544
return dir
4645
}

0 commit comments

Comments
 (0)