blob: e6f36ac6dfabe527bc2e1fecd87a466ff571145b [file] [log] [blame]
Joey Armstrongaf679da2023-01-31 14:22:41 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
3// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -080017
18def call(List namespaces = ['default'], List excludes = ['docker-registry']) {
19
20 println "Tearing down charts in namespaces: ${namespaces.join(', ')}."
21
22 def exc = excludes.join("|")
23 for(int i = 0;i<namespaces.size();i++) {
24 def n = namespaces[i]
25 sh """
Matteo Scandolobdb2c9d2021-03-18 11:00:29 -070026 for hchart in \$(helm list --all -n ${n} -q | grep -E -v '${exc}');
Matteo Scandolo42f6e572021-01-25 15:11:34 -080027 do
28 echo "Purging chart: \${hchart}"
29 helm delete -n ${n} "\${hchart}"
30 done
31 """
32 }
33
34 println "Waiting for pods to be removed from namespaces: ${namespaces.join(', ')}."
35 for(int i = 0;i<namespaces.size();i++) {
36 def n = namespaces[i]
37 sh """
38 set +x
39 PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
40 while [[ \$PODS != 0 ]]; do
Matteo Scandolo95f3bc12021-06-03 15:25:47 -070041 sleep 5
42 PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
Matteo Scandolo42f6e572021-01-25 15:11:34 -080043 done
44 """
45 }
46}
Joey Armstrongaf679da2023-01-31 14:22:41 -050047
48// EOF