Skip to content

Commit

Permalink
Merge pull request #518 from cben/GetCluster-inactive-message
Browse files Browse the repository at this point in the history
improve GetCluster message when Subscription exists but is inactive
  • Loading branch information
gdbranco authored Jul 21, 2023
2 parents cc838d8 + 8f622a1 commit 87c91ab
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ func GetCluster(connection *sdk.Connection, key string) (cluster *cmv1.Cluster,

// Try to find a matching subscription:
subsSearch := fmt.Sprintf(
"(display_name = '%s' or cluster_id = '%s' or external_cluster_id = '%s') and "+
"status in ('Reserved', 'Active')",
"(display_name = '%s' or cluster_id = '%s' or external_cluster_id = '%s')",
key, key, key,
)
subsListResponse, err := subsResource.List().
Expand All @@ -182,7 +181,14 @@ func GetCluster(connection *sdk.Connection, key string) (cluster *cmv1.Cluster,
// If there is exactly one matching subscription then return the corresponding cluster:
subsTotal := subsListResponse.Total()
if subsTotal == 1 {
id, ok := subsListResponse.Items().Slice()[0].GetClusterID()
sub := subsListResponse.Items().Slice()[0]
status, ok := sub.GetStatus()
subID, _ := sub.GetID()
if !ok || (status != "Reserved" && status != "Active") {
err = fmt.Errorf("Cluster was %s, see `ocm get subscription %s` for details", status, subID)
return
}
id, ok := sub.GetClusterID()
if ok {
var clusterGetResponse *cmv1.ClusterGetResponse
clusterGetResponse, err = clustersResource.Cluster(id).Get().
Expand Down

0 comments on commit 87c91ab

Please sign in to comment.