diff --git a/.zsh/config.sh.d/kubernetes.sh b/.zsh/config.sh.d/kubernetes.sh index abf0999..e0c3066 100644 --- a/.zsh/config.sh.d/kubernetes.sh +++ b/.zsh/config.sh.d/kubernetes.sh @@ -2,15 +2,18 @@ function kubectlgetall { local namespace="${1}" shift - for i in $( + for res in $( kubectl api-resources --verbs=list --namespaced -o name | grep -v "events.events.k8s.io" | grep -v "events" | sort | uniq ); do - echo "Resource:" $i >&2 - kubectl -n ${namespace} get --ignore-not-found ${i} "${@}" + echo "Resource: ${res}" >&2 + + kubectl \ + -n ${namespace} \ + get --ignore-not-found \ + "${res}" \ + "${@}" done } - -# vim: set ft=zsh : diff --git a/bin/kube-dump-namespace b/bin/kube-dump-namespace new file mode 100755 index 0000000..e2630af --- /dev/null +++ b/bin/kube-dump-namespace @@ -0,0 +1,37 @@ +#!/bin/bash +set -euo pipefail + +source ~/bin/script_framework.sh + +namespace="${1:-}" +[[ -n $namespace ]] || fatal "Missing namespace." + +step "Collecting available api-resources..." +api_rss=($( + kubectl api-resources --verbs=list --namespaced -o name | + grep -v "events.events.k8s.io" | + grep -v "events" | + sort | uniq +)) + +for rss in "${api_rss[@]}"; do + step "Fetching resources in api-resource ${rss}..." + + names=($( + kubectl -n "${namespace}" \ + get --ignore-not-found "${rss}" \ + -o name + )) + + for name in "${names[@]}"; do + echo -e "---\n" + + kubectl -n "${namespace}" \ + get -o yaml "${name}" + + echo + done + +done + +echo -e "..."