From 9bf274364bebd1d7957b3c1d39d833ba1e62f18e Mon Sep 17 00:00:00 2001 From: Guilherme Branco Date: Thu, 11 Apr 2024 18:23:43 -0300 Subject: [PATCH 1/3] OCM-7412 | fix: list instance types filter by region requires installer role arn --- cmd/list/instancetypes/cmd.go | 63 ++++++++++++++++++++++++++++-- cmd/list/instancetypes/cmd_test.go | 16 +++++--- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/cmd/list/instancetypes/cmd.go b/cmd/list/instancetypes/cmd.go index c27ba36b9d..d876ef2356 100644 --- a/cmd/list/instancetypes/cmd.go +++ b/cmd/list/instancetypes/cmd.go @@ -26,6 +26,9 @@ import ( "github.com/openshift/rosa/pkg/arguments" "github.com/openshift/rosa/pkg/helper" + "github.com/openshift/rosa/pkg/interactive" + "github.com/openshift/rosa/pkg/interactive/confirm" + interactiveRoles "github.com/openshift/rosa/pkg/interactive/roles" "github.com/openshift/rosa/pkg/ocm" "github.com/openshift/rosa/pkg/output" "github.com/openshift/rosa/pkg/rosa" @@ -52,10 +55,46 @@ func init() { initFlags(Cmd) } +var args struct { + region string + installerRoleArn string + externalId string + hostedClusterEnabled bool +} + +const ( + InstallerRoleArnFlag = "role-arn" +) + func initFlags(cmd *cobra.Command) { flags := cmd.Flags() + + flags.BoolVar( + &args.hostedClusterEnabled, + "hosted-cp", + false, + "Enable the use of Hosted Control Planes", + ) + + flags.StringVar( + &args.externalId, + "external-id", + "", + "An optional unique identifier that might be required when you assume a role in another account.", + ) + + // normalizing installer role argument to support deprecated flag + flags.SetNormalizeFunc(arguments.NormalizeFlags) + flags.StringVar( + &args.installerRoleArn, + InstallerRoleArnFlag, + "", + "STS Role ARN with get secrets permission.", + ) + arguments.AddRegionFlag(flags) output.AddFlag(cmd) + confirm.AddFlag(flags) } func run(cmd *cobra.Command, _ []string) { @@ -68,15 +107,33 @@ func run(cmd *cobra.Command, _ []string) { } } +func checkInteractiveModeNeeded(cmd *cobra.Command) { + installerRoleArnNotSet := (!cmd.Flags().Changed(InstallerRoleArnFlag) || args.installerRoleArn == "") && + !confirm.Yes() + if installerRoleArnNotSet { + interactive.Enable() + } +} + func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command) error { + checkInteractiveModeNeeded(cmd) r.Reporter.Debugf("Fetching instance types") - var machineTypes ocm.MachineTypeList if cmd.Flags().Changed("region") { + if interactive.Enabled() || (confirm.Yes() && args.installerRoleArn == "") { + args.installerRoleArn = interactiveRoles. + GetInstallerRoleArn( + r, + cmd, + args.installerRoleArn, + "", + r.AWSClient.FindRoleARNs, + ) + } var availabilityZones []string roleArn := "" - regionList, _, err := r.OCMClient.GetRegionList(false, "", "", "", - r.AWSClient, false, false) + regionList, _, err := r.OCMClient.GetRegionList(false, args.installerRoleArn, args.externalId, "", + r.AWSClient, args.hostedClusterEnabled, false) if err != nil { return err } diff --git a/cmd/list/instancetypes/cmd_test.go b/cmd/list/instancetypes/cmd_test.go index d348570aee..5ccf3d5ba2 100644 --- a/cmd/list/instancetypes/cmd_test.go +++ b/cmd/list/instancetypes/cmd_test.go @@ -179,9 +179,11 @@ var _ = Describe("list instance-types", func() { ] } ` - regionSuccessOutput = `ID CATEGORY CPU_CORES MEMORY + regionSuccessOutput = `INFO: Using fake_installer_arn for the Installer role +ID CATEGORY CPU_CORES MEMORY g4dn.12xlarge accelerated_computing 48 192.0 GiB ` + mockAwsClient *aws.MockClient ) BeforeEach(func() { @@ -226,9 +228,9 @@ g4dn.12xlarge accelerated_computing 48 192.0 GiB } ctrl := gomock.NewController(GinkgoT()) - awsClient := aws.NewMockClient(ctrl) - r.AWSClient = awsClient - awsClient.EXPECT().GetAWSAccessKeys().Return(&aws.AccessKey{ + mockAwsClient = aws.NewMockClient(ctrl) + r.AWSClient = mockAwsClient + mockAwsClient.EXPECT().GetAWSAccessKeys().Return(&aws.AccessKey{ AccessKeyID: "abc123", SecretAccessKey: "abc123", }, nil).AnyTimes() @@ -245,6 +247,8 @@ g4dn.12xlarge accelerated_computing 48 192.0 GiB cmd.Flags().Set("region", "us-east-1") + mockAwsClient.EXPECT().FindRoleARNs(aws.InstallerAccountRole, "").Return([]string{"fake_installer_arn"}, nil) + // POST /api/clusters_mgmt/v1/aws_inquiries/machine_types apiServer.AppendHandlers( RespondWithJSON( @@ -287,6 +291,8 @@ g4dn.12xlarge accelerated_computing 48 192.0 GiB cmd.Flags().Set("region", "us-east-xyz") + mockAwsClient.EXPECT().FindRoleARNs(aws.InstallerAccountRole, "").Return([]string{"fake_installer_arn"}, nil) + // POST /api/clusters_mgmt/v1/aws_inquiries/machine_types apiServer.AppendHandlers( RespondWithJSON( @@ -300,7 +306,7 @@ g4dn.12xlarge accelerated_computing 48 192.0 GiB Expect(err.Error()).To( ContainSubstring("Region 'us-east-xyz' not found.")) Expect(stderr).To(Equal("")) - Expect(stdout).To(Equal("")) + Expect(stdout).To(Equal("INFO: Using fake_installer_arn for the Installer role\n")) }) It("Succeeds", func() { From 55dbdefd63f8c517161246473c6c63b6f78ecd42 Mon Sep 17 00:00:00 2001 From: David Lee Date: Thu, 18 Apr 2024 09:35:31 -0400 Subject: [PATCH 2/3] OCM-6595| chore: 1.2.38-RC2 cut with cherrypicked release blocker --- pkg/info/info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/info/info.go b/pkg/info/info.go index 602c372958..6d16f73a3f 100644 --- a/pkg/info/info.go +++ b/pkg/info/info.go @@ -18,7 +18,7 @@ limitations under the License. package info -const Version = "1.2.38-RC1" +const Version = "1.2.38-RC2" // Build contains the short Git SHA of the CLI at the point it was build. Set via `-ldflags` at build time var Build = "local" From 7c8f7ebc19d0056daa8e2f3a56f9b8d1c1661d5d Mon Sep 17 00:00:00 2001 From: croche Date: Thu, 11 Apr 2024 09:06:10 +0100 Subject: [PATCH 3/3] OCM-7358 | fix: invert describe out for cluster delete protection --- cmd/describe/cluster/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/describe/cluster/cmd.go b/cmd/describe/cluster/cmd.go index 411a8105f7..e3ee08ed00 100644 --- a/cmd/describe/cluster/cmd.go +++ b/cmd/describe/cluster/cmd.go @@ -330,7 +330,7 @@ func run(cmd *cobra.Command, argv []string) { } deleteProtection := DisabledOutput - if !cluster.DeleteProtection().Enabled() { + if cluster.DeleteProtection().Enabled() { deleteProtection = EnabledOutput }