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 apply ignoring changes to spec.initcontainers field #47264

Closed
dhawal55 opened this issue Jun 9, 2017 · 26 comments · Fixed by #51816
Closed

kubectl apply ignoring changes to spec.initcontainers field #47264

dhawal55 opened this issue Jun 9, 2017 · 26 comments · Fixed by #51816
Labels
sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@dhawal55
Copy link
Contributor

dhawal55 commented Jun 9, 2017

BUG REPORT

Kubernetes version (use kubectl version):

Client Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.4", GitCommit:"d6f433224538d4f9ca2f7ae19b252e6fcb66a3ae", GitTreeState:"clean", BuildDate:"2017-05-19T20:41:07Z", GoVersion:"go1.8.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.2+coreos.0", GitCommit:"79fee581ce4a35b7791fdd92e0fc97e02ef1d5c0", GitTreeState:"clean", BuildDate:"2017-04-19T23:13:34Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}

Environment:

  • Cloud provider or hardware configuration: AWS
  • OS (e.g. from /etc/os-release): CoreOS 1409.1.0
  • Kernel (e.g. uname -a): Linux 4.11.2-coreos Unit test coverage in Kubelet is lousy. (~30%) #1 SMP Tue May 23 22:04:34 UTC 2017 x86_64 Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz GenuineIntel GNU/Linux

What happened:
kubectl apply ignores changes in spec.initcontainers field. The spec.initContainers field is also mirrored into alpha and beta annotations. I think the annotations from the previous run overwrite the changes specified in spec.initcontainers field. If I apply my changes as annotations, it works. Also, there is no --feature-gates option in kube-apiserver to turn it off annotations for initcontainers.

What you expected to happen:
spec.initcontainers changes should trump over annotations

How to reproduce it (as minimally and precisely as possible):
Create a deployment with spec.initcontainer field populated in pod template. Apply the deployment. Make changes spec.initcontainer field and apply again. kubectl says deployment is configured but your changes are not applied

@k8s-github-robot
Copy link

@dhawal55 There are no sig labels on this issue. Please add a sig label by:
(1) mentioning a sig: @kubernetes/sig-<team-name>-misc
(2) specifying the label manually: /sig <label>

Note: method (1) will trigger a notification to the team. You can find the team list here and label list here

@k8s-github-robot k8s-github-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jun 9, 2017
@jagosan
Copy link
Contributor

jagosan commented Jun 9, 2017

/sig cli

@k8s-ci-robot k8s-ci-robot added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Jun 9, 2017
@k8s-github-robot k8s-github-robot removed the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jun 9, 2017
@mengqiy
Copy link
Member

mengqiy commented Jun 9, 2017

Same issue report in kubernetes/kubectl#27. I believe Strategic Merge Patch works kubernetes/kubectl#27 (comment). It seems not a cli issue.
I think this an api machinery issue. @kubernetes/sig-api-machinery-misc

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 9, 2017
@dchen1107
Copy link
Member

Do we have the same issue in 1.7?

cc/ @kubernetes/kubernetes-release-managers

@mengqiy
Copy link
Member

mengqiy commented Jun 9, 2017

Yes.

@xingzhou
Copy link
Contributor

seems according to the doc, only "Changes to the Init Container spec are limited to the container image field.", IIUC, kubernetes/kubectl#27 is trying to update the image field, if @mengqiy you are not working on this, I can help take a look at the issue.

@mengqiy
Copy link
Member

mengqiy commented Jun 13, 2017

@xingzhou Thanks for triaging the issue.

@xingzhou
Copy link
Contributor

@erictune, I think the root cause of this issue is from these lines of code here. While when we try to update a pod object, we need to convert from v1.Pod to api.Pod, and the code in conversion function always overwrite the values in pod.Spec.InitContainers with the value of annotation pod.beta.kubernetes.io/init-containers. Therefore, when user changes the values in pod.Spec.InitContainers, it won't work.

One solution is to move the logic in the conversion function to pod's storage methods like create/update, in this case, at least we can realize that user is modifying the fields in pod.Spec.InitContainers. What's your idea on this?

@JulianWei
Copy link

JulianWei commented Jul 13, 2017

@xingzhou Is there any workaround?

@MartinodF
Copy link

@JulianWei you can just go back to specifying your init containers using the beta annotation (pod.beta.kubernetes.io/init-containers), it works correctly. When this bug is fixed, you will be able to use the stable InitContainers field. A bit annoying, but easy to fix :)

@smarterclayton
Copy link
Contributor

smarterclayton commented Jul 14, 2017 via email

@JulianWei
Copy link

@MartinodF, thank you

@alc6379
Copy link

alc6379 commented Aug 4, 2017

I don't know if this is relevant or not, but it appears that if you never used annotations at all and have only ever used initContainers in your yaml, apply doesn't seem to touch that, either.

