Fix helm behavior 62/98462/1
authorPetr Ospalý <p.ospaly@partner.samsung.com>
Fri, 15 Nov 2019 17:00:18 +0000 (18:00 +0100)
committerPetr Ospalý <p.ospaly@partner.samsung.com>
Fri, 15 Nov 2019 17:55:12 +0000 (18:55 +0100)
When 'helm serve' is not running and helm is not listening on
localhost:8879 then helm starts to delete everything...instead of
aborting or doing something sensible...

This commit fix this misbehavior: we abort

Issue-ID: OOM-2074

Change-Id: Icb4d25163012e4aedf5ec1598a4f20c738c04974
Signed-off-by: Petr Ospalý <p.ospaly@partner.samsung.com>
tools/helm-healer.sh

index 0bfe013..a6e5b39 100755 (executable)
@@ -134,6 +134,11 @@ error()
     printf "${COLOR_ON_RED}ERROR: $@ ${COLOR_OFF}\n"
 }
 
+on_exit()
+{
+    printf "$COLOR_OFF"
+}
+
 # remove all successfully completed jobs
 clean_jobs()
 {
@@ -316,6 +321,20 @@ EOF
     wait
 }
 
+is_helm_serve_running()
+{
+    # healthy result: HTTP/1.1 200 OK
+    _helm_serve_result=$(\
+        curl --head --silent --connect-timeout 3 http://127.0.0.1:8879 | \
+        head -n 1 | cut -d" " -f 3 | tr '[:upper:]' '[:lower:]' | tr -d '\r' )
+
+    if [ "$_helm_serve_result" == ok ] ; then
+        return 0
+    else
+        return 1
+    fi
+}
+
 # arg: <release name>
 undeploy_component()
 {
@@ -552,6 +571,22 @@ fi
 # main
 #
 
+# set trap for this script cleanup
+trap on_exit INT QUIT TERM EXIT
+
+# another sanity checks
+for tool in helm kubectl curl ; do
+    if ! which "$tool" >/dev/null 2>&1 ; then
+        error "Missing '${tool}' command"
+        exit 1
+    fi
+done
+
+if ! is_helm_serve_running ; then
+    error "'helm serve' is not running (http://localhost:8879)"
+    exit 1
+fi
+
 # if --delete-all is used then redeploy all components (the current namespace is deleted)
 if [ -n "$HELM_DELETE_ALL" ] ; then
     # undeploy helm release (prefix)