itaysk / kubectl-neat

Clean up Kubernetes yaml and json output to make it readable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: KUBECTL_EXTERNAL_DIFF support

abentley-ssimwave opened this issue · comments

kubectl diff and kubectl neat are both nice improvements, but they're even better together.

The problem with kubectl diff is that it can obscure actual changes through the inclusion of a bunch of fields that are not relevant-- the very ones that kubectl-neat will trim.

kubectl diff supports a KUBECTL_EXTERNAL_DIFF environment variable. It's possible to use that variable to use kubectl neat to perform the diff through a reasonably simple script:

#!/bin/bash
set -euo pipefail

files="$(cat <(ls $1) <(ls $2) | sort | uniq)"
retcode=0
for file in $files; do
    diff -uN --label old/$file <(kubectl-neat -f $1/$file) --label new/$file <(kubectl-neat -f $2/$file) || retcode=$?
done
exit $retcode

But providing it as standardized functionality would help more people and avoid rewriting the above script, and ensure any edge cases are handled.

KUBECTL_EXTERNAL_DIFF does not support arguments, so it does not support subcommands. Supporting it would likely involve reading the basename of argument 0 and determining whether to behave as kubectl-neat or diff based on that. kubectl-neat could then be symlinked to that alternate name.

A diff subcommand could also be provided. This would act as a wrapper for kubectl diff, supplying an appropriate KUBECTL_EXTERNAL_DIFF value.