Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-6391 | fix: Add region deprecation disablement to sub-commands #1992

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions cmd/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3214,30 +3214,19 @@ func run(cmd *cobra.Command, _ []string) {
"for more information.")
}

disableUsage := "Temporarily used for disabling a warning message ran from other commands (no reason to" +
" print for cluster describe called inside cluster create, but there is a use for a lone describe."
var disableRegionDeprecation bool
clusterdescribe.Cmd.LocalFlags().BoolVar(&disableRegionDeprecation, arguments.DisableRegionDeprecationFlagName,
true, disableUsage)
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
hunterkepley marked this conversation as resolved.
Show resolved Hide resolved
clusterdescribe.Cmd.Run(clusterdescribe.Cmd, []string{cluster.ID()})
disableRegionDeprecation = false // No longer disable

if isSTS {
if mode != "" {
if !output.HasFlag() || r.Reporter.IsTerminal() {
r.Reporter.Infof("Preparing to create operator roles.")
}
disableRegionDeprecation = true // disable again
operatorroles.Cmd.LocalFlags().BoolVar(&disableRegionDeprecation, arguments.DisableRegionDeprecationFlagName,
true, disableUsage)
operatorroles.Cmd.Run(operatorroles.Cmd, []string{clusterName, mode, permissionsBoundary})
if !output.HasFlag() || r.Reporter.IsTerminal() {
r.Reporter.Infof("Preparing to create OIDC Provider.")
}
oidcprovider.Cmd.LocalFlags().BoolVar(&disableRegionDeprecation, arguments.DisableRegionDeprecationFlagName,
true, disableUsage)
oidcprovider.Cmd.Run(oidcprovider.Cmd, []string{clusterName, mode, ""})
disableRegionDeprecation = false // No longer disable
} else {
output := ""
if len(operatorRoles) == 0 {
Expand Down Expand Up @@ -3272,11 +3261,8 @@ func run(cmd *cobra.Command, _ []string) {
}

if args.watch {
disableRegionDeprecation = true // Disable region deprecation
clusterdescribe.Cmd.LocalFlags().BoolVar(&disableRegionDeprecation, arguments.DisableRegionDeprecationFlagName,
true, disableUsage)
installLogs.Cmd.Run(installLogs.Cmd, []string{clusterName})
disableRegionDeprecation = false // No longer disable
arguments.DisableRegionDeprecationWarning = false // no longer disable deprecation warning
} else if !output.HasFlag() || r.Reporter.IsTerminal() {
r.Reporter.Infof(
"To determine when your cluster is Ready, run 'rosa describe cluster -c %s'.",
Expand Down
3 changes: 3 additions & 0 deletions cmd/create/ocmrole/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/spf13/cobra"

linkocmrole "github.com/openshift/rosa/cmd/link/ocmrole"
"github.com/openshift/rosa/pkg/arguments"
"github.com/openshift/rosa/pkg/aws"
awscb "github.com/openshift/rosa/pkg/aws/commandbuilder"
"github.com/openshift/rosa/pkg/aws/tags"
Expand Down Expand Up @@ -279,7 +280,9 @@ func run(cmd *cobra.Command, _ []string) {
r.OCMClient.LogEvent("ROSACreateOCMRoleModeAuto", map[string]string{
ocm.Response: ocm.Success,
})
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
linkocmrole.Cmd.Run(linkocmrole.Cmd, []string{roleARN})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
case interactive.ModeManual:
r.OCMClient.LogEvent("ROSACreateOCMRoleModeManual", map[string]string{})
_, _, err = checkRoleExists(r, roleNameRequested, isAdmin, interactive.ModeManual)
Expand Down
2 changes: 2 additions & 0 deletions cmd/create/oidcconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ func run(cmd *cobra.Command, _ []string) {
}
oidcConfigStrategy.execute(r)
if !args.rawFiles {
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
oidcprovider.Cmd.Run(oidcprovider.Cmd, []string{"", mode, oidcConfigInput.IssuerUrl})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
}
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/create/userrole/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"

linkuser "github.com/openshift/rosa/cmd/link/userrole"
"github.com/openshift/rosa/pkg/arguments"
"github.com/openshift/rosa/pkg/aws"
awscb "github.com/openshift/rosa/pkg/aws/commandbuilder"
"github.com/openshift/rosa/pkg/aws/tags"
Expand Down Expand Up @@ -215,8 +216,9 @@ func run(cmd *cobra.Command, _ []string) {
r.OCMClient.LogEvent("ROSACreateUserRoleModeAuto", map[string]string{
ocm.Response: ocm.Success,
})

arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
linkuser.Cmd.Run(linkuser.Cmd, []string{roleARN})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
case interactive.ModeManual:
r.OCMClient.LogEvent("ROSACreateUserRoleModeManual", map[string]string{})
err = generateUserRolePolicyFiles(r.Reporter, env, r.Creator.Partition, currentAccount.ID(), policies)
Expand Down
3 changes: 3 additions & 0 deletions cmd/dlt/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/openshift/rosa/cmd/dlt/oidcprovider"
"github.com/openshift/rosa/cmd/dlt/operatorrole"
uninstallLogs "github.com/openshift/rosa/cmd/logs/uninstall"
"github.com/openshift/rosa/pkg/arguments"
"github.com/openshift/rosa/pkg/interactive"
"github.com/openshift/rosa/pkg/interactive/confirm"
"github.com/openshift/rosa/pkg/ocm"
Expand Down Expand Up @@ -120,7 +121,9 @@ func run(_ *cobra.Command, _ []string) {
fmt.Print(commands, "\n")
}
if args.watch {
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
uninstallLogs.Cmd.Run(uninstallLogs.Cmd, []string{clusterKey})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
} else {
r.Reporter.Infof("To watch your cluster uninstallation logs, run 'rosa logs uninstall -c %s --watch'",
clusterKey,
Expand Down
3 changes: 3 additions & 0 deletions cmd/dlt/ocmrole/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"

unlinkocmrole "github.com/openshift/rosa/cmd/unlink/ocmrole"
"github.com/openshift/rosa/pkg/arguments"
"github.com/openshift/rosa/pkg/aws"
awscb "github.com/openshift/rosa/pkg/aws/commandbuilder"
"github.com/openshift/rosa/pkg/helper"
Expand Down Expand Up @@ -177,7 +178,9 @@ func run(cmd *cobra.Command, argv []string) {
r.OCMClient.LogEvent("ROSADeleteOCMRoleModeAuto", nil)
if isLinked {
r.Reporter.Warnf("Role ARN '%s' is linked to organization '%s'", roleARN, orgID)
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
unlinkocmrole.Cmd.Run(unlinkocmrole.Cmd, []string{roleARN})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
}
if roleExistOnAWS {
err := r.AWSClient.DeleteOCMRole(roleName, managedPolicies)
Expand Down
2 changes: 2 additions & 0 deletions cmd/dlt/oidcconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func run(cmd *cobra.Command, _ []string) {
os.Exit(1)
}
oidcConfigStrategy.execute(r)
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
oidcprovider.Cmd.Run(oidcprovider.Cmd, []string{"", mode, oidcConfigInput.IssuerUrl})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
r.OCMClient.DeleteOidcConfig(args.oidcConfigId)
if r.Reporter.IsTerminal() {
r.Reporter.Infof("Registered OIDC Config ID '%s'"+
Expand Down
3 changes: 3 additions & 0 deletions cmd/dlt/userrole/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"

unlinkuserrole "github.com/openshift/rosa/cmd/unlink/userrole"
"github.com/openshift/rosa/pkg/arguments"
"github.com/openshift/rosa/pkg/aws"
awscb "github.com/openshift/rosa/pkg/aws/commandbuilder"
"github.com/openshift/rosa/pkg/helper"
Expand Down Expand Up @@ -176,7 +177,9 @@ func run(cmd *cobra.Command, argv []string) {
if isLinked {
r.Reporter.Warnf("Role ARN '%s' is linked to account '%s'",
roleARN, currentAccount.ID())
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
unlinkuserrole.Cmd.Run(unlinkuserrole.Cmd, []string{roleARN})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
}
err := r.AWSClient.DeleteUserRole(roleName)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/register/oidcconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,7 @@ func run(cmd *cobra.Command, _ []string) {
output := fmt.Sprintf(InformOperatorRolesOutput, oidcConfig.ID())
r.Reporter.Infof(output)
}
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
oidcprovider.Cmd.Run(oidcprovider.Cmd, []string{"", mode, args.issuerUrl})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
}
3 changes: 3 additions & 0 deletions cmd/upgrade/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/spf13/cobra"

"github.com/openshift/rosa/cmd/upgrade/roles"
"github.com/openshift/rosa/pkg/arguments"
"github.com/openshift/rosa/pkg/interactive"
"github.com/openshift/rosa/pkg/interactive/confirm"
"github.com/openshift/rosa/pkg/ocm"
Expand Down Expand Up @@ -479,7 +480,9 @@ func checkSTSRolesCompatibility(r *rosa.Runtime, cluster *cmv1.Cluster, mode str
version string, clusterKey string) {
r.Reporter.Infof("Ensuring account and operator role policies for cluster '%s'"+
" are compatible with upgrade.", cluster.ID())
arguments.DisableRegionDeprecationWarning = true // disable region deprecation warning
roles.Cmd.Run(roles.Cmd, []string{mode, cluster.ID(), version, cluster.Version().ChannelGroup()})
arguments.DisableRegionDeprecationWarning = false // enable region deprecation again
if r.Reporter.IsTerminal() {
r.Reporter.Infof("Account and operator roles for cluster '%s' are compatible with upgrade", clusterKey)
}
Expand Down
18 changes: 15 additions & 3 deletions pkg/arguments/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package arguments
import (
"fmt"
"os"
"strconv"
"strings"

"github.com/spf13/cobra"
Expand All @@ -37,7 +38,9 @@ const regionFlagName = "region"
const regionDeprecationMessage = "Region flag will be removed from this command in future versions"

var hasUnknownFlags bool
var DisableRegionDeprecationFlagName = "disable-region-deprecation"

var DisableRegionDeprecationFlagName = "disable-region-deprecation" // Temporary for region deprecation
var DisableRegionDeprecationWarning = false // Temporary for region deprecation

// ParseUnknownFlags parses all flags from the CLI, including
// unknown ones, and adds them to the current command tree
Expand Down Expand Up @@ -332,15 +335,24 @@ func MarkRegionDeprecated(parentCmd *cobra.Command, childrenCmds []*cobra.Comman
deprecateRegion(parentCmd)
command.Parent().HelpFunc()(command, strings)
})

disableUsage := "Temporarily used for disabling a warning message ran from other commands (no reason to" +
" print for cluster describe called inside cluster create, but there is a use for a lone describe."
if cmd.LocalFlags().Lookup(DisableRegionDeprecationFlagName) == nil {
cmd.LocalFlags().BoolVar(&DisableRegionDeprecationWarning, DisableRegionDeprecationFlagName,
false, disableUsage)
cmd.LocalFlags().Lookup(DisableRegionDeprecationFlagName).Hidden = true
}

currentRun := cmd.Run
cmd.Run = func(c *cobra.Command, args []string) {
outputFlag := cmd.Flag("output")
regionFlag := cmd.Flag("region")
disableDeprecationFlag := cmd.Flag(DisableRegionDeprecationFlagName)
disableDeprecationFlag := cmd.LocalFlags().Lookup(DisableRegionDeprecationFlagName)
hasChangedOutputFlag := outputFlag != nil && outputFlag.Value.String() != outputFlag.DefValue
hasChangedRegionFlag := regionFlag != nil && regionFlag.Value.String() != regionFlag.DefValue
isRegionDeprecationDisabled := disableDeprecationFlag != nil &&
disableDeprecationFlag.Value.String() != disableDeprecationFlag.DefValue
disableDeprecationFlag.Value.String() == strconv.FormatBool(true)
if hasChangedRegionFlag && !hasChangedOutputFlag && !isRegionDeprecationDisabled {
_, _ = fmt.Fprintf(os.Stdout, "%s%s\n", "\u001B[0;33mW:\u001B[m ", regionDeprecationMessage)
}
Expand Down