Skip to content

Commit

Permalink
OCM-6697 | fix: upgrade role error should print extra info when invok…
Browse files Browse the repository at this point in the history
…e from upgrade cluster

Signed-off-by: Mike Ng <ming@redhat.com>
  • Loading branch information
mikeshng committed Mar 27, 2024
1 parent 9a635e0 commit 5e85f91
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/upgrade/roles/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func run(cmd *cobra.Command, argv []string) {
LogError(roles.RosaUpgradeAccRolesModeAuto, ocmClient, policyVersion, err, reporter)
if args.isInvokedFromClusterUpgrade {
reporter.Errorf("%s", err)
printClusterUpgradeInfo(mode, reporter)
os.Exit(1)
}
reporter.Errorf("Error upgrading the account role policies: %s", err)
Expand Down Expand Up @@ -417,6 +418,9 @@ func run(cmd *cobra.Command, argv []string) {
)
if err != nil {
r.Reporter.Errorf("%s", err)
if args.isInvokedFromClusterUpgrade {
printClusterUpgradeInfo(mode, reporter)
}
os.Exit(1)
}
}
Expand All @@ -443,6 +447,9 @@ func run(cmd *cobra.Command, argv []string) {
)
if err != nil {
r.Reporter.Errorf("%s", err)
if args.isInvokedFromClusterUpgrade {
printClusterUpgradeInfo(mode, r.Reporter)
}
os.Exit(1)
}
createdMissingRoles++
Expand Down Expand Up @@ -1173,3 +1180,16 @@ func checkPolicyAndClusterVersionCompatibility(policyVersion, clusterVersion str
}
return nil
}

func printClusterUpgradeInfo(mode string, reporter *rprtr.Object) {
if args.isInvokedFromClusterUpgrade && reporter.IsTerminal() {
rolesStr := fmt.Sprintf("rosa upgrade roles -c %s --cluster-version=%s --mode=%s",
args.clusterID, args.clusterUpgradeVersion, mode)
upgradeClusterStr := fmt.Sprintf("rosa upgrade cluster -c %s", args.clusterID)
reporter.Infof("Account/Operator Role policies are not valid with upgrade version %s. "+
"Run the following command(s) to upgrade the roles:\n"+
"\t%s\n\n"+
", then run the upgrade command again:\n"+
"\t%s\n", args.clusterUpgradeVersion, rolesStr, upgradeClusterStr)
}
}

0 comments on commit 5e85f91

Please sign in to comment.