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 --keep to delete --all, to keep the last N pipelineruns #720

Conversation

chmouel
Copy link
Member

@chmouel chmouel commented Feb 12, 2020

Changes

Add a --keep to delete --all so we can keep N numbers. Users can set this up in
a cronjobs to clean old pipelineruns but keeping only the last ones.

Closes #718

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)
  • Run the code checkers with make check
  • Regenerate the manpages, docs and go formatting with make generated
  • Commit messages follow commit message best practices

See the contribution guide
for more details.

@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 12, 2020
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/meow

@tekton-robot
Copy link
Contributor

@vdemeester: cat image

In response to this:

/meow

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.

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 13, 2020
Copy link
Member

@danielhelfand danielhelfand left a comment

Choose a reason for hiding this comment

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

A couple things:

  1. There needs to be a prompt specifically for --keep when not using -f. Currently it's what is shown below, but it should be a message about keeping a certain amount of pipelines:

Are you sure you want to delete all pipelineruns in namespace "default" (y/n):

  1. This is the error message for if --keep is used without --all:

Error: must provide pipelineruns to delete or --pipeline flag

There should be a clearer error message.

@@ -70,6 +71,7 @@ or
f.AddFlags(c)
c.Flags().BoolVarP(&opts.ForceDelete, "force", "f", false, "Whether to force deletion (default: false)")
c.Flags().StringVarP(&opts.ParentResourceName, "pipeline", "p", "", "The name of a pipeline whose pipelineruns should be deleted (does not delete the pipeline)")
c.Flags().IntVarP(&opts.Keep, "keep", "", 0, "Keep N number of pipelineruns when deleting alls")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
c.Flags().IntVarP(&opts.Keep, "keep", "", 0, "Keep N number of pipelineruns when deleting alls")
c.Flags().IntVarP(&opts.Keep, "keep", "", 0, "keep n number of pipelineruns when using --all flag")

Copy link
Member

Choose a reason for hiding this comment

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

Would be nice in some way to indicate that ordering here is done by most recent pipelinerun.

Copy link
Member Author

Choose a reason for hiding this comment

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

humm usually i would ask to my english master 👨‍🏫 (ie you 😄 )

what about ?

Keep the last n number of pipelineruns?

Copy link
Member

@danielhelfand danielhelfand Feb 18, 2020

Choose a reason for hiding this comment

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

keep n least recent number of pipelineruns sounds good to me.

