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

Make delete actually stop resources by default. #7210

Merged
merged 1 commit into from Apr 28, 2015

Conversation

brendandburns
Copy link
Contributor

Refactor for shared code.

@bgrant0607 @ghodss @smarterclayton @eparis

This is a breaking change for kubectl delete ... behavior by default.

@brendandburns
Copy link
Contributor Author

@deads2k too for good measure ;)

@bgrant0607
Copy link
Member

And cc @jlowdermilk

We could put a deprecated message on the stop command, like we did for rollingupdate.

err := r.Visit(func(info *resource.Info) error {
found++
reaper, err := f.Reaper(info.Mapping)
cmdutil.CheckErr(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably don't want to fatal in here. Can you return the error instead?

Oh, sorry for the dupe. PR versus commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@brendandburns
Copy link
Contributor Author

Comments addressed. I'm not convinced we should deprecate kubectl stop ... I think there is value in stop as a counter-point to run

We should alias them together, though.

@thockin
Copy link
Member

thockin commented Apr 23, 2015

Without reading the PR, SGTM. How do we do a "delete and abandon" ?

On Thu, Apr 23, 2015 at 3:01 PM, Brendan Burns notifications@github.com
wrote:

Comments addressed. I'm not convinced we should deprecate kubectl stop ...
I think there is value in stop as a counter-point to run

We should alias them together, though.


Reply to this email directly or view it on GitHub
#7210 (comment)
.

@bgrant0607
Copy link
Member

Delete and abandon is delete --recursive=false.

I'm fine with aliasing stop and delete, though we should document that: #5370.

@bgrant0607 bgrant0607 self-assigned this Apr 23, 2015
@j3ffml
Copy link
Contributor

j3ffml commented Apr 24, 2015

LGTM. +1 to keeping stop as an alias for delete --recursive=true

@liggitt
Copy link
Member

liggitt commented Apr 24, 2015

What happens if you delete something which doesn't support stop without adding --recursive=false? I like having the recursive option, but I'm not sure it should be the default

@@ -86,3 +63,24 @@ func NewCmdStop(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd.Flags().Bool("all", false, "[-all] to select all the specified resources")
return cmd
}

func DoStop(f *cmdutil.Factory, cmd *cobra.Command, args []string, filenames util.StringList, out io.Writer) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit... I think it's usually Run*, so RunStop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@ghodss
Copy link
Contributor

ghodss commented Apr 24, 2015

Is recursive the right word here? Obviously it fits for RC's but doesn't this indicate whether to wait for a graceful stop of pods too? (Where recursive would be less appropriate.) Or does it not apply to pods?

@ghodss
Copy link
Contributor

ghodss commented Apr 24, 2015

If the outcome of this PR is that delete == stop, does it just make sense to make stop an alias to delete in this PR?

@thockin
Copy link
Member

thockin commented Apr 24, 2015

--cascade ?

On Thu, Apr 23, 2015 at 8:49 PM, Sam Ghods notifications@github.com wrote:

Is recursive the right word here? Obviously it fits for RC's but doesn't
this indicate whether to wait for a graceful stop of pods too? (Where
recursive would be less appropriate.) Or does it not apply to pods?


Reply to this email directly or view it on GitHub
#7210 (comment)
.

@derekwaynecarr
Copy link
Member

+1 for --cascade

Sent from my iPhone

On Apr 23, 2015, at 11:58 PM, Tim Hockin notifications@github.com wrote:

--cascade ?

On Thu, Apr 23, 2015 at 8:49 PM, Sam Ghods notifications@github.com wrote:

Is recursive the right word here? Obviously it fits for RC's but doesn't
this indicate whether to wait for a graceful stop of pods too? (Where
recursive would be less appropriate.) Or does it not apply to pods?


Reply to this email directly or view it on GitHub
#7210 (comment)
.


Reply to this email directly or view it on GitHub.

@ghodss
Copy link
Contributor

ghodss commented Apr 24, 2015

Aren't options like "--delete-only=true" or "--graceful=false" more appropriate? --cascade still sounds like there are more objects to deal with, whereas that's not true with pods, or other objects we introduce that exclusive to themselves have a graceful and non-graceful way to stop.

@thockin
Copy link
Member

thockin commented Apr 24, 2015

I think "graceful" and "cascade" are orthogonal ideas, and even though they
appear to be mutually exclusive now, we should not presume that they will
be forever. Consider a world where deleting a pod with --cascade=false
might leave the pod's data volumes alive, while --cascade=true would
destroy them. That's a very different concern than whether the pod gets 30
seconds of warning or not.

On Thu, Apr 23, 2015 at 11:31 PM, Sam Ghods notifications@github.com
wrote:

Aren't options like "--delete-only=true" or "--graceful=false" more
appropriate? --cascade still sounds like there are more objects to deal
with, whereas that's not true with pods, or other objects we introduce that
exclusive to themselves have a graceful and non-graceful way to stop.


Reply to this email directly or view it on GitHub
#7210 (comment)
.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot
Copy link

CLAs look good, thanks!

@brendandburns
Copy link
Contributor Author

Switched to --cascade, @liggitt I added code so that if the flag is unset, and there is no reaper, then we skip back to the existing delete code.

I will add the alias in a different PR.

Please take another look.

Thanks!
--brendan

@@ -50,6 +50,7 @@ func TestDeleteObjectByTuple(t *testing.T) {

cmd := NewCmdDelete(f, buf)
cmd.Flags().Set("namespace", "test")
cmd.Flags().Set("recursive", "false")
Copy link
Member

Choose a reason for hiding this comment

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

Should be change to cascade (everywhere).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@brendandburns
Copy link
Contributor Author

Comments addressed, please re-check.

Thanks!
--brendan

@brendandburns
Copy link
Contributor Author

Friendly ping on this.

Thanks!
--brendan

reaper, err := f.Reaper(info.Mapping)
if err != nil {
// If the error is "not found" and the user didn't explicitly set "cascade" just delete.
if kubectl.IsNoSuchReaperError(err) && !cmd.Flags().Lookup("cascade").Changed {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will crash (nil deref I think) if you call it from kubectl/cmd/stop, because stop does not define a "cascade" flag. This error handling should be moved into RunDelete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. (can't do it in RunDelete because I do want to Stop those things that support stop, and not delete everything just because something else can't be stopped)

Copy link
Contributor

Choose a reason for hiding this comment

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

Checking the flag for nil is kind of an ugly hack... How about this: change ReapResult to take a boolean 'defaultToDelete' which if true, makes ReapResult do a standard delete on resources for which there is no reaper available. That way you don't have to pass in the command object, and you can do the check for an explicit --cascade in RunDelete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@brendandburns
Copy link
Contributor Author

Comment addressed, please re-check.

--brendan

@bgrant0607 bgrant0607 assigned j3ffml and unassigned bgrant0607 Apr 27, 2015
reaper, err := f.Reaper(info.Mapping)
if err != nil {
// If the error is "not found" and the user didn't explicitly set "cascade" just delete.
if kubectl.IsNoSuchReaperError(err) && cmd.Flags().Lookup("cascade") != nil && !cmd.Flags().Lookup("cascade").Changed {
Copy link
Contributor

Choose a reason for hiding this comment

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

Repeating since it may have been lost in outdated diff

Checking the flag for nil is kind of an ugly hack... How about this: change ReapResult to take a boolean defaultToDelete instead of passing the Command object. If defaultToDelete is true, do a standard delete on resources for which there is no reaper available. That way you can move the check for an explicit --cascade into RunDelete, and we're not checking for nonexistent flags as a proxy for "which toplevel command is calling me".

@brendandburns
Copy link
Contributor Author

rebased.

@j3ffml
Copy link
Contributor

j3ffml commented Apr 28, 2015

There's an unresolved comment in the diff for pkg/kubectl/cmd/delete.go that seems to be getting attached to the outdated diff thread. Please take a look and let me know if you can't see it or object to suggested change.

if r.Err() != nil {
return r.Err()
}
return ReapResult(r, f, out, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be false? By running stop user is explicitly requesting reaper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@j3ffml
Copy link
Contributor

j3ffml commented Apr 28, 2015

lgtm aside from isDeleteDefault=false for RunStop.

@brendandburns
Copy link
Contributor Author

comment addressed, ptal. unit tests are manually determined to be clean.

@j3ffml
Copy link
Contributor

j3ffml commented Apr 28, 2015

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants