Skip to content

Commit

Permalink
Call remoteAPI.UnregisterGauges() inside NewRemoteClusterServiceWatch…
Browse files Browse the repository at this point in the history
…er instead
  • Loading branch information
alpeb committed Jan 5, 2024
1 parent 999eff3 commit 43fe71c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion multicluster/cmd/service-mirror/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func restartClusterWatcher(
if err != nil {
return fmt.Errorf("unable to parse kube config: %w", err)
}
clusterWatcher, err = servicemirror.NewRemoteClusterServiceWatcher(
cw, err := servicemirror.NewRemoteClusterServiceWatcher(
ctx,
namespace,
controllerK8sAPI,
Expand All @@ -317,6 +317,7 @@ func restartClusterWatcher(
if err != nil {
return fmt.Errorf("unable to create cluster watcher: %w", err)
}
clusterWatcher = cw
err = clusterWatcher.Start(ctx)
if err != nil {
return fmt.Errorf("failed to start cluster watcher: %w", err)
Expand Down
16 changes: 7 additions & 9 deletions multicluster/service-mirror/cluster_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func NewRemoteClusterServiceWatcher(
if err != nil {
return nil, fmt.Errorf("cannot initialize api for target cluster %s: %w", clusterName, err)
}
_, err = remoteAPI.Client.Discovery().ServerVersion()
if err != nil {
remoteAPI.UnregisterGauges()
return nil, fmt.Errorf("cannot connect to api for target cluster %s: %w", clusterName, err)
}

// Create k8s event recorder
eventBroadcaster := record.NewBroadcaster()
Expand All @@ -184,7 +189,7 @@ func NewRemoteClusterServiceWatcher(
})

stopper := make(chan struct{})
rcsw := RemoteClusterServiceWatcher{
return &RemoteClusterServiceWatcher{
serviceMirrorNamespace: serviceMirrorNamespace,
link: link,
remoteAPIClient: remoteAPI,
Expand All @@ -203,14 +208,7 @@ func NewRemoteClusterServiceWatcher(
headlessServicesEnabled: enableHeadlessSvc,
// always instantiate the gatewayAlive=true to prevent unexpected service fail fast
gatewayAlive: true,
}

_, err = remoteAPI.Client.Discovery().ServerVersion()
if err != nil {
return &rcsw, fmt.Errorf("cannot connect to api for target cluster %s: %w", clusterName, err)
}

return &rcsw, nil
}, nil
}

func (rcsw *RemoteClusterServiceWatcher) mirroredResourceName(remoteName string) string {
Expand Down

0 comments on commit 43fe71c

Please sign in to comment.