Skip to content

Commit

Permalink
Updates clean.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
lordofthejars committed Feb 14, 2020
1 parent ed204cb commit 350b2fe
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -1,137 +1,137 @@
#!/bin/bash

namespace=$1
namesp=$1

if [ -z "$namespace" ]; then
if [ -z "$namesp" ]; then
namespace="tutorial"
fi

contentvs=`kubectl get virtualservice -n "$namespace" 2>/dev/null`
contentvs=`kubectl get virtualservice -n "$namesp" 2>/dev/null`

if [ -z "$contentvs" ]; then
echo "No Virtual Services in $namespace namespace."
echo "No Virtual Services in $namesp namespace."
else
contentvs=`awk 'NR>1' <<< "$contentvs"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentvs"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentvs"`

for name in ${names[@]}
do
if [ "$name" != "customer-gateway" ]; then
kubectl delete virtualservice "$name" -n "$namespace"
kubectl delete virtualservice "$name" -n "$namesp"
fi
done

fi

contentdr=`kubectl get destinationrule -n "$namespace" 2>/dev/null`
contentdr=`kubectl get destinationrule -n "$namesp" 2>/dev/null`

if [ -z "$contentdr" ]; then
echo "No Destination Rule in $namespace namespace."
echo "No Destination Rule in $namesp namespace."
else
contentdr=`awk 'NR>1' <<< "$contentdr"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentdr"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentdr"`

for name in ${names[@]}
do
kubectl delete destinationrule "$name" -n "$namespace"
kubectl delete destinationrule "$name" -n "$namesp"
done

fi

contentse=`kubectl get serviceentry -n "$namespace" 2>/dev/null`
contentse=`kubectl get serviceentry -n "$namesp" 2>/dev/null`

if [ -z "$contentse" ]; then
echo "No Service Entry in $namespace namespace."
echo "No Service Entry in $namesp namespace."
else
contentse=`awk 'NR>1' <<< "$contentse"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentse"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentse"`

for name in ${names[@]}
do
kubectl delete serviceentry "$name" -n "$namespace"
kubectl delete serviceentry "$name" -n "$namesp"
done

fi

contentp=`kubectl get policy -n "$namespace" 2>/dev/null`
contentp=`kubectl get policy -n "$namesp" 2>/dev/null`

if [ -z "$contentp" ]; then
echo "No Policy in $namespace namespace."
echo "No Policy in $namesp namespace."
else
contentp=`awk 'NR>1' <<< "$contentp"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentp"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentp"`

for name in ${names[@]}
do
kubectl delete policy "$name" -n "$namespace"
kubectl delete policy "$name" -n "$namesp"
done

fi

contentsr=`kubectl get servicerole -n "$namespace" 2>/dev/null`
contentsr=`kubectl get servicerole -n "$namesp" 2>/dev/null`

if [ -z "$contentsr" ]; then
echo "No ServiceRole in $namespace namespace."
echo "No ServiceRole in $namesp namespace."
else
contentsr=`awk 'NR>1' <<< "$contentsr"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentsr"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentsr"`

for name in ${names[@]}
do
kubectl delete servicerole "$name" -n "$namespace"
kubectl delete servicerole "$name" -n "$namesp"
done

fi

contentsrb=`kubectl get servicerolebinding -n "$namespace" 2>/dev/null`
contentsrb=`kubectl get servicerolebinding -n "$namesp" 2>/dev/null`

if [ -z "$contentsrb" ]; then
echo "No ServiceRoleBinding in $namespace namespace."
echo "No ServiceRoleBinding in $namesp namespace."
else
contentsrb=`awk 'NR>1' <<< "$contentsrb"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentsrb"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentsrb"`

for name in ${names[@]}
do
kubectl delete servicerolebinding "$name" -n "$namespace"
kubectl delete servicerolebinding "$name" -n "$namesp"
done

fi

contentrbc=`kubectl get rbacconfig -n "$namespace" 2>/dev/null`
contentrbc=`kubectl get rbacconfig -n "$namesp" 2>/dev/null`

if [ -z "$contentrbc" ]; then
echo "No RbacConfig in $namespace namespace."
echo "No RbacConfig in $namesp namespace."
else
contentrbc=`awk 'NR>1' <<< "$contentrbc"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentrbc"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentrbc"`

for name in ${names[@]}
do
kubectl delete rbacconfig "$name" -n "$namespace"
kubectl delete rbacconfig "$name" -n "$namesp"
done

fi

contentcrbc=`kubectl get ClusterRbacConfig -n "$namespace" 2>/dev/null`
contentcrbc=`kubectl get ClusterRbacConfig -n "$namesp" 2>/dev/null`

if [ -z "$contentcrbc" ]; then
echo "No ClusterRbacConfig in $namespace namespace."
echo "No ClusterRbacConfig in $namesp namespace."
else
contentcrbc=`awk 'NR>1' <<< "$contentcrbc"`

names=`awk -v namespace="$namespace" '{ {print $1} }' <<< "$contentcrbc"`
names=`awk -v namespace="$namesp" '{ {print $1} }' <<< "$contentcrbc"`

for name in ${names[@]}
do
kubectl delete ClusterRbacConfig "$name" -n "$namespace"
kubectl delete ClusterRbacConfig "$name" -n "$namesp"
done

fi

0 comments on commit 350b2fe

Please sign in to comment.