From 7edb0fbbe94741a84dfa131e98ca5c06da9d413d Mon Sep 17 00:00:00 2001 From: Derek Su Date: Mon, 10 Jun 2024 03:39:24 +0000 Subject: [PATCH] Remove deprecated grpc.Dial use, replace with grpc.NewClient Signed-off-by: Derek Su --- pkg/backend/remote/remote.go | 20 ++++++++++---------- pkg/controller/client/controller_client.go | 4 ++-- pkg/replica/client/client.go | 4 ++-- pkg/sync/rpc/server.go | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/backend/remote/remote.go b/pkg/backend/remote/remote.go index 14f50150c..270fe2b90 100644 --- a/pkg/backend/remote/remote.go +++ b/pkg/backend/remote/remote.go @@ -48,7 +48,7 @@ type Remote struct { func (r *Remote) Close() error { logrus.Infof("Closing: %s", r.name) - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL) @@ -68,7 +68,7 @@ func (r *Remote) Close() error { func (r *Remote) open() error { logrus.Infof("Opening remote: %s", r.name) - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL) @@ -89,7 +89,7 @@ func (r *Remote) open() error { func (r *Remote) Snapshot(name string, userCreated bool, created string, labels map[string]string) error { logrus.Infof("Starting to snapshot: %s %s UserCreated %v Created at %v, Labels %v", r.name, name, userCreated, created, labels) - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL) @@ -119,7 +119,7 @@ func (r *Remote) Expand(size int64) (err error) { err = types.WrapError(err, "failed to expand replica %v from remote", r.replicaServiceURL) }() - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL) @@ -142,7 +142,7 @@ func (r *Remote) Expand(size int64) (err error) { func (r *Remote) SetRevisionCounter(counter int64) error { logrus.Infof("Set revision counter of %s to : %v", r.name, counter) - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL) @@ -258,7 +258,7 @@ func (r *Remote) GetUnmapMarkSnapChainRemoved() (bool, error) { func (r *Remote) SetUnmapMarkSnapChainRemoved(enabled bool) error { logrus.Infof("Setting UnmapMarkSnapChainRemoved of %s to : %v", r.name, enabled) - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return errors.Wrapf(err, "failed connecting to ReplicaService %v", r.replicaServiceURL) @@ -290,7 +290,7 @@ func (r *Remote) ResetRebuild() error { logrus.Warnf("Resetting %v rebuild", r.name) - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return errors.Wrapf(err, "failed connecting to ReplicaService %v", r.replicaServiceURL) @@ -315,7 +315,7 @@ func (r *Remote) ResetRebuild() error { func (r *Remote) SetSnapshotMaxCount(count int) error { logrus.Infof("Setting SnapshotMaxCount of %s to : %d", r.name, count) - conn, err := grpc.Dial(r.replicaServiceURL, + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { @@ -339,7 +339,7 @@ func (r *Remote) SetSnapshotMaxCount(count int) error { func (r *Remote) SetSnapshotMaxSize(size int64) error { logrus.Infof("Setting SnapshotMaxSize of %s to : %d", r.name, size) - conn, err := grpc.Dial(r.replicaServiceURL, + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { @@ -361,7 +361,7 @@ func (r *Remote) SetSnapshotMaxSize(size int64) error { } func (r *Remote) info() (*types.ReplicaInfo, error) { - conn, err := grpc.Dial(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(r.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(r.volumeName, "")) if err != nil { return nil, errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL) diff --git a/pkg/controller/client/controller_client.go b/pkg/controller/client/controller_client.go index 40dbf8982..883fc2972 100644 --- a/pkg/controller/client/controller_client.go +++ b/pkg/controller/client/controller_client.go @@ -46,7 +46,7 @@ const ( func NewControllerClient(address, volumeName, instanceName string) (*ControllerClient, error) { getControllerServiceContext := func(serviceUrl string) (ControllerServiceContext, error) { - connection, err := grpc.Dial(serviceUrl, grpc.WithTransportCredentials(insecure.NewCredentials()), + connection, err := grpc.NewClient(serviceUrl, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(volumeName, instanceName)) if err != nil { return ControllerServiceContext{}, errors.Wrapf(err, "cannot connect to ControllerService %v", serviceUrl) @@ -412,7 +412,7 @@ func (c *ControllerClient) VersionDetailGet() (*meta.VersionOutput, error) { } func (c *ControllerClient) Check() error { - conn, err := grpc.Dial(c.serviceURL, grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.NewClient(c.serviceURL, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return errors.Wrapf(err, "cannot connect to ControllerService %v", c.serviceURL) } diff --git a/pkg/replica/client/client.go b/pkg/replica/client/client.go index 1ecb1d40b..a64ed8d94 100644 --- a/pkg/replica/client/client.go +++ b/pkg/replica/client/client.go @@ -92,7 +92,7 @@ func NewReplicaClient(address, volumeName, instanceName string) (*ReplicaClient, // for the longhorn-manager which executes these command as binaries invocations func (c *ReplicaClient) getReplicaServiceClient() (enginerpc.ReplicaServiceClient, error) { err := c.replicaServiceContext.once.Do(func() error { - cc, err := grpc.Dial(c.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + cc, err := grpc.NewClient(c.replicaServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(c.volumeName, c.instanceName)) if err != nil { return err @@ -113,7 +113,7 @@ func (c *ReplicaClient) getReplicaServiceClient() (enginerpc.ReplicaServiceClien // for the longhorn-manager which executes these command as binaries invocations func (c *ReplicaClient) getSyncServiceClient() (enginerpc.SyncAgentServiceClient, error) { err := c.syncServiceContext.once.Do(func() error { - cc, err := grpc.Dial(c.syncAgentServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), + cc, err := grpc.NewClient(c.syncAgentServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(c.volumeName, c.instanceName)) if err != nil { return err diff --git a/pkg/sync/rpc/server.go b/pkg/sync/rpc/server.go index 4540ee46b..d03027d96 100644 --- a/pkg/sync/rpc/server.go +++ b/pkg/sync/rpc/server.go @@ -971,7 +971,7 @@ func (s *SyncAgentServer) postIncrementalRestoreOperations(restoreStatus *replic } func (s *SyncAgentServer) reloadReplica() error { - conn, err := grpc.Dial(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName)) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress) @@ -990,7 +990,7 @@ func (s *SyncAgentServer) reloadReplica() error { } func (s *SyncAgentServer) replicaRevert(name, created string) error { - conn, err := grpc.Dial(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName)) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress) @@ -1292,7 +1292,7 @@ func getSnapshotsInfo(replicaClient *replicaclient.ReplicaClient) (map[string]ty } func (s *SyncAgentServer) markSnapshotAsRemoved(snapshot string) error { - conn, err := grpc.Dial(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName)) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress) @@ -1313,7 +1313,7 @@ func (s *SyncAgentServer) markSnapshotAsRemoved(snapshot string) error { } func (s *SyncAgentServer) processRemoveSnapshot(snapshot string) error { - conn, err := grpc.Dial(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName)) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress) @@ -1364,7 +1364,7 @@ func (s *SyncAgentServer) processRemoveSnapshot(snapshot string) error { } func (s *SyncAgentServer) replaceDisk(source, target string) error { - conn, err := grpc.Dial(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName)) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress) @@ -1386,7 +1386,7 @@ func (s *SyncAgentServer) replaceDisk(source, target string) error { } func (s *SyncAgentServer) rmDisk(disk string) error { - conn, err := grpc.Dial(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), + conn, err := grpc.NewClient(s.replicaAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), interceptor.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName)) if err != nil { return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress)