-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix: rbac validate command can now take either namespace or policy-file #15543
fix: rbac validate command can now take either namespace or policy-file #15543
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #15543 +/- ##
==========================================
+ Coverage 49.54% 49.68% +0.14%
==========================================
Files 269 269
Lines 46583 46629 +46
==========================================
+ Hits 23079 23169 +90
+ Misses 21232 21186 -46
- Partials 2272 2274 +2
☔ View full report in Codecov by Sentry. |
@ashinsabu3 can you write a test to prevent regressions? |
@crenshaw-dev I don't quite understand what you mean by this. If you mean a unit test, I'm not exactly sure how I would test the Rbac command functions. |
Yep, unit testing! Cobra has unit testing utilities. I think there are a couple examples using it in our code base. It'll probably require a bit of mocking to get working. |
d622b00
to
b05e753
Compare
I've added a test to check the command being returned, but couldn't get the test for it's execution working. The more I went into trying to get it working, it felt less like a unit test. I've commented it out for now @crenshaw-dev |
74ec46e
to
8b05340
Compare
…le as arg Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
8b05340
to
e96000c
Compare
The previous CI failures seem to be due to some flaky e2e tests, not sure, all passed when run on a weekend night 🙂 |
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
var ( | ||
policyFile string | ||
) | ||
|
||
var command = &cobra.Command{ | ||
Use: "validate --policy-file=POLICYFILE", | ||
Use: "validate --policy-file POLICYFILE [--namespace NAMESPACE]", |
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.
As policy-file is also optional now, put it in square brackets.
Use: "validate --policy-file POLICYFILE [--namespace NAMESPACE]", | |
Use: "validate [--policy-file POLICYFILE] [--namespace NAMESPACE]", |
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.
Done
Short: "Validate RBAC policy", | ||
Long: ` | ||
Validates an RBAC policy for being syntactically correct. The policy must be | ||
a local file, and in either CSV or K8s ConfigMap format. | ||
a local file or a K8s ConfigMap in the provided namespace, and in either CSV or K8s ConfigMap format. |
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.
While we are updating the command, can we add an example as well?
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.
Adding one, let me know if the wording looks fine
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 wording looks good! Thanks!
return command | ||
} | ||
|
||
// NewRBACCanRoleCommand is the command for 'rbac can-role' | ||
func NewRBACCanCommand() *cobra.Command { | ||
func NewRBACCanCommand(clientConfig clientcmd.ClientConfig) *cobra.Command { |
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.
Any reason to put the clientConfig as a parameter? If we are taking namespace as an input, do we need to fetch the namespace from clientConfig rather than adding namespace as a variable like policyFile
?
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've modified this back, at the time I missed something (most likely the issue you commented below
the flag &policyFile is repeated. This should be &namespace?
) and while testing the command it repeatedly returned some segmentation fault so I thought passing down the clientConfig param would fix it.
I've changed it back now that I know why my command was failing at the time.
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
@ishitasequeira Addressed comments you had. Do the changes look good? |
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.
Thanks @ashinsabu3! Changes look good!
Short: "Validate RBAC policy", | ||
Long: ` | ||
Validates an RBAC policy for being syntactically correct. The policy must be | ||
a local file, and in either CSV or K8s ConfigMap format. | ||
a local file or a K8s ConfigMap in the provided namespace, and in either CSV or K8s ConfigMap format. |
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 wording looks good! Thanks!
…le (argoproj#15543) * fix: rbac validate command can now take either namespace or policy-file as arg Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * remove changes to generated text Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * unit test for rbacvalidatecommand Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * review comments and test changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes - post rebase Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> --------- Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> Signed-off-by: jmilic1 <70441727+jmilic1@users.noreply.github.com>
…le (argoproj#15543) * fix: rbac validate command can now take either namespace or policy-file as arg Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * remove changes to generated text Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * unit test for rbacvalidatecommand Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * review comments and test changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes - post rebase Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> --------- Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
…le (argoproj#15543) * fix: rbac validate command can now take either namespace or policy-file as arg Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * remove changes to generated text Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * unit test for rbacvalidatecommand Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * review comments and test changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes - post rebase Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> --------- Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
…le (argoproj#15543) * fix: rbac validate command can now take either namespace or policy-file as arg Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * remove changes to generated text Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * unit test for rbacvalidatecommand Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * review comments and test changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes - post rebase Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> --------- Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> Signed-off-by: Kevin Lyda <kevin@lyda.ie>
…le (argoproj#15543) * fix: rbac validate command can now take either namespace or policy-file as arg Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * remove changes to generated text Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * unit test for rbacvalidatecommand Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * retrigger ci pipeline Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * review comments and test changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> * codegen changes - post rebase Signed-off-by: Ashin Sabu <ashin.sabu@harness.io> --------- Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
fixes: #6126
This fix now allows the command to take only a namespace flag if required.
Checklist: