diff --git a/pkg/store/kubeconfig_store_capi.go b/pkg/store/kubeconfig_store_capi.go index 66f74db6..2f42d8fd 100644 --- a/pkg/store/kubeconfig_store_capi.go +++ b/pkg/store/kubeconfig_store_capi.go @@ -94,6 +94,9 @@ func (s *CapiStore) getCapiClient() (client.Client, error) { &clientcmd.ConfigOverrides{}) restConfig, err := clientConfig.ClientConfig() + if err != nil { + return nil, fmt.Errorf("unable to create rest config: %v", err) + } k8sclient, err := client.New(restConfig, client.Options{ Scheme: scheme, @@ -111,6 +114,15 @@ func (s *CapiStore) StartSearch(channel chan SearchResult) { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) defer cancel() + // initialize CAPI client + if err := s.InitializeCapiStore(); err != nil { + channel <- SearchResult{ + KubeconfigPath: "", + Error: err, + } + return + } + // list clusters clusters := &clusterv1beta1.ClusterList{} err := s.Client.List(ctx, clusters) @@ -123,24 +135,33 @@ func (s *CapiStore) StartSearch(channel chan SearchResult) { } for _, cluster := range clusters.Items { + s.Logger.Debug("CAPI: found cluster", "name", cluster.Name, "namespace", cluster.Namespace) + channel <- SearchResult{ - KubeconfigPath: fmt.Sprintf("%s/%s", cluster.Namespace, cluster.Name), + KubeconfigPath: fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name), Error: nil, + Tags: map[string]string{ + "namespace": cluster.Namespace, + "name": cluster.Name, + }, } } } // GetKubeconfigForPath returns the kubeconfig for the path -func (s *CapiStore) GetKubeconfigForPath(path string, _ map[string]string) ([]byte, error) { +func (s *CapiStore) GetKubeconfigForPath(path string, tags map[string]string) ([]byte, error) { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) defer cancel() + s.Logger.Debug("CAPI: GetKubeconfigForPath", "path", path) + obj := client.ObjectKey{ - Namespace: path, - Name: path, + Namespace: tags["namespace"], + Name: tags["name"], } dataBytes, err := utilkubeconfig.FromSecret(ctx, s.Client, obj) if err != nil { + s.Logger.Debug("CAPI: GetKubeconfigForPath", "error", err) return nil, err } return dataBytes, nil