Skip to content

Instantly share code, notes, and snippets.

@amaya382
Created December 25, 2018 10:55
Show Gist options
  • Save amaya382/6001544de2c46a12edca5adfb5e0cecf to your computer and use it in GitHub Desktop.
Save amaya382/6001544de2c46a12edca5adfb5e0cecf to your computer and use it in GitHub Desktop.
dust
# Not work, because of https://github.com/kubernetes/kubernetes/issues/20352
for label in ${labels//,/ }; do
if [ "${query}" != '' ]; then
query="${query} &&"
fi
query=${query}@.spec.selector.${label//=/\=\=\"}\"
done
$KUBECTL get rs --no-headers=true -o=jsonpath="{.items[?(${query})].metadata.name}" | xargs
# Use jq
if [ "${parent_type}" == "deployments" -o "${parent_type}" == "replicasets" ]; then
tmp='.matchLabels'
else
tmp=''
fi
for label in ${labels//,/ }; do
if [ "${query}" != '' ]; then
query="${query} and"
fi
query="${query}.spec.selector${tmp}.\"${label//=/\"\=\=\"}\""
done
query=".items[] | select(${query}) | .metadata.name"
echo "($parent_type) by ($query)"
$KUBECTL get ${parent_type} --no-headers=true -o=json | jq "${query}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment