Last active
November 13, 2020 08:44
-
-
Save hoegaarden/bf0548fd0efda248c31268955a830b65 to your computer and use it in GitHub Desktop.
k-filter -- for when kubectl talks too much
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
#!/usr/bin/env bash | |
set -e | |
set -u | |
set -o pipefail | |
declare -rA FILTERS=( | |
# Remove some mostly unintersting fields | |
['klean']=' | |
del( .. | .metadata? | |
| .managedFields? , .uid? , .selfLink? , .resourceVersion? , .generation? | |
) | |
' | |
# Make secrets readable by base64 decoding them | |
['sekret']=' | |
walk( | |
if (type=="object" and .kind=="Secret" and (.data | type=="object")) | |
then | |
.data |= map_values(@base64d) | |
else | |
. | |
end | |
) | |
' | |
) | |
nope() { | |
printf 'Cannot be called as %q because no such filter exists\n' "$1" | |
echo | |
echo 'Available filters:' | |
printf ' - %q\n' "${!FILTERS[@]}" | |
echo | |
echo 'Example call:' | |
printf ' kubectl get secrets -o yaml | %q\n' "$1" | |
} | |
main() { | |
local mode | |
mode="$( basename "$0" )" | |
[ "${FILTERS[$mode]+something}" ] || { | |
nope "$mode" >&2 | |
return 1 | |
} | |
yq -y "${FILTERS[$mode]}" | |
} | |
main "$@" |
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
k-filter -- some filters for kubectl when it talks too much or grabage | |
0. Needs jq & yq on the system | |
jq: https://stedolan.github.io/jq/ (apt install jq) | |
yq: https://pypi.org/project/yq/ (pip3 install yq) | |
1. create links | |
ln -s k-filter klean | |
ln -s k-filter sekret | |
2. run it in a pipeline | |
kubectl get secrets -o yaml | klean | sekret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment