diff --git a/cmd/create/admin/cmd.go b/cmd/create/admin/cmd.go index a3d547c396..0dec27c526 100644 --- a/cmd/create/admin/cmd.go +++ b/cmd/create/admin/cmd.go @@ -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) diff --git a/cmd/create/cluster/cmd.go b/cmd/create/cluster/cmd.go index 1046189c79..2726396d6d 100644 --- a/cmd/create/cluster/cmd.go +++ b/cmd/create/cluster/cmd.go @@ -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) diff --git a/cmd/create/idp/cmd.go b/cmd/create/idp/cmd.go index ba383ee1d3..e4b717a87e 100644 --- a/cmd/create/idp/cmd.go +++ b/cmd/create/idp/cmd.go @@ -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) diff --git a/cmd/create/ingress/cmd.go b/cmd/create/ingress/cmd.go index c587f99ce8..d82adc4a90 100644 --- a/cmd/create/ingress/cmd.go +++ b/cmd/create/ingress/cmd.go @@ -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) diff --git a/cmd/create/machinepool/cmd.go b/cmd/create/machinepool/cmd.go index a985553e14..e515865141 100644 --- a/cmd/create/machinepool/cmd.go +++ b/cmd/create/machinepool/cmd.go @@ -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) diff --git a/cmd/create/oidcprovider/cmd.go b/cmd/create/oidcprovider/cmd.go index ef9522b00b..88feea5770 100644 --- a/cmd/create/oidcprovider/cmd.go +++ b/cmd/create/oidcprovider/cmd.go @@ -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) diff --git a/cmd/create/operatorroles/cmd.go b/cmd/create/operatorroles/cmd.go index 960bceb6f4..f7a522a056 100644 --- a/cmd/create/operatorroles/cmd.go +++ b/cmd/create/operatorroles/cmd.go @@ -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) diff --git a/cmd/describe/admin/cmd.go b/cmd/describe/admin/cmd.go index 6614e10511..1c50407d6a 100644 --- a/cmd/describe/admin/cmd.go +++ b/cmd/describe/admin/cmd.go @@ -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) diff --git a/cmd/describe/cluster/cmd.go b/cmd/describe/cluster/cmd.go index 01aa9cd851..4e79182c59 100644 --- a/cmd/describe/cluster/cmd.go +++ b/cmd/describe/cluster/cmd.go @@ -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) diff --git a/cmd/dlt/accountroles/cmd.go b/cmd/dlt/accountroles/cmd.go index 80320cf462..9ae8d96560 100644 --- a/cmd/dlt/accountroles/cmd.go +++ b/cmd/dlt/accountroles/cmd.go @@ -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) diff --git a/cmd/dlt/admin/cmd.go b/cmd/dlt/admin/cmd.go index 96bc183267..77bc20abc0 100644 --- a/cmd/dlt/admin/cmd.go +++ b/cmd/dlt/admin/cmd.go @@ -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) diff --git a/cmd/dlt/cluster/cmd.go b/cmd/dlt/cluster/cmd.go index e30558edfa..2c958b32e0 100644 --- a/cmd/dlt/cluster/cmd.go +++ b/cmd/dlt/cluster/cmd.go @@ -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) diff --git a/cmd/dlt/idp/cmd.go b/cmd/dlt/idp/cmd.go index 4ac09c6746..182e2842ff 100644 --- a/cmd/dlt/idp/cmd.go +++ b/cmd/dlt/idp/cmd.go @@ -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) diff --git a/cmd/dlt/ingress/cmd.go b/cmd/dlt/ingress/cmd.go index 923fcde12b..d5d24b7cea 100644 --- a/cmd/dlt/ingress/cmd.go +++ b/cmd/dlt/ingress/cmd.go @@ -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) diff --git a/cmd/dlt/machinepool/cmd.go b/cmd/dlt/machinepool/cmd.go index ce3bd107b1..42794d3a7a 100644 --- a/cmd/dlt/machinepool/cmd.go +++ b/cmd/dlt/machinepool/cmd.go @@ -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) diff --git a/cmd/dlt/oidcprovider/cmd.go b/cmd/dlt/oidcprovider/cmd.go index f093449952..ef432dc37e 100644 --- a/cmd/dlt/oidcprovider/cmd.go +++ b/cmd/dlt/oidcprovider/cmd.go @@ -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 "+ @@ -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) diff --git a/cmd/dlt/operatorrole/cmd.go b/cmd/dlt/operatorrole/cmd.go index 250b57f74b..dd1de23106 100644 --- a/cmd/dlt/operatorrole/cmd.go +++ b/cmd/dlt/operatorrole/cmd.go @@ -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 "+ @@ -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) diff --git a/cmd/dlt/upgrade/cmd.go b/cmd/dlt/upgrade/cmd.go index 15709cd9ed..fdf4122ba0 100644 --- a/cmd/dlt/upgrade/cmd.go +++ b/cmd/dlt/upgrade/cmd.go @@ -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) diff --git a/cmd/edit/addon/cmd.go b/cmd/edit/addon/cmd.go index 25a1304fd7..cf35e2d3bc 100644 --- a/cmd/edit/addon/cmd.go +++ b/cmd/edit/addon/cmd.go @@ -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) @@ -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) @@ -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) diff --git a/cmd/edit/cluster/cmd.go b/cmd/edit/cluster/cmd.go index 83a04d0d3b..ece580d8ba 100644 --- a/cmd/edit/cluster/cmd.go +++ b/cmd/edit/cluster/cmd.go @@ -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) @@ -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) diff --git a/cmd/edit/ingress/cmd.go b/cmd/edit/ingress/cmd.go index 6de8712ad1..0c81632f9c 100644 --- a/cmd/edit/ingress/cmd.go +++ b/cmd/edit/ingress/cmd.go @@ -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) @@ -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) diff --git a/cmd/edit/machinepool/cmd.go b/cmd/edit/machinepool/cmd.go index f5d7d8a7e9..2031992c37 100644 --- a/cmd/edit/machinepool/cmd.go +++ b/cmd/edit/machinepool/cmd.go @@ -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) @@ -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) diff --git a/cmd/grant/user/cmd.go b/cmd/grant/user/cmd.go index 0d46f0d7b9..0823d3731d 100644 --- a/cmd/grant/user/cmd.go +++ b/cmd/grant/user/cmd.go @@ -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) diff --git a/cmd/hibernate/cluster/cmd.go b/cmd/hibernate/cluster/cmd.go index d0989e10e1..ccb4591f63 100644 --- a/cmd/hibernate/cluster/cmd.go +++ b/cmd/hibernate/cluster/cmd.go @@ -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) diff --git a/cmd/initialize/cmd.go b/cmd/initialize/cmd.go index e9f52892ec..871f27dccf 100644 --- a/cmd/initialize/cmd.go +++ b/cmd/initialize/cmd.go @@ -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. "+ @@ -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) } @@ -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 @@ -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 } diff --git a/cmd/install/addon/cmd.go b/cmd/install/addon/cmd.go index ead38ebed4..cc8d1f9604 100644 --- a/cmd/install/addon/cmd.go +++ b/cmd/install/addon/cmd.go @@ -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) @@ -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) @@ -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) diff --git a/cmd/list/addon/cmd.go b/cmd/list/addon/cmd.go index 2dace831e7..1c8f8b02d6 100644 --- a/cmd/list/addon/cmd.go +++ b/cmd/list/addon/cmd.go @@ -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) diff --git a/cmd/list/cluster/cmd.go b/cmd/list/cluster/cmd.go index 62cfaded57..fa0e2293ab 100644 --- a/cmd/list/cluster/cmd.go +++ b/cmd/list/cluster/cmd.go @@ -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) diff --git a/cmd/list/gates/cmd.go b/cmd/list/gates/cmd.go index ee455696b0..31c3841037 100644 --- a/cmd/list/gates/cmd.go +++ b/cmd/list/gates/cmd.go @@ -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) diff --git a/cmd/list/idp/cmd.go b/cmd/list/idp/cmd.go index 5bf74b78d2..983f792d8c 100644 --- a/cmd/list/idp/cmd.go +++ b/cmd/list/idp/cmd.go @@ -89,7 +89,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) diff --git a/cmd/list/ingress/cmd.go b/cmd/list/ingress/cmd.go index 73f3c210e7..7b27b0a264 100644 --- a/cmd/list/ingress/cmd.go +++ b/cmd/list/ingress/cmd.go @@ -89,7 +89,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) diff --git a/cmd/list/machinepool/cmd.go b/cmd/list/machinepool/cmd.go index 8c744def56..62b9706f26 100644 --- a/cmd/list/machinepool/cmd.go +++ b/cmd/list/machinepool/cmd.go @@ -89,7 +89,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) diff --git a/cmd/list/upgrade/cmd.go b/cmd/list/upgrade/cmd.go index 2d5abc18b1..684e107b99 100644 --- a/cmd/list/upgrade/cmd.go +++ b/cmd/list/upgrade/cmd.go @@ -86,7 +86,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) diff --git a/cmd/list/user/cmd.go b/cmd/list/user/cmd.go index b4d6f13af8..c46e295fc7 100644 --- a/cmd/list/user/cmd.go +++ b/cmd/list/user/cmd.go @@ -87,7 +87,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) diff --git a/cmd/logs/install/cmd.go b/cmd/logs/install/cmd.go index 9dcfcbbbb1..e38a5a4691 100644 --- a/cmd/logs/install/cmd.go +++ b/cmd/logs/install/cmd.go @@ -126,7 +126,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) diff --git a/cmd/logs/uninstall/cmd.go b/cmd/logs/uninstall/cmd.go index 5ab3ceb27b..2e308462fc 100644 --- a/cmd/logs/uninstall/cmd.go +++ b/cmd/logs/uninstall/cmd.go @@ -126,7 +126,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) diff --git a/cmd/resume/cluster/cmd.go b/cmd/resume/cluster/cmd.go index a26bc76e11..1cfc37178f 100644 --- a/cmd/resume/cluster/cmd.go +++ b/cmd/resume/cluster/cmd.go @@ -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) diff --git a/cmd/revoke/user/cmd.go b/cmd/revoke/user/cmd.go index fb393ae9c3..faf4ca6465 100644 --- a/cmd/revoke/user/cmd.go +++ b/cmd/revoke/user/cmd.go @@ -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) diff --git a/cmd/uninstall/addon/cmd.go b/cmd/uninstall/addon/cmd.go index 5b5ed56cc6..683b60339e 100644 --- a/cmd/uninstall/addon/cmd.go +++ b/cmd/uninstall/addon/cmd.go @@ -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) @@ -107,7 +107,7 @@ func run(_ *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 not installed on cluster '%s'", addOnID, clusterKey) os.Exit(0) @@ -118,7 +118,7 @@ func run(_ *cobra.Command, argv []string) { } reporter.Debugf("Uninstalling add-on '%s' from cluster '%s'", addOnID, clusterKey) - err = ocmClient.UninstallAddOn(clusterKey, awsCreator, addOnID) + err = ocmClient.UninstallAddOn(clusterKey, awsCreator.AccountID, addOnID) if err != nil { reporter.Errorf("Failed to remove add-on installation '%s' from cluster '%s': %s", addOnID, clusterKey, err) os.Exit(1) diff --git a/cmd/upgrade/cluster/cmd.go b/cmd/upgrade/cluster/cmd.go index e0954fd88d..bae38cd4f5 100644 --- a/cmd/upgrade/cluster/cmd.go +++ b/cmd/upgrade/cluster/cmd.go @@ -155,7 +155,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) @@ -425,7 +425,7 @@ func run(cmd *cobra.Command, _ []string) { os.Exit(1) } - err = ocmClient.UpdateCluster(cluster.ID(), awsCreator, clusterSpec) + err = ocmClient.UpdateCluster(cluster.ID(), awsCreator.AccountID, clusterSpec) if err != nil { reporter.Errorf("Failed to update cluster '%s': %v", clusterKey, err) os.Exit(1) diff --git a/cmd/upgrade/operatorroles/cmd.go b/cmd/upgrade/operatorroles/cmd.go index 827ee1dd10..80d46818d5 100644 --- a/cmd/upgrade/operatorroles/cmd.go +++ b/cmd/upgrade/operatorroles/cmd.go @@ -125,7 +125,7 @@ func run(cmd *cobra.Command, argv []string) error { // 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) diff --git a/pkg/aws/client.go b/pkg/aws/client.go index 57a85db480..af4ae0cac6 100644 --- a/pkg/aws/client.go +++ b/pkg/aws/client.go @@ -19,6 +19,7 @@ package aws import ( "errors" "fmt" + "github.com/openshift/rosa/pkg/helper" "net/http" "os" "strings" @@ -85,7 +86,7 @@ type Client interface { ValidateCredentials() (isValid bool, err error) EnsureOsdCcsAdminUser(stackName string, adminUserName string, awsRegion string) (bool, error) DeleteOsdCcsAdminUser(stackName string) error - GetAWSAccessKeys() (*AccessKey, error) + GetAWSAccessKeys() (*helper.AccessKey, error) GetCreator() (*Creator, error) ValidateSCP(*string) (bool, error) GetSubnetIDs() ([]*ec2.Subnet, error) @@ -140,7 +141,7 @@ type Client interface { type ClientBuilder struct { logger *logrus.Logger region *string - credentials *AccessKey + credentials *helper.AccessKey } type awsClient struct { @@ -152,7 +153,7 @@ type awsClient struct { cfClient cloudformationiface.CloudFormationAPI servicequotasClient servicequotasiface.ServiceQuotasAPI awsSession *session.Session - awsAccessKeys *AccessKey + awsAccessKeys *helper.AccessKey } func CreateNewClientOrExit(logger *logrus.Logger, reporter *reporter.Object) Client { @@ -181,7 +182,7 @@ func New( cfClient cloudformationiface.CloudFormationAPI, servicequotasClient servicequotasiface.ServiceQuotasAPI, awsSession *session.Session, - awsAccessKeys *AccessKey, + awsAccessKeys *helper.AccessKey, ) Client { return &awsClient{ @@ -208,14 +209,14 @@ func (b *ClientBuilder) Region(value string) *ClientBuilder { return b } -func (b *ClientBuilder) AccessKeys(value *AccessKey) *ClientBuilder { +func (b *ClientBuilder) AccessKeys(value *helper.AccessKey) *ClientBuilder { // fmt.Printf("Using new access key %s\n", value.AccessKeyID) b.credentials = value return b } // Create AWS session with a specific set of credentials -func (b *ClientBuilder) BuildSessionWithOptionsCredentials(value *AccessKey) (*session.Session, error) { +func (b *ClientBuilder) BuildSessionWithOptionsCredentials(value *helper.AccessKey) (*session.Session, error) { return session.NewSessionWithOptions(session.Options{ Config: aws.Config{ CredentialsChainVerboseErrors: aws.Bool(true), @@ -463,17 +464,12 @@ func (c *awsClient) TagUserRegion(username string, region string) error { return nil } -type AccessKey struct { - AccessKeyID string - SecretAccessKey string -} - // GetAWSAccessKeys uses UpsertAccessKey to delete and create new access keys // for `osdCcsAdmin` each time we use the client to create a cluster. // There is no need to permanently store these credentials since they are only used // on create, the cluster uses a completely different set of IAM credentials // provisioned by this user. -func (c *awsClient) GetAWSAccessKeys() (*AccessKey, error) { +func (c *awsClient) GetAWSAccessKeys() (*helper.AccessKey, error) { if c.awsAccessKeys != nil { return c.awsAccessKeys, nil } @@ -495,7 +491,7 @@ func (c *awsClient) GetAWSAccessKeys() (*AccessKey, error) { // ValidateAccessKeys deals with AWS' eventual consistency, its attempts to call // GetCallerIdentity and will try again if the error is access denied. -func (c *awsClient) ValidateAccessKeys(AccessKey *AccessKey) error { +func (c *awsClient) ValidateAccessKeys(AccessKey *helper.AccessKey) error { logger, err := logging.NewLogger(). Build() if err != nil { @@ -551,7 +547,7 @@ func (c *awsClient) ValidateAccessKeys(AccessKey *AccessKey) error { // UpsertAccessKey first deletes all access keys attached to `username` and then creates a // new access key. DeleteAccessKey ensures we own the user before proceeding to delete // access keys -func (c *awsClient) UpsertAccessKey(username string) (*AccessKey, error) { +func (c *awsClient) UpsertAccessKey(username string) (*helper.AccessKey, error) { err := c.DeleteAccessKeys(username) if err != nil { return nil, err @@ -562,7 +558,7 @@ func (c *awsClient) UpsertAccessKey(username string) (*AccessKey, error) { return nil, err } - return &AccessKey{ + return &helper.AccessKey{ AccessKeyID: *createAccessKeyOutput.AccessKey.AccessKeyId, SecretAccessKey: *createAccessKeyOutput.AccessKey.SecretAccessKey, }, nil diff --git a/pkg/aws/client_test.go b/pkg/aws/client_test.go index 70960a6c7a..328f428abb 100644 --- a/pkg/aws/client_test.go +++ b/pkg/aws/client_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/openshift/rosa/pkg/helper" "github.com/sirupsen/logrus" "github.com/openshift/rosa/pkg/aws" @@ -37,7 +38,7 @@ var _ = Describe("Client", func() { mockCfAPI, mocks.NewMockServiceQuotasAPI(mockCtrl), &session.Session{}, - &aws.AccessKey{}, + &helper.AccessKey{}, ) }) diff --git a/pkg/helper/ocm_aws_helper.go b/pkg/helper/ocm_aws_helper.go new file mode 100644 index 0000000000..46d854a066 --- /dev/null +++ b/pkg/helper/ocm_aws_helper.go @@ -0,0 +1,6 @@ +package helper + +type AccessKey struct { + AccessKeyID string + SecretAccessKey string +} diff --git a/pkg/ocm/addons.go b/pkg/ocm/addons.go index 474c6a74e6..08d591fbcd 100644 --- a/pkg/ocm/addons.go +++ b/pkg/ocm/addons.go @@ -19,8 +19,6 @@ package ocm import ( amsv1 "github.com/openshift-online/ocm-sdk-go/accountsmgmt/v1" cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" - - "github.com/openshift/rosa/pkg/aws" ) type AddOnParam struct { @@ -40,9 +38,9 @@ type ClusterAddOn struct { State string } -func (c *Client) InstallAddOn(clusterKey string, creator *aws.Creator, addOnID string, +func (c *Client) InstallAddOn(clusterKey string, accountID string, addOnID string, params []AddOnParam) error { - cluster, err := c.GetCluster(clusterKey, creator) + cluster, err := c.GetCluster(clusterKey, accountID) if err != nil { return err } @@ -78,8 +76,8 @@ func (c *Client) InstallAddOn(clusterKey string, creator *aws.Creator, addOnID s return nil } -func (c *Client) UninstallAddOn(clusterKey string, creator *aws.Creator, addOnID string) error { - cluster, err := c.GetCluster(clusterKey, creator) +func (c *Client) UninstallAddOn(clusterKey string, accountID string, addOnID string) error { + cluster, err := c.GetCluster(clusterKey, accountID) if err != nil { return err } @@ -98,9 +96,9 @@ func (c *Client) UninstallAddOn(clusterKey string, creator *aws.Creator, addOnID return nil } -func (c *Client) GetAddOnInstallation(clusterKey string, creator *aws.Creator, +func (c *Client) GetAddOnInstallation(clusterKey string, accountID string, addOnID string) (*cmv1.AddOnInstallation, error) { - cluster, err := c.GetCluster(clusterKey, creator) + cluster, err := c.GetCluster(clusterKey, accountID) if err != nil { return nil, err } @@ -119,9 +117,9 @@ func (c *Client) GetAddOnInstallation(clusterKey string, creator *aws.Creator, return response.Body(), nil } -func (c *Client) UpdateAddOnInstallation(clusterKey string, creator *aws.Creator, addOnID string, +func (c *Client) UpdateAddOnInstallation(clusterKey string, accountID string, addOnID string, params []AddOnParam) error { - cluster, err := c.GetCluster(clusterKey, creator) + cluster, err := c.GetCluster(clusterKey, accountID) if err != nil { return err } diff --git a/pkg/ocm/clusters.go b/pkg/ocm/clusters.go index 060454a280..4957a45c97 100644 --- a/pkg/ocm/clusters.go +++ b/pkg/ocm/clusters.go @@ -24,13 +24,12 @@ import ( amv1 "github.com/openshift-online/ocm-sdk-go/accountsmgmt/v1" cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" + errors "github.com/zgalor/weberr" - "github.com/openshift/rosa/pkg/aws" + "github.com/openshift/rosa/pkg/helper" "github.com/openshift/rosa/pkg/info" - "github.com/openshift/rosa/pkg/logging" "github.com/openshift/rosa/pkg/properties" rprtr "github.com/openshift/rosa/pkg/reporter" - errors "github.com/zgalor/weberr" ) var NetworkTypes = []string{"OpenShiftSDN", "OVNKubernetes"} @@ -111,17 +110,17 @@ type OperatorIAMRole struct { } // Generate a query that filters clusters running on the current AWS session account -func getClusterFilter(creator *aws.Creator) string { +func getClusterFilter(accountID string) string { return fmt.Sprintf( "product.id = 'rosa' AND (properties.%s LIKE '%%:%s:%%' OR aws.sts.role_arn LIKE '%%:%s:%%')", properties.CreatorARN, - creator.AccountID, - creator.AccountID, + accountID, + accountID, ) } -func (c *Client) HasClusters(creator *aws.Creator) (bool, error) { - query := getClusterFilter(creator) +func (c *Client) HasClusters(accountID string) (bool, error) { + query := getClusterFilter(accountID) response, err := c.ocm.ClustersMgmt().V1().Clusters(). List(). Search(query). @@ -135,22 +134,8 @@ func (c *Client) HasClusters(creator *aws.Creator) (bool, error) { return response.Total() > 0, nil } -func (c *Client) CreateCluster(config Spec) (*cmv1.Cluster, error) { - logger, err := logging.NewLogger(). - Build() - if err != nil { - return nil, fmt.Errorf("Unable to create AWS logger: %v", err) - } - - // Create the AWS client: - awsClient, err := aws.NewClient(). - Logger(logger). - Build() - if err != nil { - return nil, fmt.Errorf("Failed to create AWS client: %v", err) - } - - spec, err := c.createClusterSpec(config, awsClient) +func (c *Client) CreateCluster(config Spec, accountID string, arn string, accessKey helper.AccessKey) (*cmv1.Cluster, error) { + spec, err := c.createClusterSpec(config, accountID, arn, accessKey) if err != nil { return nil, fmt.Errorf("Unable to create cluster spec: %v", err) } @@ -178,12 +163,12 @@ func (c *Client) CreateCluster(config Spec) (*cmv1.Cluster, error) { /** pass 0 to get all clusters */ -func (c *Client) GetClusters(creator *aws.Creator, count int) (clusters []*cmv1.Cluster, err error) { +func (c *Client) GetClusters(accountID string, count int) (clusters []*cmv1.Cluster, err error) { if count < 0 { err = errors.Errorf("Invalid Cluster count") return } - query := getClusterFilter(creator) + query := getClusterFilter(accountID) request := c.ocm.ClustersMgmt().V1().Clusters().List().Search(query) page := 1 for { @@ -208,8 +193,8 @@ func (c *Client) GetClusters(creator *aws.Creator, count int) (clusters []*cmv1. return clusters, nil } -func (c *Client) GetAllClusters(creator *aws.Creator) (clusters []*cmv1.Cluster, err error) { - query := getClusterFilter(creator) +func (c *Client) GetAllClusters(accountID string) (clusters []*cmv1.Cluster, err error) { + query := getClusterFilter(accountID) request := c.ocm.ClustersMgmt().V1().Clusters().List().Search(query) response, err := request.Send() @@ -219,9 +204,9 @@ func (c *Client) GetAllClusters(creator *aws.Creator) (clusters []*cmv1.Cluster, return response.Items().Slice(), nil } -func (c *Client) GetCluster(clusterKey string, creator *aws.Creator) (*cmv1.Cluster, error) { +func (c *Client) GetCluster(clusterKey string, accountID string) (*cmv1.Cluster, error) { query := fmt.Sprintf("%s AND (id = '%s' OR name = '%s' OR external_id = '%s')", - getClusterFilter(creator), + getClusterFilter(accountID), clusterKey, clusterKey, clusterKey, ) response, err := c.ocm.ClustersMgmt().V1().Clusters().List(). @@ -243,9 +228,9 @@ func (c *Client) GetCluster(clusterKey string, creator *aws.Creator) (*cmv1.Clus } } -func (c *Client) GetClusterByID(clusterKey string, creator *aws.Creator) (*cmv1.Cluster, error) { +func (c *Client) GetClusterByID(clusterKey string, accountID string) (*cmv1.Cluster, error) { query := fmt.Sprintf("%s AND id = '%s'", - getClusterFilter(creator), + getClusterFilter(accountID), clusterKey, ) response, err := c.ocm.ClustersMgmt().V1().Clusters().List(). @@ -267,7 +252,7 @@ func (c *Client) GetClusterByID(clusterKey string, creator *aws.Creator) (*cmv1. } } -func (c *Client) GetClusterUsingSubscription(clusterKey string, creator *aws.Creator) (*amv1.Subscription, error) { +func (c *Client) GetClusterUsingSubscription(clusterKey string, accountID string) (*amv1.Subscription, error) { query := fmt.Sprintf("plan.id = 'MOA' AND (display_name = '%s' OR "+ "cluster_id = '%s') AND status = 'Deprovisioned'", clusterKey, clusterKey) response, err := c.ocm.AccountsMgmt().V1().Subscriptions().List(). @@ -291,11 +276,11 @@ func (c *Client) GetClusterUsingSubscription(clusterKey string, creator *aws.Cre } // Gets only pending non-STS clusters that are installed in the same AWS account -func (c *Client) GetPendingClusterForARN(creator *aws.Creator) (cluster *cmv1.Cluster, err error) { +func (c *Client) GetPendingClusterForARN(accountID string) (cluster *cmv1.Cluster, err error) { query := fmt.Sprintf( "state = 'pending' AND product.id = 'rosa' AND aws.sts.role_arn = '' AND properties.%s LIKE '%%:%s:%%'", properties.CreatorARN, - creator.AccountID, + accountID, ) request := c.ocm.ClustersMgmt().V1().Clusters().List().Search(query) @@ -306,7 +291,7 @@ func (c *Client) GetPendingClusterForARN(creator *aws.Creator) (cluster *cmv1.Cl return response.Items().Get(0), nil } -func (c *Client) IsSTSClusterExists(creator *aws.Creator, count int, roleARN string) (exists bool, err error) { +func (c *Client) IsSTSClusterExists(accountID string, count int, roleARN string) (exists bool, err error) { if count < 1 { err = errors.Errorf("Cannot fetch fewer than 1 cluster") return @@ -319,7 +304,7 @@ func (c *Client) IsSTSClusterExists(creator *aws.Creator, count int, roleARN str "aws.sts.instance_iam_roles.master_role_arn = '%s' OR "+ "aws.sts.instance_iam_roles.worker_role_arn = '%s')", properties.CreatorARN, - creator.AccountID, + accountID, roleARN, roleARN, roleARN, @@ -361,8 +346,8 @@ func (c *Client) GetClusterState(clusterID string) (cmv1.ClusterState, error) { return response.Body().State(), nil } -func (c *Client) UpdateCluster(clusterKey string, creator *aws.Creator, config Spec) error { - cluster, err := c.GetCluster(clusterKey, creator) +func (c *Client) UpdateCluster(clusterKey string, accountID string, config Spec) error { + cluster, err := c.GetCluster(clusterKey, accountID) if err != nil { return err } @@ -450,8 +435,8 @@ func (c *Client) UpdateCluster(clusterKey string, creator *aws.Creator, config S return nil } -func (c *Client) DeleteCluster(clusterKey string, creator *aws.Creator) (*cmv1.Cluster, error) { - cluster, err := c.GetCluster(clusterKey, creator) +func (c *Client) DeleteCluster(clusterKey string, accountID string) (*cmv1.Cluster, error) { + cluster, err := c.GetCluster(clusterKey, accountID) if err != nil { return nil, err } @@ -467,7 +452,7 @@ func (c *Client) DeleteCluster(clusterKey string, creator *aws.Creator) (*cmv1.C return cluster, nil } -func (c *Client) createClusterSpec(config Spec, awsClient aws.Client) (*cmv1.Cluster, error) { +func (c *Client) createClusterSpec(config Spec, accountID string, arn string, awsAccessKey helper.AccessKey) (*cmv1.Cluster, error) { reporter, err := rprtr.New(). Build() @@ -475,12 +460,6 @@ func (c *Client) createClusterSpec(config Spec, awsClient aws.Client) (*cmv1.Clu return nil, fmt.Errorf("Error creating cluster reporter: %v", err) } - awsCreator, err := awsClient.GetCreator() - if err != nil { - return nil, fmt.Errorf("Failed to get AWS creator: %v", err) - } - - var awsAccessKey *aws.AccessKey if config.RoleARN == "" { /** 1) Poll the cluster with same arn from ocm @@ -489,9 +468,9 @@ func (c *Client) createClusterSpec(config Spec, awsClient aws.Client) (*cmv1.Clu */ deadline := time.Now().Add(5 * time.Minute) for { - pendingCluster, err := c.GetPendingClusterForARN(awsCreator) + pendingCluster, err := c.GetPendingClusterForARN(accountID) if err != nil { - reporter.Errorf("Error getting cluster using ARN '%s'", awsCreator.ARN) + reporter.Errorf("Error getting cluster using ARN '%s'", arn) os.Exit(1) } if time.Now().After(deadline) { @@ -508,14 +487,6 @@ func (c *Client) createClusterSpec(config Spec, awsClient aws.Client) (*cmv1.Clu } } - // Create the access key for the AWS user: - awsAccessKey, err = awsClient.GetAWSAccessKeys() - if err != nil { - return nil, fmt.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) } clusterProperties := map[string]string{} @@ -535,7 +506,7 @@ func (c *Client) createClusterSpec(config Spec, awsClient aws.Client) (*cmv1.Clu return nil, fmt.Errorf("Custom properties key %s collides with a property needed by rosa", properties.CLIVersion) } - clusterProperties[properties.CreatorARN] = awsCreator.ARN + clusterProperties[properties.CreatorARN] = arn clusterProperties[properties.CLIVersion] = info.Version // Create the cluster: @@ -632,7 +603,7 @@ func (c *Client) createClusterSpec(config Spec, awsClient aws.Client) (*cmv1.Clu } awsBuilder := cmv1.NewAWS(). - AccountID(awsCreator.AccountID) + AccountID(accountID) if config.SubnetIds != nil { awsBuilder = awsBuilder.SubnetIDs(config.SubnetIds...) diff --git a/pkg/ocm/flag.go b/pkg/ocm/flag.go index a0be6f704c..4d8be53ae7 100644 --- a/pkg/ocm/flag.go +++ b/pkg/ocm/flag.go @@ -76,7 +76,7 @@ func clusterCompletion(cmd *cobra.Command, args []string, toComplete string) ([] return []string{}, cobra.ShellCompDirectiveDefault } - clusters, err := ocmClient.GetClusters(awsCreator, 10) + clusters, err := ocmClient.GetClusters(awsCreator.AccountID, 10) if err != nil { return []string{}, cobra.ShellCompDirectiveDefault }