-
Notifications
You must be signed in to change notification settings - Fork 250
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
Add Namespace Check to Task Delete Command #350
Add Namespace Check to Task Delete Command #350
Conversation
Hi @danielhelfand. Thanks for your PR. I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
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-to-test
The following is the coverage report on pkg/.
|
The following is the coverage report on pkg/.
|
pkg/cmd/task/delete.go
Outdated
if err != nil { | ||
return fmt.Errorf("failed to create tekton client") | ||
} | ||
func deleteTask(opts *deleteOptions, s *cli.Stream, p cli.Params, cs *cli.Clients, tName string) error { |
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.
isn't cs already in p cli.Params
?
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.
Yes it is. I'll point on in a review comment why I went with this approach, but the gist of it was I was trying to avoid checking for the "failed to create tekton client"
error twice when using p.Clients()
.
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.
IMHO, ... it is okay for internal (non exported methods) to make assumptions about arguments it receives ; i.e. the caller should have ensured the arguments are valid before passing it to callee so that certain step need to be performed only once ... (premature optimisation 🤷♂️ ; may be ...)
pkg/cmd/task/delete.go
Outdated
return fmt.Errorf("failed to create tekton client") | ||
} | ||
|
||
// Check if namespace exists. Return error if namespace specified with -n doesn't exist or if user doesn't have permissions to view. |
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.
it may be better to move these validations to a package validate
so that the call appears
if err := validate.NamespaceExists(kubeClient, ns); err != nil{
return err
}
WDYT?
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 have moved the validation code under pkg/helper/validate
. Let me know what you think.
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.
How about a validate
package to keep all common validations. This may be also be useful in tests as well.
The following is the coverage report on pkg/.
|
@@ -70,16 +80,9 @@ func listCommand(p cli.Params) *cobra.Command { | |||
} | |||
|
|||
func printTaskDetails(s *cli.Stream, p cli.Params) error { | |||
|
|||
cs, err := p.Clients() | |||
if err != nil { |
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.
If there's a way to avoid the second error check here, would be nice. Was originally passing the clients as a param to printTaskDetails
, but I'm not opposed to two checks.
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.
Agree, I was also thinking of
validate.All( validate.Clients(p), validate.NamespaceExists(p))
where validate.KubeClient(p)
returns a validator function
like: func validator() error
and validate.All
just checks none of the functions return an error`
That way all commands would just have to invoke just
if err := validate.All( validate.Clients(p), validate.Foobar(x, y, z)); err != nil {
return err
}
WDYT?
BTW, I am not suggesting this change in this PR :)
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.
Sure, I think that's really clever. I'll keep this in mind a try to refactor it.
@@ -0,0 +1,32 @@ | |||
// Copyright © 2019 The Tekton Authors. |
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.
Idea here would be to use this class for common validation methods across the CLI.
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sthaha 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 |
This pull request follows up #349 and also helps to address #311. The goal is to check whether a namespace exists to alert the user if the namespace provided is invalid.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
make docs
andmake man
if needed.make check
Release Notes