Skip to content

Commit afb615b

Browse files
bin: fix clean scripts after new velero finalizers
1 parent b5b56c6 commit afb615b

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

scripts/clean-sc.sh

+21-13
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,30 @@ fi
3939
# Clean up namespaces and any other resources left behind by the apps
4040
"${here}/.././bin/ck8s" ops kubectl sc delete ns dex opensearch-system harbor fluentd-system gatekeeper-system thanos ingress-nginx monitoring kured falco velero
4141

42+
# Remove finalizers from Velero resources, see breaking changes: https://github.com/vmware-tanzu/velero/releases/tag/v1.12.0
43+
mapfile -t VELERO_CRDS < <("${here}/.././bin/ck8s" ops kubectl sc get crd -l component=velero -oyaml | \
44+
yq4 '.items[] | .metadata.name' | tr -d '"')
45+
46+
for velero_crd in "${VELERO_CRDS[@]}"; do
47+
mapfile -t VELERO_RESOURCES < <("${here}/.././bin/ck8s" ops kubectl sc get "${velero_crd}" -oyaml -n velero| \
48+
yq4 '.items[] | select(.metadata | has("finalizers")).metadata.name')
49+
for velero_resource in "${VELERO_RESOURCES[@]}"; do
50+
"${here}/.././bin/ck8s" ops kubectl sc patch "${velero_crd}" "${velero_resource}" -n velero \
51+
-p '{"metadata":{"finalizers":null}}' --type=merge
52+
done
53+
done
54+
4255
# Clean up any leftover challenges
4356
CHALLENGES=$(
44-
"${here}/.././bin/ck8s" ops \
45-
kubectl sc get challenge -A \
46-
"-o=jsonpath='{range .items[*]}{.metadata.name}{\",\"}{.metadata.namespace}{\"\n\"}{end}'"
57+
"${here}/.././bin/ck8s" ops kubectl sc get challenge -A \
58+
"-o=jsonpath='{range .items[*]}{.metadata.name}{\",\"}{.metadata.namespace}{\"\n\"}{end}'"
4759
)
48-
if [ -n "$CHALLENGES" ]; then
49-
for challenge in "${CHALLENGES[@]}"; do
50-
IFS=, read -r name namespace <<< "$challenge"
51-
"${here}/.././bin/ck8s" ops \
52-
kubectl sc patch challenge \
53-
"$name" -n "$namespace" \
54-
"-p '{\"metadata\":{\"finalizers\":null}}'" \
55-
--type=merge
56-
done
57-
fi
60+
for challenge in "${CHALLENGES[@]}"; do
61+
IFS=, read -r name namespace <<< "${challenge}"
62+
"${here}/.././bin/ck8s" ops \
63+
kubectl sc patch challenge "${name}" -n "${namespace}" \
64+
-p '{"metadata":{"finalizers":null}}' --type=merge
65+
done
5866

5967
if [ "${clusterAPIEnabled}" = "false" ]; then
6068
# Destroy cert-manager helm release

scripts/clean-wc.sh

+25
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ fi
5151
# Clean up namespaces and any other resources left behind by the apps
5252
"${here}/.././bin/ck8s" ops kubectl wc delete ns alertmanager falco fluentd-system fluentd gatekeeper-system hnc-system ingress-nginx monitoring velero kured
5353

54+
# Remove finalizers from Velero resources, see breaking changes: https://github.com/vmware-tanzu/velero/releases/tag/v1.12.0
55+
mapfile -t VELERO_CRDS < <("${here}/.././bin/ck8s" ops kubectl wc get crd -l component=velero -oyaml | \
56+
yq4 '.items[] | .metadata.name' | tr -d '"')
57+
58+
for velero_crd in "${VELERO_CRDS[@]}"; do
59+
mapfile -t VELERO_RESOURCES < <("${here}/.././bin/ck8s" ops kubectl wc get "${velero_crd}" -oyaml -n velero| \
60+
yq4 '.items[] | select(.metadata | has("finalizers")).metadata.name')
61+
for velero_resource in "${VELERO_RESOURCES[@]}"; do
62+
"${here}/.././bin/ck8s" ops kubectl wc patch "${velero_crd}" "${velero_resource}" -n velero \
63+
-p '{"metadata":{"finalizers":null}}' --type=merge
64+
done
65+
done
66+
67+
# Clean up any leftover challenges
68+
CHALLENGES=$(
69+
"${here}/.././bin/ck8s" ops kubectl wc get challenge -A \
70+
"-o=jsonpath='{range .items[*]}{.metadata.name}{\",\"}{.metadata.namespace}{\"\n\"}{end}'"
71+
)
72+
for challenge in "${CHALLENGES[@]}"; do
73+
IFS=, read -r name namespace <<< "${challenge}"
74+
"${here}/.././bin/ck8s" ops \
75+
kubectl wc patch challenge "${name}" -n "${namespace}" \
76+
-p '{"metadata":{"finalizers":null}}' --type=merge
77+
done
78+
5479
if [ "${clusterAPIEnabled}" = "false" ]; then
5580
# Destroy cert-manager helm release
5681
"${here}/.././bin/ck8s" ops helmfile wc -l app=cert-manager destroy

0 commit comments

Comments
 (0)