diff --git a/cmd/describe/cluster/cmd.go b/cmd/describe/cluster/cmd.go index 411a8105f..e3ee08ed0 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 } diff --git a/cmd/list/instancetypes/cmd.go b/cmd/list/instancetypes/cmd.go index c27ba36b9..d876ef235 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 d348570ae..5ccf3d5ba 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() { diff --git a/pkg/info/info.go b/pkg/info/info.go index 602c37295..6d16f73a3 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"