Last active
April 19, 2023 09:52
-
-
Save nielswind/8a9e2ae451ff6b690f9baff6a28851ba to your computer and use it in GitHub Desktop.
extract (k8s) kind and optionally name from yaml
This file contains 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
#!/usr/bin/env bash | |
# https://gist.githubusercontent.com/nielswind/8a9e2ae451ff6b690f9baff6a28851ba/raw/extract.sh | |
function depcheck() { | |
local DEPS=($*) | |
for cmd in "${DEPS[@]}" | |
do | |
[[ $(command -v $cmd 2>/dev/null) ]] || { echo -en "\n$cmd needs to be installed.";fail=1; } | |
done | |
[[ $fail -ne 1 ]] || { echo -en "\n${0}: Install the above and rerun this script\n";exit 1; } | |
} | |
depcheck yq | |
[[ "$#" -lt 1 || "$#" -gt 2 ]] && { echo "Usage: ${0##*/} Kind [Name]"; echo "Note: reads from stdin"; exit 1; } | |
export K=$1 | |
export N=$2 | |
IFS= | |
out=$(cat <(yq e '. | select(.kind == env(K))')) | |
[[ "$#" -eq 2 ]] && out=$(echo $out | yq e '. | select(.metadata.name == env(N))') | |
echo $out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment