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.
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 }}"]
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.
Here is the initial shell script which runs as part of this container.
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
All is well and fine if the ETCD url is accessible, but if the etcd url is inaccessible then I get an error stating Error: Job failed: BackoffLimitExceeded”
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 Pod
instead of a Job
and that doesnt work either.
Looked up at the docs for Helm but couldnt seem to find any information regarding this.
I don't think is possible. But I'd take a different approach.
If your application requires ETCD, why don't you check if ETCD is accesible as one of your Pod probes, 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 kubernetes way.
Furthermore, you can even make helm install
to wait until all the Pod's are Ready
, meaning that the command helm install
would fail if your application didn't connect to ETCD.