Skip to content

Instantly share code, notes, and snippets.

@ninlil
ninlil / kapiver.sh
Created September 1, 2021 07:44
Get applied and effective apiVersion from Kubernetes objects
#!/bin/bash
if [ "x$1" == "x" ] || [ "x$2" == "x" ]; then
echo "Usage: $(basename $0) {type} {namespace}"
echo " $(basename $0) {type} -A"
exit 1
fi
kubectl get $([ "x$2" = "x-A" ] && echo "-A" || echo "-n $2") $1 -o json | \
jq -r '.items[] | "\(.kind) \(.metadata.namespace) \(.metadata.name) \(.apiVersion) \(.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration" | fromjson | .apiVersion)"' |\