Created
June 11, 2021 21:25
-
-
Save karlkfi/a1bd1e4a0226f7d695f6310623f07df6 to your computer and use it in GitHub Desktop.
kpt-pkg-status.sh - Get the status of all resources in a directory.
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 | |
set -o errexit -o nounset -o pipefail | |
PKG_PATH="${1:-.}" | |
if ! hash jq 2>/dev/null; then | |
echo >&2 "Error: jq not found. Please install jq: https://stedolan.github.io/jq/download/" | |
fi | |
if ! hash kpt 2>/dev/null; then | |
echo >&2 "Error: kpt not found. Please install kpt: https://googlecontainertools.github.io/kpt/installation/" | |
fi | |
if ! kpt cfg cat --help &>/dev/null; then | |
echo >&2 "Error: kpt version unsupported. Must include 'kpt cfg cat'. Try kpt <= 0.39.x" | |
fi | |
function print_status() { | |
local expr | |
expr+='.items[]' | |
expr+=' | .apiVersion + "\t"' | |
expr+=' + .kind + "\t"' | |
expr+=' + .metadata.name + "\t"' | |
expr+=' + .metadata.namespace + "\t"' | |
expr+=' + (' | |
expr+=' if (.status != null and .status.conditions != null) then' | |
expr+=' .status.conditions[] | select(.type == "Ready") | .status + "\t" + .reason' | |
expr+=' else' | |
expr+=' "N/A\tN/A"' | |
expr+=' end' | |
expr+=')' | |
jq -er "${expr}" | |
} | |
( | |
echo -e "APIVersion\tKind\tName\tNamespace\tReady\tReason" | |
kpt cfg cat "${PKG_PATH}" \ | |
| kubectl get -o json -f - \ | |
| print_status \ | |
| sort | |
) | column -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment