Skip to content

Commit 16ccc52

Browse files
olucasfreitashunterkepley
authored andcommitted
OCM-4667 | feat: added new warnings to account-role checks and validation for the red-hat-managed tag
1 parent 7cc0ade commit 16ccc52

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

cmd/create/cluster/cmd.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,8 @@ func run(cmd *cobra.Command, _ []string) {
14481448
os.Exit(1)
14491449
}
14501450

1451+
r.Reporter.Warnf("Account roles not created by ROSA CLI cannot be listed, updated, or upgraded.")
1452+
14511453
if len(roleARNs) > 1 {
14521454
defaultRoleARN := roleARNs[0]
14531455
// Prioritize roles with the default prefix
@@ -1497,13 +1499,18 @@ func run(cmd *cobra.Command, _ []string) {
14971499
if isHostedCP {
14981500
createAccountRolesCommand = createAccountRolesCommand + " " + hostedCPFlag
14991501
}
1500-
r.Reporter.Warnf(fmt.Sprintf("No compatible account roles with version '%s' found. "+
1501-
"You will need to manually set them in the next steps or run '%s' to create them first.",
1502-
minor, createAccountRolesCommand))
1502+
r.Reporter.Warnf("No suitable account with ROSA CLI-created account roles were found. "+
1503+
"You can manually set them in the next steps or run '%s' to create them first.", createAccountRolesCommand)
15031504
interactive.Enable()
15041505
}
15051506

15061507
if roleARN != "" {
1508+
// Check if role has red-hat-managed tag
1509+
hasTag := roles.CheckHasRedHatManagedTag(roleARN, awsClient)
1510+
if !hasTag {
1511+
r.Reporter.Warnf("The role '%s' is not a Red Hat managed role", roleARN)
1512+
}
1513+
15071514
// check if role has hosted cp policy via AWS tag value
15081515
hostedCPPolicies, err := awsClient.HasHostedCPPolicies(roleARN)
15091516
if err != nil {
@@ -1559,13 +1566,18 @@ func run(cmd *cobra.Command, _ []string) {
15591566
if isHostedCP {
15601567
createAccountRolesCommand = createAccountRolesCommand + " " + hostedCPFlag
15611568
}
1562-
r.Reporter.Warnf(fmt.Sprintf("No compatible '%s' account roles with version '%s' found. "+
1563-
"You will need to manually set them in the next steps or run '%s' to create them first.",
1564-
role.Name, minor, createAccountRolesCommand))
1569+
r.Reporter.Warnf("No suitable accounts with ROSA CLI-created account roles were found. "+
1570+
"You can manually set them in the next steps or run '%s' to create them first.", createAccountRolesCommand)
15651571
interactive.Enable()
15661572
hasRoles = false
15671573
break
15681574
}
1575+
1576+
// Check if role has red-hat-managed tag
1577+
hasTag := roles.CheckHasRedHatManagedTag(selectedARN, awsClient)
1578+
if !hasTag {
1579+
r.Reporter.Warnf("The role '%s' is not a Red Hat managed role", selectedARN)
1580+
}
15691581
if !output.HasFlag() || r.Reporter.IsTerminal() {
15701582
r.Reporter.Infof("Using %s for the %s role", selectedARN, role.Name)
15711583
}

pkg/helper/roles/helpers.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ func GetOperatorRoleName(cluster *cmv1.Cluster, missingOperator *cmv1.STSOperato
4343
return awsCommonUtils.TruncateRoleName(role)
4444
}
4545

46+
func CheckHasRedHatManagedTag(arn string, awsClient aws.Client) bool {
47+
roleName, err := awsClient.GetRoleByARN(arn)
48+
if err != nil {
49+
return false
50+
}
51+
52+
roleTags := roleName.Tags
53+
for _, tag := range roleTags {
54+
if *tag.Key == tags.RedHatManaged {
55+
return true
56+
}
57+
}
58+
59+
return false
60+
}
61+
4662
func BuildMissingOperatorRoleCommand(
4763
missingRoles map[string]*cmv1.STSOperator,
4864
cluster *cmv1.Cluster,

0 commit comments

Comments
 (0)