-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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 for porcelain commands to make working with the last-applied… #287
Conversation
cc @kubernetes/sig-cli-api-reviews @liggitt @fabianofranz @adohe WDYT of this? cc @shiywang |
|
why? if a user edits a resource, is it not essentially an in-place apply? |
IMO one of the ideas in this proposal is that last-applied-config should only keep the fields that is manged by
|
Are you familiar with use cases for running edit against an object managed by apply? Admittedly, I don't know much about the use cases for this.
How do you define apply in this context? As I understand it, Since the reason for the annotation is to identify fields deleted from a local file - so that a patch can be sent to clear them from the live object. In the case of edit, the local configuration is not updated unless it is done so out of band. Why would a user do this instead of updating the configuration file? |
Good catch. This is definitely wrong. We don't want it to do this. |
We have a lot of addons that are |
@thockin Is your comment specifically about edit, or does it relate to the other parts of this proposal? I agree we should fix edit. @ymqytw Would you file an issue about this and take it as an item for 1.6. Also please follow up with @liggitt to make sure his concerns are satisfied. Add it as an item to the sig-cli agenda for next week. @thockin FWIW, I am starting to write another proposal for how to address the issue around editing fields that were specified in the configuration used by apply. Essentially: Any kubectl command besides apply that writes to an object checks for the last-applied-config annotation and provides a warning before updating fields present in the annotation. |
cc @kubernetes/sig-cli-misc @kubernetes/sig-cli-feature-requests Any one else still want to review this? I'd like to be able to get actionable feedback or approval by the sig-cli meeting next Wednesday. |
so if I use apply, I can't use label, annotate, edit, etc? that's unfortunate |
IMO if |
That is not the intention, but the current implementation of The reason edit is broken now is that the Let me know if it would be helpful to go through a few use cases and the resulting state. |
@kubernetes/sig-cli-proposals I've added this as an agenda item to the meeting on Wednesday and would like to merge it afterward if there are no remaining open comments. |
1. Apply subcommands | ||
- `kubectl apply set/view/diff last-applied | ||
- a little bit odd to have 2 verbs in a row | ||
- improves discoverability to have these as subcommands so they are tied to apply |
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.
how would subcommands interact with resource-builder parsing of args? ran into this with an attempt at a configmap-specific edit subcommand
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.
Great question. How did you resolve it?
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 should only accept files, and not accept type/name for resources. Is it possible to configure the resource-builder in this manner? I assume so since it seems to work for apply.
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.
ah, looks like only the builders that specify ResourceTypeOrNameArgs(true, args...)
consume arbitrary args (like get
, describe
, edit
, label
, annotate
, etc)
create, replace, apply do not do this
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.
There should not be any problem, apply
just accept files. We could make same restriction to last-applied
subcommands.
SGTM! |
kubectl apply diff last-applied -f deployment_nginx.yaml | ||
``` | ||
|
||
Opens up a 2-way diff in the default diff viewer. last-applied is old, local configuration is new. |
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 is not 3-way diff. Is this because we already have apply --dry-run -o json
?
And is a 2-way diff helpful here? apply
is not doing a 2-way diff.
If we only care about deletions, 2-way diff is OK.
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.
My intention was that this was just a diff between the current and last applied config. It is meant to help users understand what they changed locally, but not show what was changed in the cluster.
I would like to see a different 3-way diff command for apply. Maybe kubectl apply diff
. This is more complicated though.
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.
I see. We should document this after implementing this.
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.
2-way diff is ok here, we are actually calculate the deletion.
1. Open the last-applied-config in an editor | ||
|
||
```sh | ||
kubectl apply edit last-applied -f deployment_nginx.yaml |
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.
last-applied-config lives in the annotation of the live obj. So we can support kubectl apply edit last-applied resource/name
.
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.
Yeah I like that.
4. Remove the replicas field from the last-applied-config so it doesn't get deleted next apply | ||
- `kubectl apply set last-applied -f deployment_nginx.yaml` | ||
5. Verify the last-applied-config has been updated | ||
- `kubectl apply get last-applied -f deployment_nginx.yaml` |
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.
s/get/view/
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.
yeah good idea
3. Edit the last-applied-config and remove the replicas field | ||
- `kubectl apply edit last-applied -f deployment_nginx.yaml` | ||
4. Verify the last-applied-config has been updated | ||
- `kubectl apply get last-applied -f deployment_nginx.yaml` |
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.
s/get/view/
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.
done
@shiywang made a few minor changes worth looking at. I think this is stable enough to begin implementing. Why don't you get started if you haven't already, and update the issue with the progress next week? |
@pwittrock, sounds good, but can I take a stab at part of this proposal first ? maybe one of a subcommand ? |
|
||
## Naming and Format possibilities | ||
|
||
### Naming |
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.
those 6 names below are possibilities ? or we should keep them all ?
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.
No, those were possibilities considered. We should only pick 1. I prefer the first one.
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.
last-applied
sounds good to me.
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.
@pwittrock I prefer the first one too, I think we should remove this possibilities
section from the final proposal, wdyt?
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.
SGTM
@shiywang Yes. You should start with The following should be supported:
|
@pwittrock |
Thanks for the feedback Tony. Tried to include the answers to your questions in the updated doc. PTAL |
Next week I am going to try to write 6 more design proposals that I intend to cover the majority of our usability gaps. |
|
||
1. Apply subcommands | ||
- `kubectl apply set/view/diff last-applied | ||
- a little bit odd to have 2 verbs in a row |
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.
It's also a bit odd to "view" something with kubectl apply
, which is supposed to update (not view) resources.
That aside, are we planning to add more sub-commands to kubectl apply view
? If not, should we combine view
and last-applied
?
I originally commented in kubernetes/kubernetes#41146 (review)
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.
Such as kubectl apply view-last-applied -f dir/
? That would work for me.
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.
Was that what you were thinking Janet? If so I will update the doc.
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.
FYI, this is my reason for kubectl apply view-last-applied
instead of kubectl view last-applied
. Interested in your thoughts.
My reasoning for organizing the commands like this is that it helps discoverability to put related commands closely together in the command tree. As a user, I probably want to discover all the commands related to apply and last-applied-configuration in one place, e.g. kubectl apply -h should print all the sub commands related to apply. Spreading the apply related commands across the tree will make it hard to discover new commands as well as pollute the other command namespaces.
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.
Yes, something like kubectl apply view-last-applied
was what I was thinking.
In kubernetes/kubernetes#41146 I originally suggested adding this feature in kubectl get
or kubectl describe
(maybe with a flag), since this command allows users to view resources instead of mutating them. However, after reading this proposal, I agree that discoverability is probably more important for this specific feature. Maybe just documenting "It's also a bit odd to view something with kubectl apply
, which is supposed to update (not view) resources" in the proposal is enough (showing that we're aware of this but choose discoverability over this.)
Really look forward to this. 👍 |
@pwittrock yes, LGTM. I am going to merge this. |
@shiywang finally we get this proposal approved, please take a look since you have started working on this. :) |
@adohe ok,this is great!!! thank you all 👍 |
@pwittrock |
Automatic merge from submit-queue (batch tested with PRs 41146, 41486, 41482, 41538, 41784) Add apply view-last-applied subcommand reopen pr #40984, implement part of kubernetes/community#287 for now unit test all pass, the output looks like: ```console shiywang@dhcp-140-33 template $ ./kubectl apply view last-applied deployment nginx-deployment apiVersion: extensions/v1beta1 kind: Deployment metadata: creationTimestamp: null name: nginx-deployment spec: strategy: {} template: metadata: creationTimestamp: null labels: app: nginx spec: containers: - image: nginx:1.12.10 name: nginx ports: - containerPort: 80 resources: {} status: {} ``` ```release-note Support new kubectl apply view-last-applied command for viewing the last configuration file applied ``` not sure if there is any flag I should updated or the some error handling I should changed. will generate docs when you guys think is ok. cc @pwittrock @jessfraz @adohe @ymqytw
Automatic merge from submit-queue (batch tested with PRs 42044, 41694, 41927, 42050, 41987) Add apply set-last-applied subcommand implement part of kubernetes/community#287, will rebase after #41699 got merged, EDIT: since bug output format has been confirmed, will update the behavior of output format soon cc @kubernetes/sig-cli-pr-reviews @adohe @pwittrock ```release-note Support kubectl apply set-last-applied command to update the applied-applied-configuration annotation ```
Proposal for porcelain commands to make working with the last-applied…
Automatic merge from submit-queue (batch tested with PRs 42256, 46479, 45436, 46440, 46417) Add `kubectl apply edit-last-applied` subcommand third command of kubernetes/community#287 Fixes kubernetes#44905 @pwittrock @adohe @ymqytw @kubernetes/sig-cli-feature-requests could you guys have an early review ? cause some of feature I'm not sure about, will add unit tests if you think it's ok.
Automatic merge from submit-queue (batch tested with PRs 53051, 52489, 53920). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Implement `kubectl alpha diff` to diff resources `kubectl alpha diff` lets you diff your resources against live resources, or last applied, or even preview what changes are going to be applied on the cluster. This is still quite premature, and mostly untested. **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: Clearly not ready for Release note. ```release-note NONE ``` kubernetes/community#287
Proposal for porcelain commands to make working with the last-applied…
* Add self to the TOC (it's that easy!). * And fix Louis' avatar
…-config easier