From 6b01e809fe13fc10cdacda25a60adabeec6f8487 Mon Sep 17 00:00:00 2001 From: Chiman Jain Date: Tue, 5 May 2026 09:58:40 +0530 Subject: [PATCH] remove reference of deprecated ioutil package and grpc methods --- driver/mock.go | 3 ++- pkg/sanity/sanity.go | 13 ++++++------- test/driver_test.go | 7 ++++--- utils/grpcutil.go | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/driver/mock.go b/driver/mock.go index c9088542..fd532678 100644 --- a/driver/mock.go +++ b/driver/mock.go @@ -21,6 +21,7 @@ import ( "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" "github.com/kubernetes-csi/csi-test/v5/utils" ) @@ -91,7 +92,7 @@ func (m *MockCSIDriver) Nexus() (*grpc.ClientConn, error) { } // Create a client connection - m.conn, err = utils.Connect(m.Address(), grpc.WithInsecure()) + m.conn, err = utils.Connect(m.Address(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, err } diff --git a/pkg/sanity/sanity.go b/pkg/sanity/sanity.go index b57d76dc..119bb6e0 100644 --- a/pkg/sanity/sanity.go +++ b/pkg/sanity/sanity.go @@ -20,7 +20,6 @@ import ( "context" "crypto/rand" "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -30,6 +29,7 @@ import ( yaml "gopkg.in/yaml.v2" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -72,7 +72,7 @@ type TestConfig struct { Address string // DialOptions specifies the options that are to be used - // when connecting to Address. The default is grpc.WithInsecure(). + // when connecting to Address. The default is grpc.WithTransportCredentials(insecure.NewCredentials()). // A dialer will be added for Unix Domain Sockets. DialOptions []grpc.DialOption @@ -204,8 +204,8 @@ func NewTestConfig() TestConfig { IdempotentCount: 10, CheckPathCmdTimeout: 10 * time.Second, - DialOptions: []grpc.DialOption{grpc.WithInsecure(), grpc.WithAuthority("localhost")}, - ControllerDialOptions: []grpc.DialOption{grpc.WithInsecure(), grpc.WithAuthority("localhost")}, + DialOptions: []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithAuthority("localhost")}, + ControllerDialOptions: []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithAuthority("localhost")}, } } @@ -340,7 +340,6 @@ func (sc *TestContext) Finalize() { // target path using a custom command, custom function or falls back to the // default using mkdir and returns the new target path. func createMountTargetLocation(targetPath string, createPathCmd string, customCreateDir func(string) (string, error), timeout time.Duration) (string, error) { - // Return the target path if empty. if targetPath == "" { return targetPath, nil @@ -413,7 +412,7 @@ func removeMountTargetLocation(targetPath string, removePathCmd string, customRe func loadSecrets(path string) (*CSISecrets, error) { var creds CSISecrets - yamlFile, err := ioutil.ReadFile(path) + yamlFile, err := os.ReadFile(path) if err != nil { return &creds, fmt.Errorf("failed to read file %q: #%v", path, err) } @@ -429,7 +428,7 @@ func loadSecrets(path string) (*CSISecrets, error) { // loadFromFile reads struct from given file path. func loadFromFile(from string, to interface{}) { if len(from) != 0 { - yamlFile, err := ioutil.ReadFile(from) + yamlFile, err := os.ReadFile(from) if err != nil { panic(fmt.Sprintf("failed to read file %q: %v", from, err)) } diff --git a/test/driver_test.go b/test/driver_test.go index 6edbf45d..544ba750 100644 --- a/test/driver_test.go +++ b/test/driver_test.go @@ -24,6 +24,7 @@ import ( "github.com/container-storage-interface/spec/lib/go/csi" "github.com/kubernetes-csi/csi-test/v5/utils" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/reflection" ) @@ -47,7 +48,8 @@ func (s *simpleDriver) Probe(context.Context, *csi.ProbeRequest) (*csi.ProbeResp } func (s *simpleDriver) GetPluginInfo( - context.Context, *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) { + context.Context, *csi.GetPluginInfoRequest, +) (*csi.GetPluginInfoResponse, error) { return &csi.GetPluginInfoResponse{ Name: "simpleDriver", VendorVersion: "0.1.1", @@ -95,7 +97,6 @@ func (s *simpleDriver) Stop() { // Tests func TestSimpleDriver(t *testing.T) { - // Setup simple driver s := &simpleDriver{} err := s.Start() @@ -105,7 +106,7 @@ func TestSimpleDriver(t *testing.T) { defer s.Stop() // Setup a connection to the driver - conn, err := utils.Connect(s.Address(), grpc.WithInsecure()) + conn, err := utils.Connect(s.Address(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { t.Errorf("Error: %s", err.Error()) } diff --git a/utils/grpcutil.go b/utils/grpcutil.go index 3ef7050b..47e82800 100644 --- a/utils/grpcutil.go +++ b/utils/grpcutil.go @@ -38,7 +38,7 @@ func Connect(address string, dialOptions ...grpc.DialOption) (*grpc.ClientConn, })) } - conn, err := grpc.Dial(address, dialOptions...) + conn, err := grpc.NewClient(address, dialOptions...) if err != nil { return nil, err }