@2rs2ts
Copy link
Contributor

2rs2ts commented Aug 24, 2017

The beta annotations do not work for us. We've even tried to delete our daemonset and and only use the beta annotations but changes don't get noticed.

@kevingessner
Copy link

Is there any way this could be fixed for 1.7.x? Due to this bug, on 1.7 and earlier, the only reliable way to use init containers is to use the pod.beta.kubernetes.io/init-containersannotation, not the newer initContainers field. But in 1.8 (as of 6ec80ea), that annotation is going away. That means that a given pod spec can't be compatible with both 1.7 (where the annotation is required) and 1.8 (where the annotation is unsupported), without duplicating the init containers.

Fixing this in 1.7.x -- so the initContainers field is supported for updates -- would make the migration smoother, as the initContainers field could be used always. Is it too late to get this narrow problem fixed in the next 1.7 release?

@liggitt
Copy link
Member

liggitt commented Sep 6, 2017

Unfortunately, the annotations have to take precedence as long as 1.5 kubelets are supported (which is through 1.7.x), or updates from those kubelets would not correctly update the objects. 1.8 is the earliest that behavior could be dropped, and was why 6ec80ea was possible.

That conflict between honoring the earliest API representation (via annotations) to preserve skewed compatibility and having an API that isn't insane to use is why annotations are no longer used as an alpha/beta-stage mechanism for new fields.

@liggitt
Copy link
Member

liggitt commented Sep 6, 2017

fixed in #51816

@liggitt liggitt closed this as completed Sep 6, 2017
@matthiasr
Copy link

So do I understand correctly that currently the safe way is to always duplicate the init container between the annotation and the actual field, and then after upgrading to 1.8 drop the annotation?

@liggitt
Copy link
Member

liggitt commented Sep 7, 2017

So do I understand correctly that currently the safe way is to always duplicate the init container between the annotation and the actual field, and then after upgrading to 1.8 drop the annotation?

Correct. Pre-1.8, the information is duplicated in two places in the object, with the annotation taking precedence. 1.8+, only the field is honored. You should set the field for forward compatibility, and set the annotation if you want your changes to be effective against a pre-1.8 server.

@matthiasr
Copy link

matthiasr commented Sep 7, 2017 via email

@clhodapp
Copy link

Rather than manually duplicating the same content to multiple places, I've found that if you explicitly set both the alpha and the beta annotations to null, you can get the desired behavior out of the system in 1.7: initContainer updates will actually take effect and the actual API-level annotations will simply track the initContainers field.

@kevingessner
Copy link

Thanks @clhodapp -- that's super clever, and it works on 1.6 as well.

@linse
Copy link

linse commented Nov 14, 2017

@clhodapp I'm working with @kevingessner and found today that your fix worked only for existing deployments and not for new ones on 1.6.
Just in case anyone else gets stuck on this, the error message is misleading (Error from server (BadRequest): error when creating "STDIN": Deployment in version "v1beta1" cannot be handled as a Deployment: unexpected end of JSON input) and the config still passes fine with --dry-run. So not backwards compatible for us, unfortunately.

@clhodapp
Copy link

Thanks for posting your finding, @linse. It sounds like the only real fix here is updating to 1.8 then.

@Noah-Huppert
Copy link

I am still encountering this issue with Kubernetes version:

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"dd5e1a2978fd0b97d9b78e1564398aeea7e7fe92", GitTreeState:"clean", BuildDate:"2018-04-19T00:05:56Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.4-gke.0", GitCommit:"c08fe9548257472151a8fa298bd6c3e9ea1b8c09", GitTreeState:"clean", BuildDate:"2018-06-06T11:34:07Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}

I have tried setting the alpha and beta annotations to null.

@apodkutin
Copy link

apodkutin commented Oct 26, 2018

@linse, @clhodapp, @Noah-Huppert Actually, there is a way to avoid Deployment in version "v1beta1" cannot be handled as a Deployment: unexpected end of JSON input)
If there is no deployment created yet, you can remove:

annotations:
  pod.beta.kubernetes.io/init-containers: null
  pod.alpha.kubernetes.io/init-containers: null

and left only initContainers:, deployment will have been created without errors and init container will be there.
And if you already have deployment in your namespace you can left:

annotations:
  pod.beta.kubernetes.io/init-containers: null
  pod.alpha.kubernetes.io/init-containers: null

with initContainers: in your descriptor an your deployment will have been updated along with the init container.
Kubernetes version:

Client Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.12", GitCommit:"3bda299a6414b4866f179921610d6738206a18fe", GitTreeState:"clean", BuildDate:"2017-12-29T09:00:00Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.12", GitCommit:"3bda299a6414b4866f179921610d6738206a18fe", GitTreeState:"clean", BuildDate:"2017-12-29T08:39:49Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}

ruvr pushed a commit to sapcc/helm-charts that referenced this issue Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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.