[VOL-3780] Upgrading per-patchset validation to use the new charts

Change-Id: I1858f22032dd7b00215f3af0b2ffb038d1615cc2
diff --git a/vars/helmTeardown.groovy b/vars/helmTeardown.groovy
new file mode 100644
index 0000000..3dff0ab
--- /dev/null
+++ b/vars/helmTeardown.groovy
@@ -0,0 +1,30 @@
+
+def call(List namespaces = ['default'], List excludes = ['docker-registry']) {
+
+    println "Tearing down charts in namespaces: ${namespaces.join(', ')}."
+
+    def exc = excludes.join("|")
+    for(int i = 0;i<namespaces.size();i++) {
+        def n = namespaces[i]
+        sh """
+          for hchart in \$(helm list -n ${n} -q | grep -E -v '${exc}');
+          do
+              echo "Purging chart: \${hchart}"
+              helm delete -n ${n} "\${hchart}"
+          done
+        """
+    }
+
+    println "Waiting for pods to be removed from namespaces: ${namespaces.join(', ')}."
+    for(int i = 0;i<namespaces.size();i++) {
+        def n = namespaces[i]
+        sh """
+        set +x
+        PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
+        while [[ \$PODS != 0 ]]; do
+        sleep 5
+        PODS=\$(kubectl get pods -n ${n} --no-headers | wc -l)
+        done
+        """
+    }
+}