Skip to content

Instantly share code, notes, and snippets.

@ialidzhikov
Last active April 21, 2023 13:17
Show Gist options
  • Select an option

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

Select an option

Save ialidzhikov/e770307bbe2d58c108e5294f0a78924f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
while read NS; do
echo "> Checking $NS"
kinds=('configmaps' 'secrets' 'serviceaccounts' 'resourcequotas' 'backupentries.core.gardener.cloud' 'quotas.core.gardener.cloud' 'secretbindings.core.gardener.cloud' 'shoots.core.gardener.cloud' 'shootstates.core.gardener.cloud' 'terminals.dashboard.gardener.cloud' 'clusterboms.hub.k8s.sap.com' 'bastions.operations.gardener.cloud' 'rolebindings.rbac.authorization.k8s.io' 'roles.rbac.authorization.k8s.io')
for val in $kinds; do
kubectl -n $NS get $val --show-kind --ignore-not-found
done
echo "Namespace:"
kubectl get namespace $NS -o yaml
echo "Checking for project:"
kubectl get project --field-selector=spec.namespace=$NS
if read -q "choice?Press Y/y to delete: "; then
echo
echo "Will delete..."
kubectl delete ns $NS
else
echo
echo "'$choice' not 'Y' or 'y'. Exiting..."
exit 1
fi
done < canary-result.txt
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
NAMESPACES=$(kubectl get namespaces --no-headers -o custom-columns=":metadata.name" | grep "^garden-")
for NS in $NAMESPACES
do
sleep 0.5
echo "> Checking $NS"
PROJECTS=$(kubectl get project --field-selector=spec.namespace=$NS -o json)
PROJECTS_LEN=$(jq '.items | length' <<< $PROJECTS)
if [ "$PROJECTS_LEN" = 0 ]
then
echo "No Project found!"
echo $NS >> result.txt
else
PROJECT_NAME=$(jq -r '.items[0].metadata.name' <<< $PROJECTS)
echo "Found Project $PROJECT_NAME!"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment