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

Proposal: Enable purging resources in kubectl apply #29551

Conversation

lukemarsden
Copy link
Contributor

@lukemarsden lukemarsden commented Jul 25, 2016

Proposal to resolve #19805


This change is Reviewable

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

@lukemarsden
Copy link
Contributor Author

lukemarsden commented Jul 25, 2016

Re CLA issue: not sure how to add @errordeveloper to this PR. How do you add a person to a PR?

@k8s-github-robot k8s-github-robot added kind/design Categorizes issue or PR as related to design. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Jul 25, 2016
@errordeveloper
Copy link
Member

This CLA check is a bit confusing..

kubectl apply --purge-from-namespace -f https://example.com/myapp-part1.json -f https://example.com/myapp-part2.json
```

If `myapp1.json` and `myapp2.json` are in the same namespaces and it is explicitly defined, removing either of the URLs from the invocations arguments will result in all the resources that URL has defined to be purged.
Copy link
Member

Choose a reason for hiding this comment

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

insert -part here, to reflect what's above

@mikedanese mikedanese assigned mikedanese and bgrant0607 and unassigned thockin Jul 25, 2016
@mikedanese mikedanese added area/kubectl sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Jul 25, 2016
@bgrant0607
Copy link
Member

cc @ghodss @kubernetes/kubectl

@bgrant0607
Copy link
Member

@lukemarsden @errordeveloper Commits from multiple contributors will always fail the automated CLA check.

@smarterclayton
Copy link
Contributor

Agree with general approach here - I think this is the simplest and most consistent way to solve this today.

@smarterclayton
Copy link
Contributor

We would need to warn about using the generateName field inside of your applied files.

@lukemarsden
Copy link
Contributor Author

lukemarsden commented Jul 26, 2016

Agree with general approach here - I think this is the simplest and most consistent way to solve this today.

Great, thanks!

We would need to warn about using the generateName field inside of your applied files.

Yes, but we think this is a general problem with apply? We could add a warning if applied files include generateName, however. I take it that your worry is that kubectl apply X twice, for X with generateName, would end up creating two copies of the resources therein. IOW, if generateName creates random names, it breaks the ability for a second instantiation of apply to refer to the resources created by a first.

See also: #1702 (comment)

@philips
Copy link
Contributor

philips commented Jul 26, 2016

cc @ethernetdan @colhom

@smarterclayton
Copy link
Contributor

It is a general problem, just want to make sure that a user is aware of it
in the edge case (we don't have to fix it here, just a TODO is ok).

On Tue, Jul 26, 2016 at 12:29 PM, Brandon Philips notifications@github.com
wrote:

oops, I meant to cc @colhom https://github.com/colhom. disregard
@aaronlevy https://github.com/aaronlevy and @derekchiang
https://github.com/derekchiang


You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
#29551 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABG_p7W9fdIXzOtIFFLcqWJS5PMw0p-tks5qZjXngaJpZM4JUUwZ
.

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 17, 2016
@lukemarsden
Copy link
Contributor Author

@mikedanese @bgrant0607

I've simplified the proposal and updated it to reflect the discussion above. Please take another look: https://github.com/errordeveloper/kubernetes/blob/kubectl-apply-purge-from-namespace/docs/proposals/kubectl-apply-purge-missing-where.md

Thanks!

@ghodss
Copy link
Contributor

ghodss commented Aug 17, 2016

This is very cool, thanks for the update! Couple questions:

  1. How does this interact with namespaces? Maybe this was implicit but here's how I would imagine it:
  1. If no namespace is specified, operate across default namespace only.
  2. If --namespace is specified, only operate in that namespace.
  3. If --all-namespaces is specified, operate across the entire cluster.

...with the label selector working as expected in all cases. I do think you could make a case that if you do --all-namespaces, adding a label selector should throw an error, since labels generally are designed to be scoped within namespaces. But I could be convinced either way on that.

  1. If you just do --purge-missing-where "", do you then affect all objects? This makes sense to me, but I wonder if there should be a different option or change the option name for it to be more intuitive in both cases.

@errordeveloper
Copy link
Member

@ghodss good question indeed, sounds like this should be clarified.

@lukemarsden I think the title of this PR no longer reflects the current revision of the proposal doc, doesn't it? It's really not so much about purging from namespaces any more.

@lukemarsden
Copy link
Contributor Author

lukemarsden commented Aug 18, 2016

@ghodss thanks for the review!

  1. I hadn't thought about this, but I concur with your reasoning. I will update the proposal with a section on namespace interactions, cnp'ing your suggestion. Personally I wouldn't add the --all-namespaces implies disabling the flag logic, because it makes the system less flexible. Users should be able to label (and purge) things across namespaces if they wish, even if it's not the recommended convention.
  2. --purge-missing-where "" is a dangerous operation, I'm OK with it being a bit hidden/cryptic. Just as long as --purge-missing-where without the "" doesn't have the same effect (which it shouldn't, because it will require an argument). But maybe it could print a warning which can only be overridden with --force in this case? WDYT? I don't think it's quite necessary personally. --dry-run may help out here.

@bgrant0607 not urgent, but do you have any comments on the above?

@lukemarsden lukemarsden changed the title Kubectl apply purge from namespace Proposal: Enable purging resources in kubectl apply Aug 18, 2016
@lukemarsden
Copy link
Contributor Author

@errordeveloper title fixed, thanks!

@lukemarsden
Copy link
Contributor Author

lukemarsden commented Aug 18, 2016

Updated the proposal with namespace bits, thanks @ghodss!

0a014ac

@k8s-bot
Copy link

k8s-bot commented Aug 18, 2016

GCE e2e build/test passed for commit 0a014ac.


## Interactions with namespaces

* If no namespace is specified, operate across `default` namespace only.
Copy link
Member

Choose a reason for hiding this comment

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

Namespace behavior should be the same as all other kubectl commands, which means that namespace comes from the context by default.

@bgrant0607
Copy link
Member

delete has a --all flag to specify all resources in the namespace.
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/delete.go#L108

The usage may look like this (assuming the user uses the convention of labelling apps with the `app` label):

```
kubectl apply --purge-missing-where 'app=myapp' -f https://example.com/myapp.json
Copy link
Member

