-
Notifications
You must be signed in to change notification settings - Fork 255
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,9 +31,13 @@ type DeleteOptions struct { | |||||||||||||
DeleteRelated bool | ||||||||||||||
DeleteAllNs bool | ||||||||||||||
DeleteAll bool | ||||||||||||||
Keep int | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
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 commentThe 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") | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||
} | ||||||||||||||
// make sure no resource names are provided when using --all flag | ||||||||||||||
if len(resourceNames) > 0 && (o.DeleteAllNs || o.DeleteAll) { | ||||||||||||||
return fmt.Errorf("--all flag should not have any arguments or flags specified with it") | ||||||||||||||
|
@@ -51,17 +55,25 @@ func (o *DeleteOptions) CheckOptions(s *cli.Stream, resourceNames []string, ns s | |||||||||||||
return fmt.Errorf("must provide %s name(s) or use --all flag with delete", o.Resource) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if o.Keep < 0 { | ||||||||||||||
return fmt.Errorf("keep option should not be lower than 0") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if o.ForceDelete { | ||||||||||||||
return nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
formattedNames := names.QuotedList(resourceNames) | ||||||||||||||
|
||||||||||||||
keepStr := "" | ||||||||||||||
if o.Keep > 0 { | ||||||||||||||
keepStr = fmt.Sprintf(" keeping %d %ss", o.Keep, o.Resource) | ||||||||||||||
} | ||||||||||||||
switch { | ||||||||||||||
case o.DeleteAllNs: | ||||||||||||||
fmt.Fprintf(s.Out, "Are you sure you want to delete all %ss in namespace %q (y/n): ", o.Resource, ns) | ||||||||||||||
fmt.Fprintf(s.Out, "Are you sure you want to delete all %ss in namespace %q%s (y/n): ", o.Resource, ns, keepStr) | ||||||||||||||
case o.DeleteAll: | ||||||||||||||
fmt.Fprintf(s.Out, "Are you sure you want to delete all %ss (y/n): ", o.Resource) | ||||||||||||||
fmt.Fprintf(s.Out, "Are you sure you want to delete all %ss%s (y/n): ", o.Resource, keepStr) | ||||||||||||||
case o.ParentResource != "" && o.ParentResourceName != "": | ||||||||||||||
fmt.Fprintf(s.Out, "Are you sure you want to delete all %ss related to %s %q (y/n): ", o.Resource, o.ParentResource, o.ParentResourceName) | ||||||||||||||
case o.DeleteRelated: | ||||||||||||||
|
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
?