Skip to content

Commit efa0403

Browse files
bergmannfMateSaary
authored andcommitted
Fallback to deleted_cluster endpoint to get cluster information.
1 parent bc011c0 commit efa0403

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

pkg/utils/utils.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func GetCluster(connection *sdk.Connection, key string) (cluster *cmv1.Cluster,
6767
// Prepare the resources that we will be using:
6868
subsResource := connection.AccountsMgmt().V1().Subscriptions()
6969
clustersResource := connection.ClustersMgmt().V1().Clusters()
70+
deletedClustersResource := connection.ClustersMgmt().V1().DeletedClusters()
7071

7172
// Try to find a matching subscription:
7273
subsSearch := fmt.Sprintf(
@@ -146,6 +147,29 @@ func GetCluster(connection *sdk.Connection, key string) (cluster *cmv1.Cluster,
146147
return
147148
}
148149

150+
// If we get here we might still be able to get some information from the deleted_clusters information:
151+
deletedClustersResponse, err := deletedClustersResource.List().Search(clustersSearch).Size(1).Send()
152+
if err != nil {
153+
err = fmt.Errorf("can't retrieve deleted clusters for key '%s': '%v'", key, err)
154+
return
155+
}
156+
157+
// If there is exactly one cluster matching then return it:
158+
clustersTotal = deletedClustersResponse.Total()
159+
if clustersTotal == 1 {
160+
cluster = deletedClustersResponse.Items().Slice()[0].Cluster()
161+
return
162+
}
163+
164+
// If there are multiple matching clusters then we should report it as an error:
165+
if clustersTotal > 1 {
166+
err = fmt.Errorf(
167+
"there are %d deleted clusters with identifier or name '%s'",
168+
clustersTotal, key,
169+
)
170+
return
171+
}
172+
149173
// If we are here then there are no subscriptions or clusters matching the passed key:
150174
err = fmt.Errorf(
151175
"There are no subscriptions or clusters with identifier or name '%s'",

0 commit comments

Comments
 (0)