Choose a reason for hiding this comment

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

Why mash --purge and the label selector together into a single flag? We have a convention for filtering commands by label selector already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bgrant0607 because the label selector is specific to the purge operation. Splitting the purge flag from the label selector, IMO, makes it more dangerous, because presumably --purge without a label selector would delete everything not in the provided manifests. Making --purge require -l would beg the question why not unify them? Furthermore the spelling of --purge-missing-where "condition" reads naturally to explain the semantics of what's happening IMO. --purge -l condition is less clear to new users. Furthermore -l makes sense as a filter on other ops because they are simple ops, like delete - it's obvious what's being filtered. But we're making apply a compound operation: "create some things and delete others", -l on its own isn't sufficiently descriptive to make clear what the label selector applies to (only the deletions). That's why I proposed the combined flag -- it's better UX IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

With the original design which was entirely label based, merging the flags certainly had merit. But now that we've introduced namespace as a filter as well, doesn't it break down a little? The filter is by selector, namespace, both or none, so at this point, having the purge flag merged specifically with the label selector doesn't seem to make as much sense.

If the goal is to protect against the danger of the flag, we should add a confirmation step which by default lists all resources which will be deleted and requires user confirmation to continue. Then we can add another flag like --continue to skip the prompt.

That way we protect against user error while maintaining our consistency of -l and --namespace.

Copy link
Member

Choose a reason for hiding this comment

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

@lukemarsden I disagree that the selector should only apply to prune/purge. I'd like to be able to use it to update a subset of the objects.

Also, we need to consider the overall usability of kubectl, not just this command. I prioritize consistency across commands fairly highly, so there's a high bar for departing from established precedent.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bgrant0607
Copy link
Member

@lukemarsden Please do not deviate from conventions established by other commands.

@bgrant0607
Copy link
Member

@lukemarsden Please re-read prior feedback.

@lukemarsden
Copy link
Contributor Author

@bgrant0607 @ghodss @smarterclayton thanks for the feedback! I'll address this in another rev of the proposal shortly.

@bgrant0607
Copy link
Member

@lukemarsden Thanks.

Another way to look at this: Assume that apply will get some of the same flags, such as --selector, as other commands (e.g., delete, get, replace). How should --purge-missing interact with those flags?

@bgrant0607
Copy link
Member

Relevant flags:

  • --selector
  • --all
  • --all-namespaces

I assume that by default the deletion behavior will correspond to delete --cascade=true --ignore-not-found=true --now=false.

@bgrant0607
Copy link
Member

@lukemarsden Is this proposal still active? I would like to see it finished.

@mikedanese
Copy link
Member

FYI, there is a WIP implementation here #33075

@bgrant0607
Copy link
Member

#33075 merged.

@bgrant0607 bgrant0607 closed this Oct 10, 2016
@errordeveloper errordeveloper deleted the kubectl-apply-purge-from-namespace branch October 11, 2016 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl kind/design Categorizes issue or PR as related to design. release-note-none Denotes a PR that doesn't merit a release note. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. 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.

kubectl apply should be able to delete objects missing from supplied config (aka prune)