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 results in incorrect/corrupted config if a fieldRef env var is added #26229

Closed
ghodss opened this issue May 24, 2016 · 9 comments
Closed
Labels
area/app-lifecycle area/kubectl kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@ghodss
Copy link
Contributor

ghodss commented May 24, 2016

$ cat simple-dpl.json
{
   "apiVersion": "extensions/v1beta1",
   "kind": "Deployment",
   "metadata": {
      "name": "simple"
   },
   "spec": {
      "replicas": 1,
      "template": {
         "metadata": {
            "labels": {
               "box.com/app": "simple"
            }
         },
         "spec": {
            "containers": [
               {
                  "name": "simple",
                  "image": "ubuntu:16.04",
                  "command": [
                     "sleep", "10000"
                  ],
                  "env": [
                     {
                        "name": "POD_NAME",
                        "valueFrom": {
                           "fieldRef": {
                              "fieldPath": "metadata.name"
                           }
                        }
                     },
                     {
                        "name": "EXAMPLE_VAR",
                        "value": "value"
                     }
                  ]
               }
            ]
         }
      }
   }
}
$ kubectl apply -f simple-dpl.json
deployment "simple" configured
# edit simple-dpl.yaml to add POD_NAMESPACE
$ cat simple-dpl.json
{
   "apiVersion": "extensions/v1beta1",
   "kind": "Deployment",
   "metadata": {
      "name": "simple"
   },
   "spec": {
      "replicas": 1,
      "template": {
         "metadata": {
            "labels": {
               "box.com/app": "simple"
            }
         },
         "spec": {
            "containers": [
               {
                  "name": "simple",
                  "image": "ubuntu:16.04",
                  "command": [
                     "sleep", "10000"
                  ],
                  "env": [
                     {
                        "name": "POD_NAME",
                        "valueFrom": {
                           "fieldRef": {
                              "fieldPath": "metadata.name"
                           }
                        }
                     },
                     {
                        "name": "POD_NAMESPACE",
                        "valueFrom": {
                           "fieldRef": {
                              "fieldPath": "metadata.namespace"
                           }
                        }
                     },
                     {
                        "name": "EXAMPLE_VAR",
                        "value": "value"
                     }
                  ]
               }
            ]
         }
      }
   }
}
$ kubectl apply --v=10 -f simple-dpl.json
I0525 17:37:38.404596   78630 loader.go:229] Config loaded from file /Users/sam/.kube/config
I0525 17:37:38.405171   78630 round_trippers.go:267] curl -k -v -XGET  -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.2.0+5cb86ee (darwin/amd64) kubernetes/5cb86ee" http://10.1.2.3:8080/api
I0525 17:37:38.409174   78630 round_trippers.go:286] GET http://10.1.2.3:8080/api 200 OK in 3 milliseconds
I0525 17:37:38.409188   78630 round_trippers.go:292] Response Headers:
I0525 17:37:38.409192   78630 round_trippers.go:295]     Content-Type: application/json
I0525 17:37:38.409195   78630 round_trippers.go:295]     Date: Thu, 26 May 2016 00:37:38 GMT
I0525 17:37:38.409198   78630 round_trippers.go:295]     Content-Length: 131
I0525 17:37:38.409250   78630 request.go:870] Response Body: {"kind":"APIVersions","versions":["v1"],"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]}
I0525 17:37:38.410394   78630 round_trippers.go:267] curl -k -v -XGET  -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.2.0+5cb86ee (darwin/amd64) kubernetes/5cb86ee" http://10.1.2.3:8080/apis
I0525 17:37:38.411002   78630 round_trippers.go:286] GET http://10.1.2.3:8080/apis 200 OK in 0 milliseconds
I0525 17:37:38.411018   78630 round_trippers.go:292] Response Headers:
I0525 17:37:38.411022   78630 round_trippers.go:295]     Content-Type: application/json
I0525 17:37:38.411025   78630 round_trippers.go:295]     Date: Thu, 26 May 2016 00:37:38 GMT
I0525 17:37:38.411028   78630 round_trippers.go:295]     Content-Length: 763
I0525 17:37:38.411060   78630 request.go:870] Response Body: {"kind":"APIGroupList","groups":[{"name":"autoscaling","versions":[{"groupVersion":"autoscaling/v1","version":"v1"}],"preferredVersion":{"groupVersion":"autoscaling/v1","version":"v1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]},{"name":"batch","versions":[{"groupVersion":"batch/v1","version":"v1"}],"preferredVersion":{"groupVersion":"batch/v1","version":"v1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]},{"name":"extensions","versions":[{"groupVersion":"extensions/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"extensions/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]}]}
I0525 17:37:38.411311   78630 round_trippers.go:267] curl -k -v -XGET  -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.2.0+5cb86ee (darwin/amd64) kubernetes/5cb86ee" http://10.1.2.3:8080/version
I0525 17:37:38.411752   78630 round_trippers.go:286] GET http://10.1.2.3:8080/version 200 OK in 0 milliseconds
I0525 17:37:38.411762   78630 round_trippers.go:292] Response Headers:
I0525 17:37:38.411765   78630 round_trippers.go:295]     Content-Type: application/json
I0525 17:37:38.411768   78630 round_trippers.go:295]     Date: Thu, 26 May 2016 00:37:38 GMT
I0525 17:37:38.411771   78630 round_trippers.go:295]     Content-Length: 146
I0525 17:37:38.411789   78630 request.go:870] Response Body: {
  "major": "1",
  "minor": "2",
  "gitVersion": "v1.2.0",
  "gitCommit": "5cb86ee022267586db386f62781338b0483733b3",
  "gitTreeState": "clean"
}
I0525 17:37:38.413284   78630 decoder.go:141] decoding stream as JSON
I0525 17:37:38.442553   78630 round_trippers.go:267] curl -k -v -XGET  -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.2.0+5cb86ee (darwin/amd64) kubernetes/5cb86ee" http://10.1.2.3:8080/api
I0525 17:37:38.445426   78630 round_trippers.go:286] GET http://10.1.2.3:8080/api 200 OK in 2 milliseconds
I0525 17:37:38.445441   78630 round_trippers.go:292] Response Headers:
I0525 17:37:38.445444   78630 round_trippers.go:295]     Content-Type: application/json
I0525 17:37:38.445447   78630 round_trippers.go:295]     Date: Thu, 26 May 2016 00:37:38 GMT
I0525 17:37:38.445449   78630 round_trippers.go:295]     Content-Length: 131
I0525 17:37:38.445492   78630 request.go:870] Response Body: {"kind":"APIVersions","versions":["v1"],"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]}
I0525 17:37:38.445685   78630 round_trippers.go:267] curl -k -v -XGET  -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.2.0+5cb86ee (darwin/amd64) kubernetes/5cb86ee" http://10.1.2.3:8080/apis
I0525 17:37:38.447819   78630 round_trippers.go:286] GET http://10.1.2.3:8080/apis 200 OK in 2 milliseconds
I0525 17:37:38.447831   78630 round_trippers.go:292] Response Headers:
I0525 17:37:38.447835   78630 round_trippers.go:295]     Content-Type: application/json
I0525 17:37:38.447837   78630 round_trippers.go:295]     Date: Thu, 26 May 2016 00:37:38 GMT
I0525 17:37:38.447840   78630 round_trippers.go:295]     Content-Length: 763
I0525 17:37:38.447864   78630 request.go:870] Response Body: {"kind":"APIGroupList","groups":[{"name":"autoscaling","versions":[{"groupVersion":"autoscaling/v1","version":"v1"}],"preferredVersion":{"groupVersion":"autoscaling/v1","version":"v1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]},{"name":"batch","versions":[{"groupVersion":"batch/v1","version":"v1"}],"preferredVersion":{"groupVersion":"batch/v1","version":"v1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]},{"name":"extensions","versions":[{"groupVersion":"extensions/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"extensions/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"10.0.2.15:443"}]}]}
I0525 17:37:38.448724   78630 round_trippers.go:267] curl -k -v -XGET  -H "Accept: application/json, */*" -H "User-Agent: kubectl/v1.2.0+5cb86ee (darwin/amd64) kubernetes/5cb86ee" http://10.1.2.3:8080/apis/extensions/v1beta1/namespaces/default/deployments/simple
I0525 17:37:38.449995   78630 round_trippers.go:286] GET http://10.1.2.3:8080/apis/extensions/v1beta1/namespaces/default/deployments/simple 200 OK in 1 milliseconds
I0525 17:37:38.450009   78630 round_trippers.go:292] Response Headers:
I0525 17:37:38.450015   78630 round_trippers.go:295]     Content-Length: 1775
I0525 17:37:38.450019   78630 round_trippers.go:295]     Content-Type: application/json
I0525 17:37:38.450023   78630 round_trippers.go:295]     Date: Thu, 26 May 2016 00:37:38 GMT
I0525 17:37:38.450060   78630 request.go:870] Response Body: {"kind":"Deployment","apiVersion":"extensions/v1beta1","metadata":{"name":"simple","namespace":"default","selfLink":"/apis/extensions/v1beta1/namespaces/default/deployments/simple","uid":"ebac7b27-22d9-11e6-872e-08002720aabc","resourceVersion":"989","generation":2,"creationTimestamp":"2016-05-26T00:36:43Z","labels":{"box.com/app":"simple"},"annotations":{"deployment.kubernetes.io/revision":"1","kubectl.kubernetes.io/last-applied-configuration":"{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"simple\",\"creationTimestamp\":null},\"spec\":{\"replicas\":1,\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"box.com/app\":\"simple\"}},\"spec\":{\"containers\":[{\"name\":\"simple\",\"image\":\"ubuntu:16.04\",\"command\":[\"sleep\",\"10000\"],\"env\":[{\"name\":\"POD_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.name\"}}},{\"name\":\"EXAMPLE_VAR\",\"value\":\"value\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"}},"spec":{"replicas":1,"selector":{"matchLabels":{"box.com/app":"simple"}},"template":{"metadata":{"creationTimestamp":null,"labels":{"box.com/app":"simple"}},"spec":{"containers":[{"name":"simple","image":"ubuntu:16.04","command":["sleep","10000"],"env":[{"name":"POD_NAME","valueFrom":{"fieldRef":{"apiVersion":"v1","fieldPath":"metadata.name"}}},{"name":"EXAMPLE_VAR","value":"value"}],"resources":{},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{}}},"strategy":{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":1,"maxSurge":1}}},"status":{"observedGeneration":2,"replicas":1,"updatedReplicas":1,"availableReplicas":1}}
I0525 17:37:38.453385   78630 request.go:541] Request Body: {"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"simple\",\"creationTimestamp\":null},\"spec\":{\"replicas\":1,\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"box.com/app\":\"simple\"}},\"spec\":{\"containers\":[{\"name\":\"simple\",\"image\":\"ubuntu:16.04\",\"command\":[\"sleep\",\"10000\"],\"env\":[{\"name\":\"POD_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.name\"}}},{\"name\":\"POD_NAMESPACE\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.namespace\"}}},{\"name\":\"EXAMPLE_VAR\",\"value\":\"value\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"},"creationTimestamp":null},"spec":{"template":{"spec":{"containers":[{"env":[{"name":"EXAMPLE_VAR","value":"value"}],"name":"simple"}]}}}}
I0525 17:37:38.453420   78630 round_trippers.go:267] curl -k -v -XPATCH  -H "Accept: application/json, */*" -H "Content-Type: application/strategic-merge-patch+json" -H "User-Agent: kubectl/v1.2.0+5cb86ee (darwin/amd64) kubernetes/5cb86ee" http://10.1.2.3:8080/apis/extensions/v1beta1/namespaces/default/deployments/simple
I0525 17:37:38.457324   78630 round_trippers.go:286] PATCH http://10.1.2.3:8080/apis/extensions/v1beta1/namespaces/default/deployments/simple 200 OK in 3 milliseconds
I0525 17:37:38.457337   78630 round_trippers.go:292] Response Headers:
I0525 17:37:38.457340   78630 round_trippers.go:295]     Content-Length: 1872
I0525 17:37:38.457343   78630 round_trippers.go:295]     Content-Type: application/json
I0525 17:37:38.457346   78630 round_trippers.go:295]     Date: Thu, 26 May 2016 00:37:38 GMT
I0525 17:37:38.457372   78630 request.go:870] Response Body: {"kind":"Deployment","apiVersion":"extensions/v1beta1","metadata":{"name":"simple","namespace":"default","selfLink":"/apis/extensions/v1beta1/namespaces/default/deployments/simple","uid":"ebac7b27-22d9-11e6-872e-08002720aabc","resourceVersion":"999","generation":3,"creationTimestamp":"2016-05-26T00:36:43Z","labels":{"box.com/app":"simple"},"annotations":{"deployment.kubernetes.io/revision":"1","kubectl.kubernetes.io/last-applied-configuration":"{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"simple\",\"creationTimestamp\":null},\"spec\":{\"replicas\":1,\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"box.com/app\":\"simple\"}},\"spec\":{\"containers\":[{\"name\":\"simple\",\"image\":\"ubuntu:16.04\",\"command\":[\"sleep\",\"10000\"],\"env\":[{\"name\":\"POD_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.name\"}}},{\"name\":\"POD_NAMESPACE\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.namespace\"}}},{\"name\":\"EXAMPLE_VAR\",\"value\":\"value\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"}},"spec":{"replicas":1,"selector":{"matchLabels":{"box.com/app":"simple"}},"template":{"metadata":{"creationTimestamp":null,"labels":{"box.com/app":"simple"}},"spec":{"containers":[{"name":"simple","image":"ubuntu:16.04","command":["sleep","10000"],"env":[{"name":"POD_NAME","valueFrom":{"fieldRef":{"apiVersion":"v1","fieldPath":"metadata.name"}}},{"name":"EXAMPLE_VAR","value":"value"}],"resources":{},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{}}},"strategy":{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":1,"maxSurge":1}}},"status":{"observedGeneration":2,"replicas":1,"updatedReplicas":1,"availableReplicas":1}}
deployment "simple" configured
$ kubectl get deployments -o json
{
    "kind": "List",
    "apiVersion": "v1",
    "metadata": {},
    "items": [
        {
            "kind": "Deployment",
            "apiVersion": "extensions/v1beta1",
            "metadata": {
                "name": "simple",
                "namespace": "default",
                "selfLink": "/apis/extensions/v1beta1/namespaces/default/deployments/simple",
                "uid": "ebac7b27-22d9-11e6-872e-08002720aabc",
                "resourceVersion": "1000",
                "generation": 3,
                "creationTimestamp": "2016-05-26T00:36:43Z",
                "labels": {
                    "box.com/app": "simple"
                },
                "annotations": {
                    "deployment.kubernetes.io/revision": "1",
                    "kubectl.kubernetes.io/last-applied-configuration": "{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"simple\",\"creationTimestamp\":null},\"spec\":{\"replicas\":1,\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"box.com/app\":\"simple\"}},\"spec\":{\"containers\":[{\"name\":\"simple\",\"image\":\"ubuntu:16.04\",\"command\":[\"sleep\",\"10000\"],\"env\":[{\"name\":\"POD_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.name\"}}},{\"name\":\"POD_NAMESPACE\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.namespace\"}}},{\"name\":\"EXAMPLE_VAR\",\"value\":\"value\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"
                }
            },
            "spec": {
                "replicas": 1,
                "selector": {
                    "matchLabels": {
                        "box.com/app": "simple"
                    }
                },
                "template": {
                    "metadata": {
                        "creationTimestamp": null,
                        "labels": {
                            "box.com/app": "simple"
                        }
                    },
                    "spec": {
                        "containers": [
                            {
                                "name": "simple",
                                "image": "ubuntu:16.04",
                                "command": [
                                    "sleep",
                                    "10000"
                                ],
                                "env": [
                                    {
                                        "name": "POD_NAME",
                                        "valueFrom": {
                                            "fieldRef": {
                                                "apiVersion": "v1",
                                                "fieldPath": "metadata.name"
                                            }
                                        }
                                    },
                                    {
                                        "name": "EXAMPLE_VAR",
                                        "value": "value"
                                    }
                                ],
                                "resources": {},
                                "terminationMessagePath": "/dev/termination-log",
                                "imagePullPolicy": "IfNotPresent"
                            }
                        ],
                        "restartPolicy": "Always",
                        "terminationGracePeriodSeconds": 30,
                        "dnsPolicy": "ClusterFirst",
                        "securityContext": {}
                    }
                },
                "strategy": {
                    "type": "RollingUpdate",
                    "rollingUpdate": {
                        "maxUnavailable": 1,
                        "maxSurge": 1
                    }
                }
            },
            "status": {
                "observedGeneration": 3,
                "replicas": 1,
                "updatedReplicas": 1,
                "availableReplicas": 1
            }
        }
    ]
}

Happens on both 1.2.0 and HEAD (69b9002).

Notice that POD_NAMESPACE is missing in the spec, but is present in last-applied-configuration. Also, EXAMPLE_VAR must be present for this bug to reproduce.

This is a pretty severe issue IMO and ideally would be fixed in a 1.2.x point release (as well as 1.3) - we ended up with corrupted data because of it because we were referring to $(POD_NAMESPACE) in one env var which successfully was modified, but the POD_NAMESPACE didn't get added.

@bgrant0607 bgrant0607 added kind/bug Categorizes issue or PR as related to a bug. help-wanted priority/backlog Higher priority than priority/awaiting-more-evidence. area/kubectl labels May 24, 2016
@bgrant0607
Copy link
Member

cc @kubernetes/kubectl

@bgrant0607
Copy link
Member

@ghodss Output of kubectl version and dump of the patch request please.

@adohe-zz
Copy link

@ghodss also could you tell me how you you create the original source? I tried to reproduce this issue on HEAD but just failed. Below are steps to reproduce:

[tony@localhost kubernetes]$ cluster/kubectl.sh create -f ~/Desktop/yaml/test_k8s/simple-dpl.yaml
deployment "simple" created
[tony@localhost kubernetes]$ cluster/kubectl.sh apply -f ~/Desktop/yaml/test_k8s/simple-dpl.yaml
deployment "simple" configured
[tony@localhost kubernetes]$ cluster/kubectl.sh get deployment
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
simple    1         1         1            1           1m
[tony@localhost kubernetes]$ cluster/kubectl.sh apply -f ~/Desktop/yaml/test_k8s/new-simple-dpl.yaml
deployment "simple" configured

here the new-simple-dpl.yaml is:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: simple
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: simple
    spec:
      containers:
        - name: ubuntu
          image: ubuntu:16.04
          command: ["sh", "-c", "while true; do env; sleep 10; done"]
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: VAR
              value: val-modified

after apply the new-simple-dpl.yaml the deployment is:

[tony@localhost kubernetes]$ cluster/kubectl.sh get deployment simple -o json
{
    "kind": "Deployment",
    "apiVersion": "extensions/v1beta1",
    "metadata": {
        "name": "simple",
        "namespace": "default",
        "selfLink": "/apis/extensions/v1beta1/namespaces/default/deployments/simple",
        "uid": "b03e2822-2221-11e6-a448-b05adacd35f7",
        "resourceVersion": "91",
        "generation": 5,
        "creationTimestamp": "2016-05-25T02:37:56Z",
        "labels": {
            "name": "simple"
        },
        "annotations": {
            "deployment.kubernetes.io/revision": "2",
            "kubectl.kubernetes.io/last-applied-configuration": "{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"simple\",\"creationTimestamp\":null},\"spec\":{\"replicas\":1,\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"name\":\"simple\"}},\"spec\":{\"containers\":[{\"name\":\"ubuntu\",\"image\":\"ubuntu:16.04\",\"command\":[\"sh\",\"-c\",\"while true; do env; sleep 10; done\"],\"env\":[{\"name\":\"POD_NAME\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.name\"}}},{\"name\":\"POD_NAMESPACE\",\"valueFrom\":{\"fieldRef\":{\"fieldPath\":\"metadata.namespace\"}}},{\"name\":\"VAR\",\"value\":\"val-modified\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"
        }
    },
    "spec": {
        "replicas": 1,
        "selector": {
            "matchLabels": {
                "name": "simple"
            }
        },
        "template": {
            "metadata": {
                "creationTimestamp": null,
                "labels": {
                    "name": "simple"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "ubuntu",
                        "image": "ubuntu:16.04",
                        "command": [
                            "sh",
                            "-c",
                            "while true; do env; sleep 10; done"
                        ],
                        "env": [
                            {
                                "name": "POD_NAME",
                                "valueFrom": {
                                    "fieldRef": {
                                        "apiVersion": "v1",
                                        "fieldPath": "metadata.name"
                                    }
                                }
                            },
                            {
                                "name": "VAR",
                                "value": "val-modified"
                            },
                            {
                                "name": "POD_NAMESPACE",
                                "valueFrom": {
                                    "fieldRef": {
                                        "apiVersion": "v1",
                                        "fieldPath": "metadata.namespace"
                                    }
                                }
                            }
                        ],
                        "resources": {},
                        "terminationMessagePath": "/dev/termination-log",
                        "imagePullPolicy": "IfNotPresent"
                    }
                ],
                "restartPolicy": "Always",
                "terminationGracePeriodSeconds": 30,
                "dnsPolicy": "ClusterFirst",
                "securityContext": {}
            }
        },
        "strategy": {
            "type": "RollingUpdate",
            "rollingUpdate": {
                "maxUnavailable": 1,
                "maxSurge": 1
            }
        }
    },
    "status": {
        "observedGeneration": 5,
        "replicas": 1,
        "updatedReplicas": 1,
        "availableReplicas": 1
    }
}

Also just as @bgrant0607 said, could you provide the dump of the patch request?

@ghodss ghodss changed the title kubectl apply results in incorrect/corrupted config if a fieldRef env var is added while another env var is modified kubectl apply results in incorrect/corrupted config if a fieldRef env var is added May 26, 2016
@ghodss
Copy link
Contributor Author

ghodss commented May 26, 2016

@adohe I'm not sure what happened but I think maybe with YAML it doesn't reproduce - I just re-did the test and edited the issue to include JSON examples and now it reproduces consistently, both on 1.2.0 and on HEAD. Also, it turns out you don't have to modify EXAMPLE_VAR, but it does have to be present. Can you try to reproduce again?

@ghodss
Copy link
Contributor Author

ghodss commented May 26, 2016

@bgrant0607 Added the patch request. Looks like kubectl isn't sending the new POD_NAMESPACE var.

@adohe-zz
Copy link

@ghodss sure, I will try to reproduce this again.

@bgrant0607
Copy link
Member

Could this be related to #25585?

@adohe-zz
Copy link

@ghodss @bgrant0607 I believe this is the same as #25585. This should be fixed #26418 is landed on HEAD.

@ghodss
Copy link
Contributor Author

ghodss commented Jun 20, 2016

Thanks @adohe!

@ghodss ghodss closed this as completed Jun 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/app-lifecycle area/kubectl kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

No branches or pull requests

3 participants