@@ -53,15 +53,18 @@ func (c *client) GetOrCreateCksCluster(cluster *clusterv1.Cluster, csCluster *in
5353 if csCluster .Status .CloudStackClusterID != "" {
5454 externalManagedCluster , count , err := c .cs .Kubernetes .GetKubernetesClusterByID (csCluster .Status .CloudStackClusterID , withExternalManaged (), cloudstack .WithProject (c .user .Project .ID ))
5555 if err != nil {
56- return err
56+ return fmt . Errorf ( "failed to get CKS cluster by ID %s: %w" , csCluster . Status . CloudStackClusterID , err )
5757 } else if count > 0 {
5858 csCluster .Status .CloudStackClusterID = externalManagedCluster .Id
5959 return nil
6060 }
61+ // Cluster ID is set in status but not found in CloudStack
62+ // This could mean the cluster was deleted externally or doesn't have ExternalManaged type
63+ return fmt .Errorf ("CKS cluster with ID %s not found in CloudStack (expected ExternalManaged type)" , csCluster .Status .CloudStackClusterID )
6164 }
6265
6366 // Check if a cluster exists with the same name
64- clusterName := fmt . Sprintf ( "%s - %s - %s" , cluster .GetName (), csCluster . GetName (), csCluster . GetUID () )
67+ clusterName := cluster .GetName ()
6568 externalManagedCluster , count , err := c .cs .Kubernetes .GetKubernetesClusterByName (clusterName , withExternalManaged (), cloudstack .WithProject (c .user .Project .ID ))
6669 if err != nil && ! strings .Contains (err .Error (), "No match found for " ) {
6770 return err
@@ -81,7 +84,7 @@ func (c *client) GetOrCreateCksCluster(cluster *clusterv1.Cluster, csCluster *in
8184 }
8285 }
8386 // NewCreateKubernetesClusterParams(description string, kubernetesversionid string, name string, serviceofferingid string, size int64, zoneid string) *CreateKubernetesClusterParams
84- params := c .cs .Kubernetes .NewCreateKubernetesClusterParams (fmt .Sprintf ("%s managed by CAPC" , clusterName ), "" , clusterName , "" , 0 , fd .Zone .ID )
87+ params := c .cs .Kubernetes .NewCreateKubernetesClusterParams (fmt .Sprintf ("Cluster %s managed by CAPC" , clusterName ), "" , clusterName , "" , 0 , fd .Zone .ID )
8588
8689 setIfNotEmpty (c .user .Project .ID , params .SetProjectid )
8790 setIfNotEmpty (accountName , params .SetAccount )
0 commit comments