21 lines
670 B
YAML
21 lines
670 B
YAML
# services/maintenance/pod-cleaner-script.yaml
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: pod-cleaner-script
|
|
namespace: maintenance
|
|
data:
|
|
pod_cleaner.sh: |
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
for phase in Succeeded Failed; do
|
|
kubectl get pods -A --field-selector="status.phase=${phase}" \
|
|
-o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}' \
|
|
| while read -r namespace name; do
|
|
if [ -n "${namespace}" ] && [ -n "${name}" ]; then
|
|
kubectl delete pod -n "${namespace}" "${name}" --ignore-not-found --grace-period=0 --wait=false
|
|
fi
|
|
done
|
|
done
|