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

Add Namespace Check to Task Delete Command #350

Merged
merged 1 commit into from
Oct 10, 2019
Merged

Add Namespace Check to Task Delete Command #350

merged 1 commit into from
Oct 10, 2019

Conversation

danielhelfand
Copy link
Member

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:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Regenerate the manpages and docs with make docs and make man if needed.
  • Run the code checkers with make check
  • Commit messages follow commit message best practices

Release Notes

Adds error message to tkn task delete when a namespace does not exist

@tekton-robot tekton-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 8, 2019
@tekton-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

pkg/cmd/task/delete.go Outdated Show resolved Hide resolved
Copy link
Member

@sthaha sthaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 9, 2019
@tekton-robot
Copy link
Contributor

The following is the coverage report on pkg/.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/task/delete.go 90.9% 91.5% 0.6

@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 9, 2019
@tekton-robot
Copy link
Contributor

The following is the coverage report on pkg/.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/task/delete.go 90.9% 91.5% 0.6

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 {
Copy link
Member

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 ?

Copy link
Member Author

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().

Copy link
Member

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 ...)

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.
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@sthaha sthaha left a 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.

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 9, 2019
@tekton-robot
Copy link
Contributor

The following is the coverage report on pkg/.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/cmd/task/delete.go 90.9% 89.8% -1.1
pkg/cmd/task/list.go 67.4% 66.7% -0.8
pkg/helper/validate/validate.go Do not exist 100.0%

@@ -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 {
Copy link
Member Author

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.

Copy link
Member

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 :)

Copy link
Member Author

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.
Copy link
Member Author

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.

Copy link
Member

@sthaha sthaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 10, 2019
@tekton-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 10, 2019
@tekton-robot tekton-robot merged commit 74f5638 into tektoncd:master Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants