Skip to content

Commit

Permalink
fix(grpc): replace grpc.Dial with grpc.NewClient
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit authored and mergify[bot] committed Aug 18, 2024
1 parent 16f0b4f commit f436656
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions pkg/backend/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL)
Expand All @@ -67,7 +67,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL)
Expand All @@ -88,7 +88,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL)
Expand Down Expand Up @@ -118,7 +118,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL)
Expand All @@ -141,7 +141,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL)
Expand Down Expand Up @@ -257,7 +257,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return errors.Wrapf(err, "failed connecting to ReplicaService %v", r.replicaServiceURL)
Expand Down Expand Up @@ -289,7 +289,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return errors.Wrapf(err, "failed connecting to ReplicaService %v", r.replicaServiceURL)
Expand All @@ -314,7 +314,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
Expand All @@ -338,7 +338,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
Expand All @@ -360,7 +360,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()),
ptypes.WithIdentityValidationClientInterceptor(r.volumeName, ""))
if err != nil {
return nil, errors.Wrapf(err, "cannot connect to ReplicaService %v", r.replicaServiceURL)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/client/controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
ptypes.WithIdentityValidationClientInterceptor(volumeName, instanceName))
if err != nil {
return ControllerServiceContext{}, errors.Wrapf(err, "cannot connect to ControllerService %v", serviceUrl)
Expand Down Expand Up @@ -411,7 +411,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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/replica/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewReplicaClient(address, volumeName, instanceName string) (*ReplicaClient,
// for the longhorn-manager which executes these command as binaries invocations
func (c *ReplicaClient) getReplicaServiceClient() (ptypes.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()),
ptypes.WithIdentityValidationClientInterceptor(c.volumeName, c.instanceName))
if err != nil {
return err
Expand All @@ -112,7 +112,7 @@ func (c *ReplicaClient) getReplicaServiceClient() (ptypes.ReplicaServiceClient,
// for the longhorn-manager which executes these command as binaries invocations
func (c *ReplicaClient) getSyncServiceClient() (ptypes.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()),
ptypes.WithIdentityValidationClientInterceptor(c.volumeName, c.instanceName))
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions pkg/sync/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,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()),
ptypes.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress)
Expand All @@ -989,7 +989,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()),
ptypes.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress)
Expand Down Expand Up @@ -1291,7 +1291,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()),
ptypes.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress)
Expand All @@ -1312,7 +1312,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()),
ptypes.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress)
Expand Down Expand Up @@ -1363,7 +1363,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()),
ptypes.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress)
Expand All @@ -1385,7 +1385,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()),
ptypes.WithIdentityValidationClientInterceptor(s.volumeName, s.instanceName))
if err != nil {
return errors.Wrapf(err, "cannot connect to ReplicaService %v", s.replicaAddress)
Expand Down

0 comments on commit f436656

Please sign in to comment.