for _, pr := range pipelineRuns.Items {
var counter = 0
for _, pr := range prhsort.SortPipelineRunsByStartTime(pipelineRuns.Items) {
if keep > 0 && counter != keep {
Copy link
Member

Choose a reason for hiding this comment

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

Should there be some kind of error message if keep < 0? Currently, it will delete all pipelineruns.

Copy link
Member Author

Choose a reason for hiding this comment

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

in case If the user choose ?:

--last=-1

I guess that's quite a weird user case

Copy link
Member

Choose a reason for hiding this comment

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

Right, I mean it's totally unlikely, but we should prevent it by checking if keep < 0 similar to what is done for limit. So fail fast in RunE in this case.

Copy link
Member

Choose a reason for hiding this comment

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

@danielhelfand isn't the code above already checking that keep can't be < 0 ?

@chmouel chmouel force-pushed the issue-718-add---limit-to-delete---all-for-pipelineruns-and-task branch from 9019171 to 6a2ec02 Compare February 19, 2020 14:55
Copy link
Member

@vdemeester vdemeester 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 Feb 27, 2020
@vdemeester vdemeester added this to the 0.8.0 🐯 milestone Feb 27, 2020
@danielhelfand
Copy link
Member

/hold

There is some feedback that I think should be addressed in this pr still.

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 27, 2020
@danielhelfand
Copy link
Member

A couple things:

  1. There needs to be a prompt specifically for --keep when not using -f. Currently it's what is shown below, but it should be a message about keeping a certain amount of pipelines:

Are you sure you want to delete all pipelineruns in namespace "default" (y/n):

  1. This is the error message for if --keep is used without --all:

Error: must provide pipelineruns to delete or --pipeline flag

There should be a clearer error message.

@vdemeester Less about the issue with keep < 0. More about the issues listed above.

@vdemeester
Copy link
Member

@danielhelfand ah indeed

@vdemeester vdemeester force-pushed the issue-718-add---limit-to-delete---all-for-pipelineruns-and-task branch from 6a2ec02 to 7d18aeb Compare February 27, 2020 11:28
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 27, 2020
@vdemeester vdemeester force-pushed the issue-718-add---limit-to-delete---all-for-pipelineruns-and-task branch from 7d18aeb to f9310a5 Compare February 27, 2020 11:32
@tektoncd tektoncd deleted a comment from tekton-robot Feb 27, 2020
@vdemeester
Copy link
Member

@danielhelfand taken into account 👼
/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 27, 2020
@vdemeester vdemeester force-pushed the issue-718-add---limit-to-delete---all-for-pipelineruns-and-task branch from f9310a5 to 87dc38e Compare February 27, 2020 11:34
@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/helper/options/delete.go 95.8% 89.7% -6.2

@@ -80,13 +82,16 @@ func deletePipelineRuns(s *cli.Stream, p cli.Params, prNames []string, opts *opt
if err != nil {
return fmt.Errorf("failed to create tekton client")
}
if opts.Keep > 0 && !opts.DeleteAllNs {
Copy link
Member

Choose a reason for hiding this comment

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

This error message will only be reached if using -f. My recommendation would be to check earlier in RunE or Args to account for prompt situation:

If I run tkn pr delete --keep 7, I get the following:

Error: must provide pipelinerun name(s) or use --pipeline flag or --all flag to use delete

chmouel and others added 2 commits February 27, 2020 15:25
Closes tektoncd#718

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
Closes tektoncd#718

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
@vdemeester vdemeester force-pushed the issue-718-add---limit-to-delete---all-for-pipelineruns-and-task branch 2 times, most recently from 3eed134 to 8270263 Compare February 27, 2020 14:36
}

func (o *DeleteOptions) CheckOptions(s *cli.Stream, resourceNames []string, ns string) error {
if o.Keep > 0 && !(o.DeleteAllNs || o.DeleteAll) {
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag")
Copy link
Member

Choose a reason for hiding this comment

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

Promise this is the last thing. Could the error message be:

Suggested change
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag")
return fmt.Errorf("must use --all flag with --keep")

}

func (o *DeleteOptions) CheckOptions(s *cli.Stream, resourceNames []string, ns string) error {
if o.Keep > 0 && !(o.DeleteAllNs || o.DeleteAll) {
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag")
Copy link
Member

Choose a reason for hiding this comment

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

Promise this is the last thing. Could the error message be:

Suggested change
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag")
return fmt.Errorf("must use --all flag with --keep")

}

func (o *DeleteOptions) CheckOptions(s *cli.Stream, resourceNames []string, ns string) error {
if o.Keep > 0 && !(o.DeleteAllNs || o.DeleteAll) {
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag")
Copy link
Member

Choose a reason for hiding this comment

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

Promise this is the last thing. Could the error message be:

Suggested change
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag")
return fmt.Errorf("must use --all flag with --keep")

}

func (o *DeleteOptions) CheckOptions(s *cli.Stream, resourceNames []string, ns string) error {
if o.Keep > 0 && !(o.DeleteAllNs || o.DeleteAll) {
Copy link
Member

Choose a reason for hiding this comment

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

Promise this is the last thing. Could the error message be:

Suggested change
if o.Keep > 0 && !(o.DeleteAllNs || o.DeleteAll) {
return fmt.Errorf("must use --all flag with --keep")

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
@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/helper/options/delete.go 95.8% 87.1% -8.7

Copy link
Member

@danielhelfand danielhelfand 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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danielhelfand, vdemeester

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:
  • OWNERS [danielhelfand,vdemeester]

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 lgtm Indicates that a PR is ready to be merged. label Feb 27, 2020
@tekton-robot tekton-robot merged commit 9a2c0be into tektoncd:master Feb 27, 2020
@chmouel chmouel deleted the issue-718-add---limit-to-delete---all-for-pipelineruns-and-task branch March 2, 2020 06:55
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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --keep delete --all for pipelineruns and taskruns
5 participants