vmware-archive/kubecfg

kubecfg diff is showing incorrect information (marking unchanged lines as changed, ...)

mplzik opened this issue · 9 comments

When running kubecfg diff on our infrastructure, the output often contains lines that do no change, e.g.:

$ kubecfg diff my/config.jsonnet
...
-    "replicas": 1,
+    "replicas": 1,
...
               {
-                "containerPort": 8089,
+                "containerPort": 8089,
                 "name": "whatever",
                 "protocol": "TCP"
               }
...

Moreover, we've seen cases when the diff was out-of-context, e.g. environment variable showing a value change to a value that should belong to another environment variable according to the configuration.

$ kubecfg version
kubecfg version: v0.9.0
jsonnet version: v0.10.0
client-go version: v0.0.0-master+$Format:%h$
seh commented

Not having inspected the code, I think these port differences show up due to the “int ot string” representation used in the Kubernetes API. Perhaps kubecfg is reading an integer (or just a number) from the evaluated Jsonnet output, but the API server is presenting a string for the corresponding field’s value.

That might indeed be a part of the problem (but IIRC, I tried representing my values as both strings and ints and in both cases I got invalid output, so it might be a bit more intricate). Another issue might be hidden inside gojsondiff library -- there are a few open issues that result in incorrect diffs produced, e.g.:

W.r.t. the issues I mentioned, while the first one (no-op diff lines) are just an annoyance, the other issue I mentioned (likely related to yudai/gojsondiff#24) is actually dangerous, since it presents the user with false infrastructure changes data; I'd recommend prioritizing that one.

Thanks for the problem report. Yes, the current diff code is the simplest thing I could put together, and could benefit from some actual thought. Designs/patches up to entire replacements welcome.

Would you be OK with a plain stupid "format both JSONs and run diff on them"-like approach? That would probably be reasonably fool-proof (although without any json-specific heuristics).

Friendly ping :) I attached my PR to update the diff code a bit; please let me know what you think about it. Some custom formatting code was needed to maintain backward compatibility.

bikeshed warning: I changed the color formatting to change color of text instead of text background, which I found quite hard to read. I'll be happy to revert the change if needed.

Fixed by #230

q3k commented

@anguslees Would it be possible to cut a new official release to contain this fix?

jjo commented

Would it be possible to cut a new official release to contain this fix?

+1 @q3k on -^, a 0.9.1 would suffice :)

mkmik commented

I reviewed the changes since 0.9.0 and they were all bug fixes. released as 0.9.1