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 diff fails to detect differences in Service objects #1601

Open
jrcast opened this issue May 24, 2024 · 6 comments
Open

kubectl diff fails to detect differences in Service objects #1601

jrcast opened this issue May 24, 2024 · 6 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@jrcast
Copy link

jrcast commented May 24, 2024

What happened:
kubectl diff is not detecting diffs between a service's manifest file and the modified service object in Kubernetes. I tried both client-side or server-side mode without success.

What you expected to happen:
kubectl diff identifies the diff

How to reproduce:

  1. Create a K8s service using a manifest kubectl create -f my-svc.yaml. Where my-svc.yaml is:
    apiVersion: v1
    kind: Service
    metadata:
      name: example
      namespace: default
    spec:
      ports:
        - name: service-port
          port: 80
          protocol: TCP
          targetPort: service-port
      selector:
        app.kubernetes.io/instance: example
      type: ClusterIP
  2. Using kubectl edit, modify the K8s service. i.e. Add an extra port.
    apiVersion: v1
    kind: Service
    metadata:
      name: example
      namespace: default
    spec:
      ports:
        - name: service-port
          port: 80
          protocol: TCP
          targetPort: service-port
        - name: shouldntbehere    # <<<< THIS 
          port: 8080
          protocol: TCP
          targetPort: service-port
      selector:
        app.kubernetes.io/instance: example
      type: ClusterIP
  3. Run:
    kubectl diff -f my-svc.yaml
    # or
    kubectl diff -f my-svc.yaml --server-side --force-conflicts
  4. No diff shows up.

Anything else we need to know?:

Environment:

  • Kubernetes client and server versions (use kubectl version): 1.27 on both server/client. Also tried 1.30 with same results.
  • Cloud provider or hardware configuration: AWS EKS
  • OS (e.g: cat /etc/os-release): Ubuntu 22.04.4 LTS
@jrcast jrcast added the kind/bug Categorizes issue or PR as related to a bug. label May 24, 2024
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label May 24, 2024
@ardaguclu
Copy link
Member

Have you verified that the kubectl edit actually updated your service?

@kundan2707
Copy link

@jrcast have you checked if kubectl command executed successfully without error ?

@kundan2707
Copy link

/remove-kind bug

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. and removed kind/bug Categorizes issue or PR as related to a bug. labels May 27, 2024
@kundan2707
Copy link

/kind support

@k8s-ci-robot k8s-ci-robot added the kind/support Categorizes issue or PR as a support question. label May 27, 2024
@brianpursley
Copy link
Member

Can confirm this happens when you make changes using kubectl edit, and it does seem to have something to do with server side apply.

If you use the --save-config flag with edit, then kubectl diff will work:

kubectl edit service example --save-config
$ kubectl diff -f my-svc.yaml 
diff -u -N /tmp/LIVE-3530718821/v1.Service.default.example /tmp/MERGED-1768176721/v1.Service.default.example
--- /tmp/LIVE-3530718821/v1.Service.default.example	2024-05-28 11:44:49.052930430 -0400
+++ /tmp/MERGED-1768176721/v1.Service.default.example	2024-05-28 11:44:49.056930322 -0400
@@ -22,10 +22,6 @@
     port: 80
     protocol: TCP
     targetPort: service-port
-  - name: shouldntbehere
-    port: 8080
-    protocol: TCP
-    targetPort: service-port
   selector:
     app.kubernetes.io/instance: example
   sessionAffinity: None

But if you use that flag, it's going to add the kubectl.kubernetes.io/last-applied-configuration annotation, which shouldn't be a requirement for diff.

/remove-kind support
/kind bug

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. and removed kind/support Categorizes issue or PR as a support question. labels May 28, 2024
@ardaguclu
Copy link
Member

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 5, 2024
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. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. priority/backlog Higher priority than priority/awaiting-more-evidence. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

5 participants