blob: 0d7bb1c18e1676c663f1835f3a28ce43e79005f6 [file] [log] [blame]
Joey Armstrongaf679da2023-01-31 14:22:41 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrong6a9013e2024-02-01 17:56:57 -05003// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrongaf679da2023-01-31 14:22:41 -05004//
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
Joey Armstronge391ce12023-09-21 15:55:11 -040018/* -----------------------------------------------------------------------
19groovylint-disable NoDef, VariableTypeRequired
20Reason: jenkins.sh() and groovy String do not play nicely together.
21 cast(String) => java.lang.String not supported natively.
22* -----------------------------------------------------------------------
23*/
24
Matteo Scandolo42f6e572021-01-25 15:11:34 -080025def call(List namespaces = ['default'], List excludes = ['docker-registry']) {
Joey Armstronge391ce12023-09-21 15:55:11 -040026 String spaces = namespaces.join(', ')
27 String msg = "Tearing down charts in namespaces: ${spaces}."
28 println(msg)
Matteo Scandolo42f6e572021-01-25 15:11:34 -080029
Joey Armstronge391ce12023-09-21 15:55:11 -040030 def exc = excludes.join('|')
31 for (int i = 0; i < namespaces.size(); i++) {
32 // sh() and groovy String vars do not play well together
Matteo Scandolo42f6e572021-01-25 15:11:34 -080033 def n = namespaces[i]
Joey Armstronge391ce12023-09-21 15:55:11 -040034
35 sh(label : "Tearing down charts in namespaces: ${n}.",
36 script : """
Matteo Scandolobdb2c9d2021-03-18 11:00:29 -070037 for hchart in \$(helm list --all -n ${n} -q | grep -E -v '${exc}');
Matteo Scandolo42f6e572021-01-25 15:11:34 -080038 do
39 echo "Purging chart: \${hchart}"
40 helm delete -n ${n} "\${hchart}"
41 done
Joey Armstronge391ce12023-09-21 15:55:11 -040042 """)
Matteo Scandolo42f6e572021-01-25 15:11:34 -080043 }
44
45 println "Waiting for pods to be removed from namespaces: ${namespaces.join(', ')}."
Joey Armstronge391ce12023-09-21 15:55:11 -040046 for (int i = 0; i < namespaces.size(); i++) {
Matteo Scandolo42f6e572021-01-25 15:11:34 -080047 def n = namespaces[i]
48 sh """
49 set +x
50 PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
51 while [[ \$PODS != 0 ]]; do
Matteo Scandolo95f3bc12021-06-03 15:25:47 -070052 sleep 5
53 PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
Matteo Scandolo42f6e572021-01-25 15:11:34 -080054 done
55 """
56 }
57}
Joey Armstrongaf679da2023-01-31 14:22:41 -050058
59// EOF