From a5e975860a67eb6cc4e32c86f63ee9c15408d1ce Mon Sep 17 00:00:00 2001 From: Florian Bergmann Date: Wed, 20 May 2026 11:16:51 +0200 Subject: [PATCH] Fallback to deleted_cluster endpoint to get cluster information. --- pkg/utils/utils.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index f5320a08a..65d89c05b 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -67,6 +67,7 @@ func GetCluster(connection *sdk.Connection, key string) (cluster *cmv1.Cluster, // Prepare the resources that we will be using: subsResource := connection.AccountsMgmt().V1().Subscriptions() clustersResource := connection.ClustersMgmt().V1().Clusters() + deletedClustersResource := connection.ClustersMgmt().V1().DeletedClusters() // Try to find a matching subscription: subsSearch := fmt.Sprintf( @@ -146,6 +147,29 @@ func GetCluster(connection *sdk.Connection, key string) (cluster *cmv1.Cluster, return } + // If we get here we might still be able to get some information from the deleted_clusters information: + deletedClustersResponse, err := deletedClustersResource.List().Search(clustersSearch).Size(1).Send() + if err != nil { + err = fmt.Errorf("Can't retrieve deleted clusters for key '%s': '%v'", key, err) + return + } + + // If there is exactly one cluster matching then return it: + clustersTotal = deletedClustersResponse.Total() + if clustersTotal == 1 { + cluster = deletedClustersResponse.Items().Slice()[0].Cluster() + return + } + + // If there are multiple matching clusters then we should report it as an error: + if clustersTotal > 1 { + err = fmt.Errorf( + "There are %d deleted clusters with identifier or name '%s'", + clustersTotal, key, + ) + return + } + // If we are here then there are no subscriptions or clusters matching the passed key: err = fmt.Errorf( "There are no subscriptions or clusters with identifier or name '%s'",