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 diff ignores namespace #70843

Open
toothbrush opened this Issue Nov 9, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@toothbrush

toothbrush commented Nov 9, 2018

What happened:

I have a file myfile.yml which contains something like this – minimal working example: (note the namespace)

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
  namespace: kube-system
  labels:
    app: nginx
spec:
  template:
    metadata:
      labels:
        name: nginx
    spec:
      dnsPolicy: Default
      containers:
        - image: nginx:latest
          name: nginx

After successfully deploying this to a cluster, running

$ kubectl alpha diff -f myfile.yml LAST LOCAL

Shows the entire file as a diff, as if i had never deployed the Deployment:

diff -u -N /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LAST-540113411/nginx /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LOCAL-145015686/nginx
--- /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LAST-540113411/nginx	2018-11-09 14:08:49.000000000 +1100
+++ /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LOCAL-145015686/nginx	2018-11-09 14:08:49.000000000 +1100
@@ -0,0 +1,17 @@
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+  labels:
+    app: nginx
+  name: nginx
+spec:
+  template:
+    metadata:
+      labels:
+        name: nginx
+    spec:
+      containers:
+      - image: nginx:latest
+        name: nginx
+      dnsPolicy: Default

However, if i specify the namespace on the CLI things are different (and closer to what i expect):

$ kubectl alpha diff -n kube-system -f myfile.yml LAST LOCAL
diff -u -N /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LAST-238279227/nginx /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LOCAL-902844510/nginx
--- /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LAST-238279227/nginx	2018-11-09 14:10:42.000000000 +1100
+++ /var/folders/wz/9znz2f_12538yqt5cwht1mn40000gn/T/LOCAL-902844510/nginx	2018-11-09 14:10:42.000000000 +1100
@@ -1,11 +1,9 @@
 apiVersion: extensions/v1beta1
 kind: Deployment
 metadata:
-  annotations: {}
   labels:
     app: nginx
   name: nginx
-  namespace: kube-system
 spec:
   template:
     metadata:

What you expected to happen:

I would expect the diff to be empty, because the Deployment is live on the cluster. Then, if i add something to the file, such as an annotation, i would want just that diff to show up. Specifically, there's weirdness around the namespace: it's not read from my local YML file, only when i specify it on the CLI. Also note the empty annotations hash, but that's not as serious an issue.

Environment:

  • Kubernetes version (use kubectl version):
Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.2", GitCommit:"17c77c7898218073f14c8d573582e8d2313dc740", GitTreeState:"clean", BuildDate:"2018-10-30T21:39:38Z", GoVersion:"go1.11.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.2", GitCommit:"17c77c7898218073f14c8d573582e8d2313dc740", GitTreeState:"clean", BuildDate:"2018-10-24T06:43:59Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration: Kubernetes manually deployed on AWS (but this doesn't seem relevant)
  • OS (e.g. from /etc/os-release): Client is macOS 10.13.6, Server is Ubuntu 18.04.1 LTS
  • Kernel (e.g. uname -a): Linux ip-x-x-x-x 4.15.0-1023-aws #23-Ubuntu SMP Mon Sep 24 16:31:06 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

/kind bug

@toothbrush

This comment has been minimized.

toothbrush commented Nov 9, 2018

/sig cli

@k8s-ci-robot k8s-ci-robot added sig/cli and removed needs-sig labels Nov 9, 2018

@zegl

This comment has been minimized.

Contributor

zegl commented Nov 11, 2018

This bug seems to have been fixed as of the current master.

~/src/kubernetes bazel-bin/cmd/kubectl/darwin_amd64_pure_stripped/kubectl apply -f diff-bug.yaml
deployment.extensions/nginx created

~/src/kubernetes bazel-bin/cmd/kubectl/darwin_amd64_pure_stripped/kubectl diff -f diff-bug.yaml
# No output

~/src/kubernetes bazel-bin/cmd/kubectl/darwin_amd64_pure_stripped/kubectl -n kube-system diff -f diff-bug.yaml
# No output

~/src/kubernetes bazel-bin/cmd/kubectl/darwin_amd64_pure_stripped/kubectl -n default diff -f diff-bug.yaml
error: the namespace from the provided object "kube-system" does not match the namespace "default". You must pass '--namespace=kube-system' to perform this operation.
@toothbrush

This comment has been minimized.

toothbrush commented Nov 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment