<p>I am trying to develop a Helm chart for an application to ease release management and deployment of the application to kubernetes. In order to do so, i have written a pre-install hook in the Helm chart. </p>

<pre><code>    apiVersion: batch/v1
kind: Job
metadata:
  name: px-etcd-preinstall-hook
  labels:
    heritage: {{.Release.Service | quote }}
    release: {{.Release.Name | quote }}
    chart: "{{.Chart.Name}}-{{.Chart.Version}}"
  annotations:
    "helm.sh/hook": pre-install
    "helm.sh/hook-weight": "-5"
    "helm.sh/hook-delete-policy": hook-succeeded, hook-failed
spec:
  backoffLimit: 2
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: pre-install-job
        imagePullPolicy: Always
        image: "hrishi/px-etcd-preinstall-hook:v1"
        command: ['/bin/sh']
        args: ['/usr/bin/etcdStatus.sh',"{{ .Values.etcdEndPoint }}"]
</code></pre>

<p>This docker container just checks if an ETCD endpoint is accessible or not. Idea is for it to wait for a few seconds and a few tries and then exit.<br>
Here is the initial shell script which runs as part of this container. </p>

<pre><code>set -x
echo "Initializing..."
svcname=$1
echo $svcname
etcdURL=$(echo "$svcname" | awk -F: '{ st = index($0,":");print substr($0,st+1)}')
echo $etcdURL

response=$(curl --write-out %{http_code} --silent --output /dev/null "$etcdURL/version")
echo $response

if [[ "$response" != 200 ]]
then
    echo "Provided etcd url is not reachable. Exiting.."
    exit 1
fi 
</code></pre>

<p>All is well and fine if the ETCD url is accessible, but if the etcd url is inaccessible then I get an error stating <code>Error: Job failed: BackoffLimitExceeded”</code></p>

<p>I want to check if there is a way of setting a user friendly error message stating that the url isnt accessible or something like that. 
Seems there isnt a way to do it right now, not that i know of. I tried this to just be a <code>Pod</code> instead of a <code>Job</code> and that doesnt work either. </p>

<p>Looked up at the docs for Helm but couldnt seem to find any information regarding this. </p>

<p>I don't think is possible. But I'd take a different approach.</p>

<p>If your application requires ETCD, why don't you check if ETCD is accesible as one of your <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/" rel="nofollow noreferrer">Pod probes</a>, like liveness or readiness? That way, if there is no connectivity between your application and ETCD, your application won't start and you'll know that the probe failed when describing your Pod, in a more <em>kubernetes way</em>.</p>

<p>Furthermore, you can even make <code>helm install</code> <a href="https://github.com/kubernetes/helm/blob/master/docs/using_helm.md#helpful-options-for-installupgraderollback" rel="nofollow noreferrer">to wait until all the Pod's are <code>Ready</code></a>, meaning that the command <code>helm install</code> would fail if your application didn't connect to ETCD.</p>
