Skip to content

Commit

Permalink
remove dependency for ocm and aws
Browse files Browse the repository at this point in the history
  • Loading branch information
pvasant committed Apr 4, 2022
1 parent 588fdb5 commit 9acba6f
Show file tree
Hide file tree
Showing 46 changed files with 135 additions and 142 deletions.
2 changes: 1 addition & 1 deletion cmd/create/admin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
11 changes: 10 additions & 1 deletion cmd/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,16 @@ func run(cmd *cobra.Command, _ []string) {
reporter.Infof("To view a list of clusters and their status, run 'rosa list clusters'")
}

_, err = ocmClient.CreateCluster(clusterConfig)
// Create the access key for the AWS user:
awsAccessKey, err := awsClient.GetAWSAccessKeys()
if err != nil {
reporter.Errorf("Failed to get access keys for user '%s': %v",
aws.AdminUserName, err)
}
reporter.Debugf("Access key identifier is '%s'", awsAccessKey.AccessKeyID)
reporter.Debugf("Secret access key is '%s'", awsAccessKey.SecretAccessKey)

_, err = ocmClient.CreateCluster(clusterConfig, awsCreator.AccountID, awsCreator.ARN, *awsAccessKey)
if err != nil {
if args.dryRun {
reporter.Errorf("Creating cluster '%s' should fail: %s", clusterName, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/idp/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/ingress/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/oidcprovider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, creator)
cluster, err := ocmClient.GetCluster(clusterKey, creator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/operatorroles/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, creator)
cluster, err := ocmClient.GetCluster(clusterKey, creator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/describe/admin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/describe/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/accountroles/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func run(cmd *cobra.Command, _ []string) {
reporter.Errorf("Failed to get IAM credentials: %s", err)
os.Exit(1)
}
clusters, err := ocmClient.GetAllClusters(creator)
clusters, err := ocmClient.GetAllClusters(creator.AccountID)
if err != nil {
reporter.Errorf("Error getting clusters %s", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/admin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func run(cmd *cobra.Command, _ []string) {
}

reporter.Debugf("Deleting cluster '%s'", clusterKey)
cluster, err := ocmClient.DeleteCluster(clusterKey, awsCreator)
cluster, err := ocmClient.DeleteCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("%s", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/idp/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func run(_ *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/ingress/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func run(_ *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func run(_ *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/dlt/oidcprovider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
sub, err := ocmClient.GetClusterUsingSubscription(clusterKey, creator)
sub, err := ocmClient.GetClusterUsingSubscription(clusterKey, creator.AccountID)
if err != nil {
if errors.GetType(err) == errors.Conflict {
reporter.Errorf("More than one cluster found with the same name '%s'. Please "+
Expand All @@ -113,7 +113,7 @@ func run(cmd *cobra.Command, argv []string) {
if sub != nil {
clusterID = sub.ClusterID()
}
c, err := ocmClient.GetClusterByID(clusterID, creator)
c, err := ocmClient.GetClusterByID(clusterID, creator.AccountID)
if err != nil {
if errors.GetType(err) != errors.NotFound {
reporter.Errorf("Error validating cluster '%s': %v", clusterKey, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/dlt/operatorrole/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func run(cmd *cobra.Command, argv []string) {
}()

reporter.Debugf("Loading cluster '%s'", clusterKey)
sub, err := ocmClient.GetClusterUsingSubscription(clusterKey, creator)
sub, err := ocmClient.GetClusterUsingSubscription(clusterKey, creator.AccountID)
if err != nil {
if errors.GetType(err) == errors.Conflict {
reporter.Errorf("More than one cluster found with the same name '%s'. Please "+
Expand All @@ -137,7 +137,7 @@ func run(cmd *cobra.Command, argv []string) {
if sub != nil {
clusterID = sub.ClusterID()
}
c, err := ocmClient.GetClusterByID(clusterID, creator)
c, err := ocmClient.GetClusterByID(clusterID, creator.AccountID)
if err != nil {
if errors.GetType(err) != errors.NotFound {
reporter.Errorf("Error validating cluster '%s': %v", clusterKey, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/upgrade/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions cmd/edit/addon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand All @@ -125,7 +125,7 @@ func run(cmd *cobra.Command, argv []string) {
os.Exit(1)
}

addOnInstallation, err := ocmClient.GetAddOnInstallation(clusterKey, awsCreator, addOnID)
addOnInstallation, err := ocmClient.GetAddOnInstallation(clusterKey, awsCreator.AccountID, addOnID)
if err != nil {
reporter.Errorf("Failed to get add-on '%s' installation: %v", addOnID, err)
os.Exit(1)
Expand Down Expand Up @@ -255,7 +255,7 @@ func run(cmd *cobra.Command, argv []string) {
})

reporter.Debugf("Updating add-on parameters for '%s' on cluster '%s'", addOnID, clusterKey)
err = ocmClient.UpdateAddOnInstallation(clusterKey, awsCreator, addOnID, params)
err = ocmClient.UpdateAddOnInstallation(clusterKey, awsCreator.AccountID, addOnID, params)
if err != nil {
reporter.Errorf("Failed to update add-on installation '%s' for cluster '%s': %v", addOnID, clusterKey, err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/edit/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func run(cmd *cobra.Command, _ []string) {
}

reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down Expand Up @@ -493,7 +493,7 @@ func run(cmd *cobra.Command, _ []string) {
}

reporter.Debugf("Updating cluster '%s'", clusterKey)
err = ocmClient.UpdateCluster(clusterKey, awsCreator, clusterConfig)
err = ocmClient.UpdateCluster(clusterKey, awsCreator.AccountID, clusterConfig)
if err != nil {
reporter.Errorf("Failed to update cluster: %v", err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/edit/ingress/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand All @@ -191,7 +191,7 @@ func run(cmd *cobra.Command, argv []string) {
Private: private,
}

err = ocmClient.UpdateCluster(clusterKey, awsCreator, clusterConfig)
err = ocmClient.UpdateCluster(clusterKey, awsCreator.AccountID, clusterConfig)
if err != nil {
reporter.Errorf("Failed to update cluster API on cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/edit/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down Expand Up @@ -209,7 +209,7 @@ func run(cmd *cobra.Command, argv []string) {
}

reporter.Debugf("Updating machine pool '%s' on cluster '%s'", machinePoolID, clusterKey)
err = ocmClient.UpdateCluster(clusterKey, awsCreator, clusterConfig)
err = ocmClient.UpdateCluster(clusterKey, awsCreator.AccountID, clusterConfig)
if err != nil {
reporter.Errorf("Failed to update machine pool '%s' on cluster '%s': %s",
machinePoolID, clusterKey, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/grant/user/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func run(_ *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/hibernate/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func run(cmd *cobra.Command, _ []string) {
}()

// Get the cluster to check the state
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
21 changes: 17 additions & 4 deletions cmd/initialize/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,15 @@ func run(cmd *cobra.Command, argv []string) {
reporter.Infof("Skipping AWS SCP policies check for '%s'...", aws.AdminUserName)
}

// Get creator ARN to determine existing clusters:
awsCreator, err := cfClient.GetCreator()
if err != nil {
reporter.Infof("Failed to get AWS creator: %v", err)
}

// Check whether the user can create a basic cluster
reporter.Infof("Validating cluster creation...")
err = simulateCluster(ocmClient, region.Region())
err = simulateCluster(ocmClient, region.Region(), awsCreator, cfClient)
if err != nil {
ocmClient.LogEvent("ROSAInitDryRunFailed", nil)
reporter.Warnf("Cluster creation failed. "+
Expand All @@ -243,7 +249,7 @@ func deleteStack(awsClient aws.Client, ocmClient *ocm.Client) error {
}

// Check whether the account has clusters:
hasClusters, err := ocmClient.HasClusters(awsCreator)
hasClusters, err := ocmClient.HasClusters(awsCreator.AccountID)
if err != nil {
return fmt.Errorf("Failed to check for clusters: %v", err)
}
Expand All @@ -262,7 +268,7 @@ func deleteStack(awsClient aws.Client, ocmClient *ocm.Client) error {
return nil
}

func simulateCluster(ocmClient *ocm.Client, region string) error {
func simulateCluster(ocmClient *ocm.Client, region string, creator *aws.Creator, awsClient aws.Client) error {
dryRun := true
if region == "" {
region = aws.DefaultRegion
Expand All @@ -273,7 +279,14 @@ func simulateCluster(ocmClient *ocm.Client, region string) error {
DryRun: &dryRun,
}

_, err := ocmClient.CreateCluster(spec)
// Create the access key for the AWS user:
awsAccessKey, err := awsClient.GetAWSAccessKeys()
if err != nil {
return fmt.Errorf("Failed to get access keys for user '%s': %v",
aws.AdminUserName, err)
}

_, err = ocmClient.CreateCluster(spec, creator.AccountID, creator.ARN, *awsAccessKey)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/install/addon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func run(cmd *cobra.Command, argv []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand All @@ -123,7 +123,7 @@ func run(cmd *cobra.Command, argv []string) {
os.Exit(1)
}

addOn, err := ocmClient.GetAddOnInstallation(clusterKey, awsCreator, addOnID)
addOn, err := ocmClient.GetAddOnInstallation(clusterKey, awsCreator.AccountID, addOnID)
if addOn != nil {
reporter.Warnf("Addon '%s' is already installed on cluster '%s'", addOnID, clusterKey)
os.Exit(0)
Expand Down Expand Up @@ -233,7 +233,7 @@ func run(cmd *cobra.Command, argv []string) {
}

reporter.Debugf("Installing add-on '%s' on cluster '%s'", addOnID, clusterKey)
err = ocmClient.InstallAddOn(clusterKey, awsCreator, addOnID, params)
err = ocmClient.InstallAddOn(clusterKey, awsCreator.AccountID, addOnID, params)
if err != nil {
reporter.Errorf("Failed to add add-on installation '%s' for cluster '%s': %v", addOnID, clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/list/addon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func run(_ *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/list/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func run(_ *cobra.Command, _ []string) {
}()

// Retrieve the list of clusters:
clusters, err := ocmClient.GetClusters(awsCreator, 1000)
clusters, err := ocmClient.GetClusters(awsCreator.AccountID, 1000)
if err != nil {
reporter.Errorf("Failed to get clusters: %v", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/list/gates/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func run(cmd *cobra.Command, _ []string) {

// Try to find the cluster:
reporter.Debugf("Loading cluster '%s'", clusterKey)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator)
cluster, err := ocmClient.GetCluster(clusterKey, awsCreator.AccountID)
if err != nil {
reporter.Errorf("Failed to get cluster '%s': %v", clusterKey, err)
os.Exit(1)
Expand Down
Loading

0 comments on commit 9acba6f

Please sign in to comment.