summaryrefslogtreecommitdiff
path: root/.local/bin/kubectl-get-all
blob: f4707d54e961003e679bc5a0492e5ce125477053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash
tmpdir="$(mktemp -d)"
trap 'rm -rf -- "$tmpdir"' EXIT

if [[ $# -eq 0 ]]; then
	kubectl api-resources --namespaced=true -o name | xargs printf '%s true\n'
	kubectl api-resources --namespaced=false -o name | xargs printf '%s false\n'
else
	printf '%s %s\n' "$@"
fi | while read -r type namespaced; do
	if [[ $type != *.* ]]; then
		type="${type}."
	fi
	export type
	if [[ $namespaced == true ]]; then
		kubectl get "$type" --all-namespaces --output=json 2>/dev/null |
			jq -r '.items[]|($ENV.type + "/" + .metadata.name + " --namespace=" + .metadata.namespace)'
	else
		kubectl get "$type" --output=json 2>/dev/null |
			jq -r '.items[]|($ENV.type + "/" + .metadata.name)'
	fi >"$tmpdir/$type" &
done
grep -r ^ "$tmpdir"