Skip to content

Instantly share code, notes, and snippets.

@ialidzhikov
Created May 22, 2024 11:02
Show Gist options
  • Select an option

  • Save ialidzhikov/c0126097eae4e4354e5b69948e02f7f2 to your computer and use it in GitHub Desktop.

Select an option

Save ialidzhikov/c0126097eae4e4354e5b69948e02f7f2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
TMP_DIR=$(mktemp -d -t run-XXXXXXXXXX)
echo "TMP_DIR=$TMP_DIR"
SEEDS=$(kubectl -n garden get shoots -o json | jq -r '.items[] | select(.status.hibernated == false) | .metadata.namespace + "," + .metadata.name')
for SEED in $SEEDS
do
sleep 1s
echo "> Checking $SEED"
TOKENS=(${SEED//,/ })
NAMESPACE=${TOKENS[0]}
NAME=${TOKENS[1]}
kubectl create \
-f <(printf '{"spec":{"expirationSeconds":86400}}') \
--raw /apis/core.gardener.cloud/v1beta1/namespaces/${NAMESPACE}/shoots/${NAME}/viewerkubeconfig | \
jq -r ".status.kubeconfig" | \
base64 -d > $TMP_DIR/$NAME.yaml
echo "Checking..."
LOST_PVS=$(kubectl --kubeconfig=$TMP_DIR/$NAME.yaml get pv -o json | jq -r '.items[] | select(.status.phase=="Lost") | .metadata.name')
if [ -n "$LOST_PVS" ]
then
echo "Found 'Lost' PVs - $LOST_PVS!"
exit 1
fi
done
echo "Finished successfully!"
rm -rf $TMP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment