Improve k8s ressource listing / dumping

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-06-13 16:26:00 +02:00
parent 38ab36dded
commit 4e91ed6c22
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 45 additions and 5 deletions

View file

@ -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 :

37
bin/kube-dump-namespace Executable file
View file

@ -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 "..."