Skip to content

Commit

Permalink
- added a destroy-script for the resources installed"
Browse files Browse the repository at this point in the history
- added labels to the resources
  • Loading branch information
aayushrangwala authored and Ayush Rangwala committed Apr 15, 2021
1 parent 9734686 commit 8ed7de5
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
.idea
/bin

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
1 change: 1 addition & 0 deletions deploy/kubernetes-1.17/destroy.sh
2 changes: 2 additions & 0 deletions deploy/kubernetes-1.18/hostpath/csi-hostpath-attacher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-hostpath-attacher
labels:
app: csi-attacher
spec:
serviceName: "csi-hostpath-attacher"
replicas: 1
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes-1.18/hostpath/csi-hostpath-driverinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: storage.k8s.io/v1
kind: CSIDriver
metadata:
name: hostpath.csi.k8s.io
labels:
app: csi-hostpath-driver
spec:
# Supports persistent and ephemeral inline volumes.
volumeLifecycleModes:
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes-1.18/hostpath/csi-hostpath-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-hostpathplugin
labels:
app: csi-hostpathplugin
spec:
serviceName: "csi-hostpathplugin"
# One replica only:
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes-1.18/hostpath/csi-hostpath-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-hostpath-provisioner
labels:
app: csi-provisioner
spec:
serviceName: "csi-hostpath-provisioner"
replicas: 1
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes-1.18/hostpath/csi-hostpath-resizer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-hostpath-resizer
labels:
app: csi-resizer
spec:
serviceName: "csi-hostpath-resizer"
replicas: 1
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes-1.18/hostpath/csi-hostpath-snapshotter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-hostpath-snapshotter
labels:
app: csi-snapshotter
spec:
serviceName: "csi-hostpath-snapshotter"
replicas: 1
Expand Down
4 changes: 4 additions & 0 deletions deploy/kubernetes-1.18/hostpath/csi-hostpath-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ apiVersion: v1
kind: Service
metadata:
name: hostpath-service
labels:
app: csi-hostpath-socat
spec:
type: NodePort
selector:
Expand All @@ -22,6 +24,8 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-hostpath-socat
labels:
app: csi-hostpath-socat
spec:
serviceName: "csi-hostpath-socat"
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshotClass
metadata:
name: csi-hostpath-snapclass
labels:
app: csi-snapshotter
driver: hostpath.csi.k8s.io #csi-hostpath
deletionPolicy: Delete
56 changes: 56 additions & 0 deletions deploy/util/destroy-hostpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

# This script performs the step to destroy the hostpath plugin driver
# completely by checking all the resources.
# This should be in sync with the deploy script based on any future additions/deletions
# of the resources

# The script assumes that kubectl is available on the OS path
# where it is executed.

set -e
set -o pipefail

BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

LABELS=(csi-snapshotter csi-hostpathplugin csi-attacher csi-resizer csi-hostpath-driver csi-provisioner csi-hostpath-socat)

run () {
echo "$@" >&2
"$@"

for label in "${LABELS[@]}"; do
kubectl delete all,role,clusterrole,rolebinding,clusterrolebinding,sa -l app=${label} || true
done

# delete hostpath plugin as a fall back
echo "deleting hostpath components"
for i in $(ls ${BASE_DIR}/hostpath/*.yaml | sort); do
echo "deleting $i"
kubectl delete -f "$i" || true
done

}

run

# Wait until all pods are not deleted. We have to make some assumptions
# about the deployment here, otherwise we wouldn't know what to wait
# for: the expectation is that we run attacher, provisioner,
# snapshotter, resizer, socat and hostpath plugin in the default namespace.
expected_running_pods=0
cnt=0
while [ $(kubectl get pods 2>/dev/null | grep '^csi-hostpath.* Running ' | wc -l) -gt ${expected_running_pods} ]; do
if [ $cnt -gt 30 ]; then
echo "$(kubectl get pods 2>/dev/null | grep '^csi-hostpath.* Running ' | wc -l) running pods:"
kubectl describe pods

echo >&2 "ERROR: hostpath deployment still ready after over 5min"
exit 1
fi
echo $(date +%H:%M:%S) "waiting for hostpath deployment to delete, attempt #$cnt"
cnt=$(($cnt + 1))
sleep 10
done


0 comments on commit 8ed7de5

Please sign in to comment.