Skip to content

Commit

Permalink
Remove deprecated grpc.Dial use, replace with grpc.NewClient
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Jun 10, 2024
1 parent bee4d4b commit ff488d7
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 @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
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()),
interceptor.WithIdentityValidationClientInterceptor(volumeName, instanceName))
if err != nil {
return ControllerServiceContext{}, errors.Wrapf(err, "cannot connect to ControllerService %v", serviceUrl)
Expand Down Expand Up @@ -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)
}
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 @@ -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
Expand All @@ -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
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 @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit ff488d7

Please sign in to comment.