Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Unverified Commit e20db821 authored by Idriss's avatar Idriss
Browse files

Add a prefix filter

parent c2e49c62
No related branches found
No related tags found
No related merge requests found
# clean-k8s-objects
Remove finilizers and delete all the object related to a CRD in a given namespace
```shell
./clean.sh -n <NAMESPACE> -c <CRD>
```
If you want to only delete the resource that begin with a prefix filter:
```shell
./clean.sh -n <NAMESPACE> -c <CRD> -f <FILTER>
```
#!/usr/bin/env bash
K8S_CLI="kubectl"
FILTER=""
error() {
echo "Error: invalid parameters!" >&2
......@@ -12,12 +13,17 @@ usage() {
echo "Usage: ./clean.sh -n <NAMESPACE> -c <CRD>"
echo "-n <NAMESPACE>: Kubernetes namespace"
echo "-c <CRD>: Kubernetes custom resource definition"
echo "-f <FILTER>: Prefix filter (perform only on name begining with filter)"
echo "-h: Get the help"
}
main() {
if [[ ! $NS ]] || [[ ! $CRD ]]; then
error
fi
"${K8S_CLI}" -n "${NS}" get "${CRD}" | while read name trash; do
if [[ $name == "NAME" ]]; then
if [[ $name == "NAME" ]] || [[ ! $name =~ "${FILTER}".* ]]; then
continue
fi
......@@ -29,10 +35,11 @@ main() {
[[ $# -lt 1 ]] && error
while getopts ":n:c:h" option; do
while getopts ":n:c:f:h" option; do
case "$option" in
n) NS="${OPTARG}" ;;
c) CRD="${OPTARG}" ;;
f) FILTER="${OPTARG}" ;;
:) error ;;
h) usage ;;
*) error ;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment