Skip to content

Commit 7e9873f

Browse files
committed
Fix critical bug: use correct context when connecting to remote clusters
The operator was using the current-context from the kubeconfig instead of selecting the context that matches the cluster name. This caused all remote clusters to connect to whichever cluster was set as current-context. Now we explicitly set the CurrentContext to match the cluster name before creating the REST config, ensuring each remote cluster uses its own context. This fixes the issue where ottawa cluster was showing 0 routes because it was actually querying the robbinsdale cluster.
1 parent fb837aa commit 7e9873f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

internal/controller/cluster_manager.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,18 @@ func (m *ClusterManager) createClusterClient(ctx context.Context, dashboard *hom
193193
return nil, fmt.Errorf("key %q not found in secret %s", key, clusterCfg.SecretRef.Name)
194194
}
195195

196-
// Parse kubeconfig
197-
restConfig, err := clientcmd.RESTConfigFromKubeConfig(kubeconfigData)
196+
// Parse kubeconfig and use the context matching the cluster name
197+
config, err := clientcmd.Load(kubeconfigData)
198198
if err != nil {
199-
return nil, fmt.Errorf("failed to parse kubeconfig: %w", err)
199+
return nil, fmt.Errorf("failed to load kubeconfig: %w", err)
200+
}
201+
202+
// Override current-context to match the cluster name
203+
config.CurrentContext = clusterCfg.Name
204+
205+
restConfig, err := clientcmd.NewDefaultClientConfig(*config, &clientcmd.ConfigOverrides{}).ClientConfig()
206+
if err != nil {
207+
return nil, fmt.Errorf("failed to create REST config for context %s: %w", clusterCfg.Name, err)
200208
}
201209

202210
// Create client for the remote cluster

0 commit comments

Comments
 (0)