Skip to content

Commit

Permalink
Merge pull request openshift#764 from tbrisker/runtimeck
Browse files Browse the repository at this point in the history
Add cluster lookup methods to runtime
  • Loading branch information
openshift-ci[bot] authored Jun 29, 2022
2 parents 699767f + bd48305 commit 85afa70
Show file tree
Hide file tree
Showing 38 changed files with 131 additions and 456 deletions.
16 changes: 3 additions & 13 deletions cmd/create/admin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,9 @@ func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

cluster := r.FetchCluster()
if cluster.State() != cmv1.ClusterStateReady {
r.Reporter.Errorf("Cluster '%s' is not yet ready", clusterKey)
os.Exit(1)
Expand All @@ -91,6 +80,7 @@ func run(cmd *cobra.Command, _ []string) {

// No cluster admin yet: proceed to create it.
var password string
var err error
passwordArg := args.passwordArg
if len(passwordArg) == 0 {
r.Reporter.Debugf("Generating random password")
Expand Down
16 changes: 3 additions & 13 deletions cmd/create/idp/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,9 @@ func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

cluster := r.FetchCluster()
if cluster.State() != cmv1.ClusterStateReady {
r.Reporter.Errorf("Cluster '%s' is not yet ready", clusterKey)
os.Exit(1)
Expand All @@ -329,6 +318,7 @@ func run(cmd *cobra.Command, _ []string) {
"Any optional fields can be left empty and a default will be selected.")
}

var err error
if interactive.Enabled() {
if idpType == "" {
idpType = validIdps[0]
Expand Down
17 changes: 3 additions & 14 deletions cmd/create/ingress/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

clusterKey := r.GetClusterKey()
var err error
labelMatch := args.labelMatch
if interactive.Enabled() {
labelMatch, err = interactive.GetString(interactive.Input{
Expand All @@ -104,14 +100,7 @@ func run(cmd *cobra.Command, _ []string) {
os.Exit(1)
}

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

cluster := r.FetchCluster()
if cluster.AWS().PrivateLink() {
r.Reporter.Errorf("Cluster '%s' is PrivateLink and does not support creating new ingresses", clusterKey)
os.Exit(1)
Expand Down
16 changes: 3 additions & 13 deletions cmd/create/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,9 @@ func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

cluster := r.FetchCluster()
if cluster.State() != cmv1.ClusterStateReady {
r.Reporter.Errorf("Cluster '%s' is not yet ready", clusterKey)
os.Exit(1)
Expand All @@ -209,6 +198,7 @@ func run(cmd *cobra.Command, _ []string) {
os.Exit(1)
}

var err error
// Machine pool name:
name := strings.Trim(args.name, " \t")
if name == "" && !interactive.Enabled() {
Expand Down
15 changes: 2 additions & 13 deletions cmd/create/oidcprovider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ func run(cmd *cobra.Command, argv []string) {
}
}

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

mode, err := aws.GetMode()
if err != nil {
Expand All @@ -90,14 +86,7 @@ func run(cmd *cobra.Command, argv []string) {
interactive.Enable()
}

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

cluster := r.FetchCluster()
if cluster.AWS().STS().RoleARN() == "" {
r.Reporter.Errorf("Cluster '%s' is not an STS cluster.", clusterKey)
os.Exit(1)
Expand Down
15 changes: 2 additions & 13 deletions cmd/create/operatorroles/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ func run(cmd *cobra.Command, argv []string) {
}
}

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

mode, err := aws.GetMode()
if err != nil {
Expand All @@ -112,14 +108,7 @@ func run(cmd *cobra.Command, argv []string) {
interactive.Enable()
}

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

cluster := r.FetchCluster()
if cluster.AWS().STS().RoleARN() == "" {
r.Reporter.Errorf("Cluster '%s' is not an STS cluster.", clusterKey)
os.Exit(1)
Expand Down
15 changes: 2 additions & 13 deletions cmd/describe/admin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,9 @@ func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

cluster := r.FetchCluster()
if cluster.State() != cmv1.ClusterStateReady {
r.Reporter.Errorf("Cluster '%s' is not yet ready", clusterKey)
os.Exit(1)
Expand Down
15 changes: 2 additions & 13 deletions cmd/describe/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,10 @@ func run(cmd *cobra.Command, argv []string) {
if len(argv) == 1 && !cmd.Flag("cluster").Changed {
clusterKey = argv[0]
} else {
clusterKey, err = ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
clusterKey = r.GetClusterKey()
}

cluster := r.FetchCluster()
var str string
if output.HasFlag() {
err = output.Print(cluster)
Expand Down
12 changes: 6 additions & 6 deletions cmd/describe/installation/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/openshift/rosa/pkg/ocm"
"github.com/openshift/rosa/pkg/rosa"
)

Expand Down Expand Up @@ -69,23 +70,22 @@ func run(_ *cobra.Command, argv []string) {
"Expected the cluster to be specified with the --cluster flag")
os.Exit(1)
}
ocm.SetClusterKey(args.clusterKey)

if args.installationKey == "" {
r.Reporter.Errorf(
"Expected the add-on installation to be specified with the --addon flag")
os.Exit(1)
}

if err := describeAddonInstallation(r, args.clusterKey, args.installationKey); err != nil {
if err := describeAddonInstallation(r, args.installationKey); err != nil {
r.Reporter.Errorf("Failed to describe add-on installation: %v", err)
os.Exit(1)
}
}

func describeAddonInstallation(r *rosa.Runtime, clusterKey string, installationKey string) error {
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
return err
}
func describeAddonInstallation(r *rosa.Runtime, installationKey string) error {
cluster := r.FetchCluster()

installation, err := r.OCMClient.GetAddOnInstallation(cluster.ID(), installationKey)
if err != nil {
Expand Down
15 changes: 2 additions & 13 deletions cmd/dlt/admin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,9 @@ func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

cluster := r.FetchCluster()
if cluster.State() != cmv1.ClusterStateReady {
r.Reporter.Errorf("Cluster '%s' is not yet ready", clusterKey)
os.Exit(1)
Expand Down
6 changes: 1 addition & 5 deletions cmd/dlt/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ func run(cmd *cobra.Command, _ []string) {
r := rosa.NewRuntime().WithAWS().WithOCM()
defer r.Cleanup()

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

if !confirm.Confirm("delete cluster %s", clusterKey) {
os.Exit(0)
Expand Down
15 changes: 2 additions & 13 deletions cmd/dlt/idp/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,9 @@ func run(_ *cobra.Command, argv []string) {

idpName := argv[0]

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

cluster := r.FetchCluster()
// Try to find the identity provider:
r.Reporter.Debugf("Loading identity provider '%s'", idpName)
idps, err := r.OCMClient.GetIdentityProviders(cluster.ID())
Expand Down
15 changes: 2 additions & 13 deletions cmd/dlt/ingress/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,9 @@ func run(_ *cobra.Command, argv []string) {
os.Exit(1)
}

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}

// Try to find the cluster:
r.Reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := r.OCMClient.GetCluster(clusterKey, r.Creator)
if err != nil {
r.Reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

cluster := r.FetchCluster()
// Try to find the ingress:
r.Reporter.Debugf("Loading ingresses for cluster '%s'", clusterKey)
ingresses, err := r.OCMClient.GetIngresses(cluster.ID())
Expand Down
15 changes: 2 additions & 13 deletions cmd/dlt/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,14 @@ func run(_ *cobra.Command, argv []string) {
os.Exit(1)
}

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

if machinePoolID == "Default" {
r.Reporter.Errorf("Machine pool '%s' cannot be deleted from cluster '%s'", machinePoolID, clusterKey)
os.Exit(1)
}

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

cluster := r.FetchCluster()
// Try to find the machine pool:
r.Reporter.Debugf("Loading machine pools for cluster '%s'", clusterKey)
machinePools, err := r.OCMClient.GetMachinePools(cluster.ID())
Expand Down
6 changes: 1 addition & 5 deletions cmd/dlt/oidcprovider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ func run(cmd *cobra.Command, argv []string) {
ocm.SetClusterKey(argv[0])
}

clusterKey, err := ocm.GetClusterKey()
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
clusterKey := r.GetClusterKey()

mode, err := aws.GetMode()
if err != nil {
Expand Down
Loading

0 comments on commit 85afa70

Please sign in to comment.