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 d8392a5
Show file tree
Hide file tree
Showing 2 changed files with 10 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
17 changes: 8 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 Expand Up @@ -1271,3 +1269,4 @@ func (rcsw *RemoteClusterServiceWatcher) isRemoteDiscovery(l map[string]string)

return remoteDiscoverySelector.Matches(labels.Set(l))
}

0 comments on commit d8392a5

Please sign in to comment.