-
Notifications
You must be signed in to change notification settings - Fork 249
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
Add --keep to delete --all, to keep the last N pipelineruns #720
Conversation
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.
/meow
In response to this:
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.
A couple things:
- 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):
- 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.
pkg/cmd/pipelinerun/delete.go
Outdated
@@ -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") |
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.
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") |
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.
Would be nice in some way to indicate that ordering here is done by most recent pipelinerun.
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.
humm usually i would ask to my english master 👨🏫 (ie you 😄 )
what about ?
Keep the last
n number of pipelineruns?
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.
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 { |
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.
Should there be some kind of error message if keep < 0? Currently, it will delete all pipelineruns.
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.
in case If the user choose ?:
--last=-1
I guess that's quite a weird user case
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.
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.
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.
@danielhelfand isn't the code above already checking that keep
can't be < 0
?
9019171
to
6a2ec02
Compare
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
/hold There is some feedback that I think should be addressed in this pr still. |
@vdemeester Less about the issue with |
@danielhelfand ah indeed |
6a2ec02
to
7d18aeb
Compare
7d18aeb
to
f9310a5
Compare
@danielhelfand taken into account 👼 |
f9310a5
to
87dc38e
Compare
The following is the coverage report on pkg/.
|
pkg/cmd/pipelinerun/delete.go
Outdated
@@ -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 { |
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 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
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>
3eed134
to
8270263
Compare
pkg/helper/options/delete.go
Outdated
} | ||
|
||
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") |
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.
Promise this is the last thing. Could the error message be:
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag") | |
return fmt.Errorf("must use --all flag with --keep") |
pkg/helper/options/delete.go
Outdated
} | ||
|
||
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") |
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.
Promise this is the last thing. Could the error message be:
return fmt.Errorf("must provide pipelineruns to delete or --pipeline flag") | |
return fmt.Errorf("must use --all flag with --keep") |
pkg/helper/options/delete.go
Outdated
} | ||
|
||
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") |
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.
Promise this is the last thing. Could the error message be:
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) { |
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.
Promise this is the last thing. Could the error message be:
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>
The following is the coverage report on pkg/.
|
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: 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:
Approvers can indicate their approval by writing |
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:
make check
make generated
See the contribution guide
for more details.