summaryrefslogtreecommitdiffstats
path: root/kubernetes/helm/plugins/undeploy/undeploy.sh
blob: dca4499aa1743bec1dde21cf8cc99d102f2f6997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh

usage() {
cat << EOF
Delete an umbrella Helm Chart, and its subcharts, that was previously deployed using 'Helm deploy'.

Example of deleting all Releases that have the prefix 'demo'.
  $ helm undeploy demo

  $ helm undeploy demo --purge

Usage:
  helm undeploy [RELEASE] [flags]

Flags:
      --purge     remove the releases from the store and make its name free for later use
EOF
}

undeploy() {
  RELEASE=$1
  FLAGS=$2

  reverse_list=
  for item in $(helm ls -q --all | grep $RELEASE)
  do
    reverse_list="$item $reverse_list"
  done
  for item in $reverse_list
  do
    helm del $item $FLAGS
  done
}

if [ -z "$1" ]; then
  echo "Error: command 'undeploy' requires a release name"
  exit 1
fi

case "${1:-"help"}" in
  "help")
    usage
    ;;
  "--help")
    usage
    ;;
  "-h")
    usage
    ;;
  *)
    undeploy $1 $(echo ${@} | sed 's/^ *[^ ]* *//')
    ;;
esac

exit 0