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

kubectl annotate patches too much #49044

Closed
MikeSpreitzer opened this issue Jul 17, 2017 · 6 comments · Fixed by #49259
Closed

kubectl annotate patches too much #49044

MikeSpreitzer opened this issue Jul 17, 2017 · 6 comments · Fixed by #49259
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@MikeSpreitzer
Copy link
Member

Is this a BUG REPORT or FEATURE REQUEST?:

Uncomment only one, leave it on its own line:

/kind bug

/kind feature

What happened:
I used kubectl --v=10 annotate to learn about patching object metadata, and was surprised to find more than the metadata in the PATCH request body. Here is an example:

    $ kubectl --v=10 annotate pods mypod bar=foo
    ...
    I0717 18:55:21.106675  161234 request.go:991] Request Body: {"metadata":{"annotations":{"bar":"foo"}},"status":{"conditions":[{"lastProbeTime":null,"lastTransitionTime":"2017-07-14T00:36:40Z","status":"True","type":"Initialized"},{"lastProbeTime":null,"lastTransitionTime":"2017-07-14T00:37:06Z","status":"True","type":"Ready"},{"lastProbeTime":null,"lastTransitionTime":"2017-07-14T00:36:40Z","status":"True","type":"PodScheduled"}]}}

    I0717 18:55:21.106795  161234 round_trippers.go:398] curl -k -v -XPATCH  -H "Content-Type: application/merge-patch+json" -H "User-Agent: kubectl/v1.6.4 (linux/amd64) kubernetes/d6f4332" -H "Accept: application/json" https://172.16.11.12:443/api/v1/namespaces/default/pods/mypod

    I0717 18:55:21.112228  161234 round_trippers.go:417] PATCH https://172.16.11.12:443/api/v1/namespaces/default/pods/mypod 200 OK in 5 milliseconds

What you expected to happen:
I expected to see my new annotation, but not the pod's status, in the request body.

How to reproduce it (as minimally and precisely as possible):
I hope the above makes this clear.

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): 1.6.4 in client and server
  • Cloud provider or hardware configuration**: bare metal install
  • OS (e.g. from /etc/os-release): Ubuntu 16.04
  • Kernel (e.g. uname -a): 4.4.0-34-generic
  • Install tools: private Ansible
  • Others: N/A
@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 17, 2017
@k8s-github-robot
Copy link

@MikeSpreitzer
There are no sig labels on this issue. Please add a sig label by:

  1. mentioning a sig: @kubernetes/sig-<group-name>-<group-suffix>
    e.g., @kubernetes/contributor-experience-<group-suffix> to notify the contributor experience sig, OR

  2. specifying the label manually: /sig <label>
    e.g., /sig scalability to apply the sig/scalability label

Note: Method 1 will trigger an email to the group. You can find the group list here and label list here.
The <group-suffix> in the method 1 has to be replaced with one of these: bugs, feature-requests, pr-reviews, test-failures, proposals

@k8s-github-robot k8s-github-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jul 17, 2017
@MikeSpreitzer
Copy link
Member Author

@kubernetes/sig-cli-bugs

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. kind/bug Categorizes issue or PR as related to a bug. labels Jul 17, 2017
@k8s-ci-robot
Copy link
Contributor

@MikeSpreitzer: Reiterating the mentions to trigger a notification:
@kubernetes/sig-cli-bugs.

In response to this:

@kubernetes/sig-cli-bugs

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-github-robot k8s-github-robot removed the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jul 17, 2017
@mengqiy
Copy link
Member

mengqiy commented Jul 17, 2017

Can you provide the step to reproduce?

@MikeSpreitzer
Copy link
Member Author

MikeSpreitzer commented Jul 18, 2017

Just make a pod, then

$ kubectl --v=10 annotate pods $podname bar=foo

@dixudx
Copy link
Member

dixudx commented Jul 18, 2017

The root cause is that when creating a patch for merge, nil value will be considered as different value. That's why status (due to "lastProbeTime":null) is in the request body.

Will create a PR to vendor when evanphx/json-patch #45 gets merged.

k8s-github-robot pushed a commit that referenced this issue Jul 26, 2017
Automatic merge from submit-queue (batch tested with PRs 49259, 49350)

update json-patch to fix nil value issue when creating mergepatch

**What this PR does / why we need it**:
When [creating a patch for merge](https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/annotate.go#L255), nil value will be considered as different value. This has been fixed and merged in [evanphx/json-patch #45](evanphx/json-patch#45).

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #49044

**Special notes for your reviewer**:
/cc @MikeSpreitzer @mengqiy 

**Release note**:

```release-note
Fix nil value issue when creating json patch for merge
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants