Skip to content

Commit

Permalink
Add FetchCluster method to runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrisker committed Jun 28, 2022
1 parent b75c278 commit ef9507c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/rosa/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rosa
import (
"os"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/openshift/rosa/pkg/aws"
"github.com/openshift/rosa/pkg/logging"
"github.com/openshift/rosa/pkg/ocm"
Expand All @@ -17,6 +18,7 @@ type Runtime struct {
AWSClient aws.Client
Creator *aws.Creator
ClusterKey string
Cluster *cmv1.Cluster
}

func NewRuntime() *Runtime {
Expand Down Expand Up @@ -67,3 +69,30 @@ func (r *Runtime) GetClusterKey() string {
r.ClusterKey = clusterKey
return clusterKey
}

func (r *Runtime) FetchCluster() *cmv1.Cluster {
if r.Cluster != nil {
return r.Cluster
}

// We don't want to lazy init the OCM client since it requires cleanup
if r.OCMClient == nil {
r.Reporter.Errorf("Tried to fetch a cluster without initializing the OCM client, exiting.")
os.Exit(1)
}
if r.ClusterKey == "" {
r.GetClusterKey()
}
if r.Creator == nil {
r.WithAWS()
}

r.Reporter.Debugf("Loading cluster '%s'", r.ClusterKey)
cluster, err := r.OCMClient.GetCluster(r.ClusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", r.ClusterKey, err)
os.Exit(1)
}
r.Cluster = cluster
return cluster
}

0 comments on commit ef9507c

Please sign in to comment.