Skip to content

Instantly share code, notes, and snippets.

@fl64
Last active May 28, 2024 15:09
Show Gist options
  • Save fl64/6ef8b42dc07f16264cc902b79791147d to your computer and use it in GitHub Desktop.
Save fl64/6ef8b42dc07f16264cc902b79791147d to your computer and use it in GitHub Desktop.
find all kubevirt and cdi resources
#!/usr/bin/env bash
query_meta='
.items[]
| select(
(.metadata // {} | tojson | test("(kubevirt|cdi)") )
)
|
{
kind: .kind,
apiVersion: .apiVersion,
name: .metadata.name,
ns: .metadata.namespace,
}
'
skip_api_regex="(events|endpoints|podmetrics)"
collect() {
for api in ${1}; do
if [[ "${api}" =~ ${skip_api_regex} ]]; then
continue;
fi
result=$(kubectl get ${api} -A -o=json 2>/dev/null | jq "${query_meta}")
if [[ $result != "" ]]; then
echo ${result} | jq -c
fi
done
}
res=$(kubectl api-resources -o name)
collect "${res}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment