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 for porcelain commands to make working with the last-applied… #287

Merged
merged 1 commit into from
Feb 11, 2017

Conversation

pwittrock
Copy link
Member

…-config easier

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 25, 2017
@pwittrock
Copy link
Member Author

cc @kubernetes/sig-cli-api-reviews

@liggitt @fabianofranz @adohe WDYT of this?

cc @shiywang

@mengqiy
Copy link
Member

mengqiy commented Jan 26, 2017

kubectl edit will update the annotation if the last-applied-config already exists. It will save almost everything in the last-applied-config. It will cause trouble for apply to manage the fields.
So we may need to change edit's behavior.

@liggitt
Copy link
Member

liggitt commented Jan 26, 2017

So we may need to change edit's behavior.

why? if a user edits a resource, is it not essentially an in-place apply?

@mengqiy
Copy link
Member

mengqiy commented Jan 26, 2017

IMO one of the ideas in this proposal is that last-applied-config should only keep the fields that is manged by apply. e.g. if we want an autoscaler to manage a field like replica count, we should not save it in the annotation.

edit is doing a 2-way diff, and it will save almost all fields in the annotation. This behavior may cause trouble to the idea above.

@pwittrock
Copy link
Member Author

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.

why? if a user edits a resource, is it not essentially an in-place apply?

How do you define apply in this context? As I understand it, apply is a utility for managing a kubernetes object using a local configuration file. In the case of edit, no configuration file is used.

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?

@pwittrock
Copy link
Member Author

pwittrock commented Jan 26, 2017

edit is doing a 2-way diff, and it will save almost all fields in the annotation. This behavior may cause trouble to the idea above.

Good catch. This is definitely wrong. We don't want it to do this.

@thockin
Copy link
Member

thockin commented Jan 27, 2017

We have a lot of addons that are apply'ed into existence. End-users seem to find new ways to hurt themselves on every release by changing the value of some field that we didn't specify. Often args or env or things like that, it seems. They get "unhappy" when we nuke those changes.

@pwittrock
Copy link
Member Author

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

@pwittrock
Copy link
Member Author

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.

@liggitt
Copy link
Member

liggitt commented Jan 27, 2017

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.

so if I use apply, I can't use label, annotate, edit, etc? that's unfortunate

@mengqiy
Copy link
Member

mengqiy commented Jan 27, 2017

so if I use apply, I can't use label, annotate, edit, etc? that's unfortunate

IMO if label and annotate are updating a field that is not owned by apply (not in the last-applied-config annotation), that operation is OK.
@pwittrock has a related doc PR to teach the users how to manage the resource.

@mengqiy
Copy link
Member

mengqiy commented Jan 27, 2017

@pwittrock created kubernetes/kubernetes#40626

@pwittrock
Copy link
Member Author

pwittrock commented Jan 27, 2017

@liggitt

so if I use apply, I can't use label, annotate, edit, etc? that's unfortunate

That is not the intention, but the current implementation of edit breaks kubectl apply. We need to follow up on annotate, label, scale, set, etc and get everything working consistently.

The reason edit is broken now is that the last-applied-config is essentially a list of fields to delete if they do not appear in the configuration file provided to apply. Having edit update the annotation essentially says "have apply delete all my changes if I don't add them back to the configuration file before apply is next called". This seems like the wrong behavior to me, and IMHO the proper behavior is to have apply ignore any changes made by edit so long as they don't conflict with the fields set in the configuration file.

Let me know if it would be helpful to go through a few use cases and the resulting state.

@pwittrock
Copy link
Member Author

@liggitt FYI, I have this proposal for better support around using apply with imperative kubectl commands (edit, set, label, scale, annotate, patch, etc) #303

@pwittrock
Copy link
Member Author

@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
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Contributor

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.

@pwittrock
Copy link
Member Author

@adohe He Tony, I am assigning this to you for approval. Once you approve I plan to move forward with having it implemented.

@shiywang You will be implementing this

@jessfraz Would you shepherd through the new contributor process?

@jessfraz
Copy link
Contributor

jessfraz commented Feb 1, 2017

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.
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Contributor

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
Copy link
Member

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.

Copy link
Member Author

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`
Copy link
Member

Choose a reason for hiding this comment

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

s/get/view/

Copy link
Member Author

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`
Copy link
Member

Choose a reason for hiding this comment

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

s/get/view/

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@pwittrock
Copy link
Member Author

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

@shiywang
Copy link

shiywang commented Feb 3, 2017

@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
Copy link

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 ?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

SGTM

@pwittrock
Copy link
Member Author

@shiywang Yes. You should start with kubectl apply view last-applied

The following should be supported:

  • kubectl apply view last-applied -f filename.yaml
  • kubectl apply view last-applied kind/name

@shiywang
Copy link

shiywang commented Feb 8, 2017

@pwittrock kubectl apply view last-applied is almost done, will open another pr to address apply set.

@pwittrock
Copy link
Member Author

Thanks for the feedback Tony. Tried to include the answers to your questions in the updated doc. PTAL

@pwittrock
Copy link
Member Author

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
Copy link
Member

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)

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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

@pwittrock
Copy link
Member Author

@janetkuo updated with your feedback.

@adohe Are we good to merge this?

@adohe-zz
Copy link
Contributor

adohe-zz commented Feb 11, 2017

Next week I am going to try to write 6 more design proposals that I intend to cover the majority of >our usability gaps.

Really look forward to this. 👍

@adohe-zz
Copy link
Contributor

@pwittrock yes, LGTM. I am going to merge this.

@adohe-zz adohe-zz merged commit 26d03a0 into kubernetes:master Feb 11, 2017
@adohe-zz
Copy link
Contributor

@shiywang finally we get this proposal approved, please take a look since you have started working on this. :)

@shiywang
Copy link

@adohe ok,this is great!!! thank you all 👍

@shiywang
Copy link

shiywang commented Feb 18, 2017

@pwittrock set-last-applied is ready for review, will be working on edit-last-applied

k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Feb 23, 2017
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
k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Feb 27, 2017
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
```
ruebenramirez pushed a commit to ruebenramirez/community that referenced this pull request Apr 22, 2017
Proposal for porcelain commands to make working with the last-applied…
enisoc pushed a commit to enisoc/kubernetes that referenced this pull request May 26, 2017
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.
krmayankk pushed a commit to krmayankk/kubernetes that referenced this pull request Oct 25, 2017
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
MadhavJivrajani pushed a commit to MadhavJivrajani/community that referenced this pull request Nov 30, 2021
Proposal for porcelain commands to make working with the last-applied…
danehans pushed a commit to danehans/community that referenced this pull request Jul 18, 2023
* Add self to the TOC (it's that easy!).

* And fix Louis' avatar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants