Add preStop hook to istio proxy sidecars

Graceful shutdown of pods was not working with istio, because the
istio sidecars were prematurely shut down, thereby killing running
requests.

This change adds a preStop hook that holds the shutdown of the sidecar
until the application container is shutdown.

Change-Id: I8a5e1478fc94f063dbee340d7c59dccd4f3495a8
diff --git a/istio/src/istio-sidecar-injector-cm.yaml b/istio/src/istio-sidecar-injector-cm.yaml
index 0607ddb..47e6a64 100755
--- a/istio/src/istio-sidecar-injector-cm.yaml
+++ b/istio/src/istio-sidecar-injector-cm.yaml
@@ -319,6 +319,13 @@
         lifecycle:
           {{ toYaml .Values.global.proxy.lifecycle | indent 4 }}
         {{- end }}
+        lifecycle:
+          preStop:
+            exec:
+              command:
+              - "/bin/sh"
+              - "-c"
+              - "while [ $(netstat -plunt | grep tcp | grep -v envoy | wc -l | xargs) -ne 0 ]; do sleep 1; done"
         env:
         - name: JWT_POLICY
           value: {{ .Values.global.jwtPolicy }}