Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 3 | // Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 17 | |
Joey Armstrong | e391ce1 | 2023-09-21 15:55:11 -0400 | [diff] [blame] | 18 | /* ----------------------------------------------------------------------- |
| 19 | groovylint-disable NoDef, VariableTypeRequired |
| 20 | Reason: jenkins.sh() and groovy String do not play nicely together. |
| 21 | cast(String) => java.lang.String not supported natively. |
| 22 | * ----------------------------------------------------------------------- |
| 23 | */ |
| 24 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 25 | def call(List namespaces = ['default'], List excludes = ['docker-registry']) { |
Joey Armstrong | e391ce1 | 2023-09-21 15:55:11 -0400 | [diff] [blame] | 26 | String spaces = namespaces.join(', ') |
Joey Armstrong | 8ee5e4c | 2023-09-21 16:06:03 -0400 | [diff] [blame] | 27 | println("Tearing down charts in namespaces: ${spaces}.") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 28 | |
Joey Armstrong | e391ce1 | 2023-09-21 15:55:11 -0400 | [diff] [blame] | 29 | def exc = excludes.join('|') |
| 30 | for (int i = 0; i < namespaces.size(); i++) { |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 31 | def n = namespaces[i] |
Joey Armstrong | 8ee5e4c | 2023-09-21 16:06:03 -0400 | [diff] [blame] | 32 | sh(label : "Tearing down chart in namespace ${n}", |
Joey Armstrong | e391ce1 | 2023-09-21 15:55:11 -0400 | [diff] [blame] | 33 | script : """ |
Joey Armstrong | 8ee5e4c | 2023-09-21 16:06:03 -0400 | [diff] [blame] | 34 | set +x |
Matteo Scandolo | bdb2c9d | 2021-03-18 11:00:29 -0700 | [diff] [blame] | 35 | for hchart in \$(helm list --all -n ${n} -q | grep -E -v '${exc}'); |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 36 | do |
| 37 | echo "Purging chart: \${hchart}" |
| 38 | helm delete -n ${n} "\${hchart}" |
| 39 | done |
Joey Armstrong | 8ee5e4c | 2023-09-21 16:06:03 -0400 | [diff] [blame] | 40 | """) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Joey Armstrong | 8ee5e4c | 2023-09-21 16:06:03 -0400 | [diff] [blame] | 43 | banner = "Waiting for pods to be removed from namespaces: ${spaces}" |
Joey Armstrong | e391ce1 | 2023-09-21 15:55:11 -0400 | [diff] [blame] | 44 | for (int i = 0; i < namespaces.size(); i++) { |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 45 | def n = namespaces[i] |
Joey Armstrong | 8ee5e4c | 2023-09-21 16:06:03 -0400 | [diff] [blame] | 46 | sh(label : "Waiting for pod removal in namespace ${n}", |
| 47 | script : """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 48 | set +x |
| 49 | PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l) |
| 50 | while [[ \$PODS != 0 ]]; do |
Matteo Scandolo | 95f3bc1 | 2021-06-03 15:25:47 -0700 | [diff] [blame] | 51 | sleep 5 |
| 52 | PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 53 | done |
Joey Armstrong | 8ee5e4c | 2023-09-21 16:06:03 -0400 | [diff] [blame] | 54 | """) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 55 | } |
| 56 | } |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 57 | |
| 58 | // EOF |