Skip to content

Commit c6b3f34

Browse files
author
Tim Bannister
committed
Automatically clean up after deploying PSA examples
Readers who want to skip the clean up can edit these scripts; it seems fair to assume that a reader who wants that would know how to edit a shell script and delete lines from it.
1 parent 25a926e commit c6b3f34

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

content/en/examples/security/kind-with-cluster-level-baseline-pod-security.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ nodes:
5353
EOF
5454
kind create cluster --name psa-with-cluster-pss --config /tmp/pss/cluster-config.yaml
5555
kubectl cluster-info --context kind-psa-with-cluster-pss
56+
5657
# Wait for 15 seconds (arbitrary) ServiceAccount Admission Controller to be available
5758
sleep 15
5859
cat <<EOF |
@@ -68,3 +69,14 @@ spec:
6869
- containerPort: 80
6970
EOF
7071
kubectl apply -f -
72+
73+
# Wait
74+
sleep 3
75+
76+
# Clean up
77+
printf "\n\nCleaning up:\n" 1>&2
78+
set -e
79+
kubectl delete pod --all -n example --now
80+
kubectl delete ns example
81+
kind delete cluster --name psa-with-cluster-pss
82+
rm -f /tmp/pss/cluster-config.yaml

content/en/examples/security/kind-with-namespace-level-baseline-pod-security.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/sh
22
kind create cluster --name psa-ns-level
33
kubectl cluster-info --context kind-psa-ns-level
4-
# Wait for 15 seconds (arbitrary) ServiceAccount Admission Controller to be available
4+
# Wait for 15 seconds (arbitrary) for ServiceAccount Admission Controller to be available
55
sleep 15
6-
kubectl create ns example
6+
7+
# Create and label the namespace
8+
kubectl create ns example || exit 1 # if namespace exists, don't do the next steps
79
kubectl label --overwrite ns example \
810
pod-security.kubernetes.io/enforce=baseline \
911
pod-security.kubernetes.io/enforce-version=latest \
@@ -26,3 +28,13 @@ spec:
2628
- containerPort: 80
2729
EOF
2830
kubectl apply -n example -f -
31+
32+
# Wait
33+
sleep 3
34+
35+
# Clean up
36+
printf "\n\nCleaning up:\n" 1>&2
37+
set -e
38+
kubectl delete pod --all -n example --now
39+
kubectl delete ns example
40+
kind delete cluster --name psa-ns-level

0 commit comments

Comments
 (0)