Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve GetCluster message when Subscription exists but is inactive #518

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,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 @@ -164,7 +163,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