#!/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"