-
Notifications
You must be signed in to change notification settings - Fork 208
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
bugfixes for editing managed service #763
Conversation
@tbrisker PTAL: A flag checking object was to the Rosa runtime object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I feel adding argument related logic to the runtime, perhaps we should keep a separation between them?
cmd/edit/service/cmd.go
Outdated
"github.com/openshift/rosa/pkg/arguments" | ||
"github.com/openshift/rosa/pkg/ocm" | ||
"github.com/openshift/rosa/pkg/rosa" | ||
) | ||
|
||
var args ocm.UpdateManagedServiceArgs | ||
|
||
var runtime *rosa.Runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too fond of using a global for the runtime (or in general)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither, I thought I couldn't do it without using a global variable but I just figured out a way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve this if the removal of the global variable works for you.
@tbrisker I can change it if needed, but how should we determine what goes in the runtime object? I thought the FlagChecker fit in with the other objects in the Runtime: objects that will be used during the run. |
@renan-campos I think the runtime should be limited to what happens in the |
That makes sense; Last time you reviewed the code the checker had to be globally scoped, but I changed it so that all of it occurs in the |
cmd/edit/service/cmd.go
Outdated
|
||
if len(parameters) == 0 { | ||
r.Reporter.Errorf("Service %q has no parameters to edit", args.ID) | ||
// Setting parameter flags as valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems out of place?
cmd/edit/service/cmd.go
Outdated
// Adding known flags to flag checker before parsing the unknown flags | ||
cmd.Flags().VisitAll(func(flag *pflag.Flag) { | ||
r.FlagChecker.AddValidFlag(flag) | ||
}) | ||
|
||
err := arguments.ParseUnknownFlags(cmd, argv) | ||
if err != nil { | ||
r.Reporter.Errorf("Failed to parse flags: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
if len(cmd.Flags().Args()) > 0 { | ||
r.Reporter.Errorf("Unrecognized command line parameter") | ||
os.Exit(1) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty generic, maybe that be done inside WithFlagChecker()
? perhaps pass cmd
to the NewRuntime()
method as that might be useful in other places for refactoring, or into WithFlagChecker()
?
Still not sure if this should be in the runtime itself or the FlagCheck
object... Perhaps lets start with the separate object and we can move it into the runtime if we see this becomes a common pattern?
cmd/edit/service/cmd.go
Outdated
cmd.Flags().VisitAll(func(flag *pflag.Flag) { | ||
if !r.FlagChecker.IsValidFlag(flag) { | ||
r.Reporter.Errorf("%q is not a valid flag", flag.Name) | ||
os.Exit(1) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also generic and perhaps shouldn't be here - if the FlagChecker has access to cmd
(whether directly or via runtime) this could become something like FlagChecker.ValidateFlags()
pkg/arguments/validator.go
Outdated
return f | ||
} | ||
|
||
func (f *FlagCheck) AddValidParameter(parameterName string) *FlagCheck { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems very addons-specific, perhaps we could combine this with AddValidFlag
and have one method that accepts a string and leave it to the caller to pass the right string?
cmd/edit/service/cmd.go
Outdated
r.FlagChecker.AddValidFlag(flag) | ||
}) | ||
|
||
err := arguments.ParseUnknownFlags(cmd, argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought, lmk what you think:
This will add all the unknown flags to cmd.Flags()
to check if they are valid later.
i'm wondering if we could perhaps flip the order around, add the flags from the addon params, and then get rid of keeping a separate set of valid flags and instead use cmd.Flags().Lookup(..)
to check if a flag is valid or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The barrier to this approach is that the flags need to be parsed before the addon parameters are known.
So the flow needs to go:
- Parse flags
- Get the addon related to the service id
- Ensure the user provided flags are original command flags or add-on parameter flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having to use some of the flags before being able to check all the flags is what really throws me off trying to get a good flow here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParseUnknownFlags mutating the cmdFlagset doesn't help...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but i think you should be able to access the known flags (which is what you need to get the other ones) even before parsing the unknown ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I tried it that way.
It's coming together... |
pkg/rosa/runtime.go
Outdated
OCMClient *ocm.Client | ||
AWSClient aws.Client | ||
Creator *aws.Creator | ||
FlagChecker *arguments.FlagCheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed for now
cmd/edit/service/cmd.go
Outdated
r.FlagChecker.AddValidFlag(flag) | ||
}) | ||
|
||
err := arguments.ParseUnknownFlags(cmd, argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but i think you should be able to access the known flags (which is what you need to get the other ones) even before parsing the unknown ones
Lets merge this in, we can follow up with any other changes @tbrisker wants when he returns. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ciaranRoche, renan-campos The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@renan-campos: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Fixes SDA-6104