Created
December 25, 2018 10:55
-
-
Save amaya382/6001544de2c46a12edca5adfb5e0cecf to your computer and use it in GitHub Desktop.
dust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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