homeport / dyff

/ˈdʏf/ - diff tool for YAML files, and sometimes JSON
MIT License
1.27k stars 60 forks source link

[support] How to use `--filter` with `kubectl diff`? #161

Open madhukar93 opened 3 years ago

madhukar93 commented 3 years ago

I'm trying to only see diffs in the specs using #160 (similar to the original usecase #157 - trying to exclude metadata because it has server generated annotations I want to ignore) the following still reports diffs in metadata -

export KUBECTL_EXTERNAL_DIFF='dyff between --filter=spec --color=on --omit-header --set-exit-code'`
kustomize build . | kubectl diff -f -

I've tried variations with`--filter=/spec' and such, but haven't got the desired result, what am I missing?

HeavyWombat commented 3 years ago

Thanks for the question. I will have a look at it tomorrow. I assume I can take some Kubernetes related examples to try to reproduce the issue, right?

madhukar93 commented 3 years ago

Yes. Assuming that the versions of kubernetes, kubectl are irrelevant, any example should work. Thanks!

HeavyWombat commented 3 years ago

I am pretty busy at the moment, but I still have this on my agenda.

madhukar93 commented 3 years ago

Hey, thanks for bumping this. I muddled through what I wanted to do, but I'll also take a better look when I get time.

wsny commented 1 year ago

This is being caused by kubectl itself, as it will not allow the required characters for any of the filter, filter-regexp, exclude or exclude-regexp flags. See character restrictions here.

Can work around this by creating a script in your path with the following code, and using that as your KUBECTL_EXTERNAL_DIFF

$ cat _kc_diff
#!/usr/bin/env bash
dyff between --exclude=metadata.generation --set-exit-code --omit-header "$1" "$2"

$ export KUBECTL_EXTERNAL_DIFF="_kc_diff"