Skip to content

Commit

Permalink
Migrate from io/ioutil package to io and os packages
Browse files Browse the repository at this point in the history
  • Loading branch information
bells17 committed Sep 12, 2023
1 parent 32c3fb3 commit 5c9c3c3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
"time"

Expand Down Expand Up @@ -107,7 +107,7 @@ func OnConnectionLoss(reconnect func() bool) Option {
func ExitOnConnectionLoss() func() bool {
return func() bool {
terminationMsg := "Lost connection to CSI driver, exiting"
if err := ioutil.WriteFile(terminationLogPath, []byte(terminationMsg), 0644); err != nil {
if err := os.WriteFile(terminationLogPath, []byte(terminationMsg), 0644); err != nil {
klog.Errorf("%s: %s", terminationLogPath, err)
}
klog.Exit(terminationMsg)
Expand Down
3 changes: 1 addition & 2 deletions connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package connection

import (
"context"
"io/ioutil"
"net"
"os"
"path"
Expand All @@ -43,7 +42,7 @@ import (
)

func tmpDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "connect")
dir, err := os.MkdirTemp("", "connect")
require.NoError(t, err, "creating temp directory")
return dir
}
Expand Down
3 changes: 1 addition & 2 deletions leaderelection/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package leaderelection
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"regexp"
Expand Down Expand Up @@ -219,7 +218,7 @@ func inClusterNamespace() string {
return ns
}

if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if data, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
return ns
}
Expand Down
6 changes: 3 additions & 3 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package metrics

import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -506,7 +506,7 @@ func TestRegisterToServer_Noop(t *testing.T) {
t.Fatalf("/metrics response status not 200. Response was: %+v", resp)
}

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

contentBytes, err := ioutil.ReadAll(resp.Body)
contentBytes, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to parse pprof index response. Response was: %+v Error: %v", resp, err)
}
Expand Down
3 changes: 1 addition & 2 deletions rpc/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package rpc
import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"path"
Expand All @@ -40,7 +39,7 @@ import (
)

func tmpDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "connect")
dir, err := os.MkdirTemp("", "connect")
require.NoError(t, err, "creating temp directory")
return dir
}
Expand Down

0 comments on commit 5c9c3c3

Please sign in to comment.