Skip to content

Instantly share code, notes, and snippets.

@ninlil
Created September 1, 2021 07:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninlil/affbf7514d4e74c7634e77f47e172236 to your computer and use it in GitHub Desktop.
Save ninlil/affbf7514d4e74c7634e77f47e172236 to your computer and use it in GitHub Desktop.
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)"' |\
column -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment