apiVersion: v1
kind: Pod
metadata:
  annotations:
    helm.sh/hook: test-success
  labels:
    app: consul
    chart: consul-helm
    heritage: Helm
    release: RELEASE-NAME
  name: RELEASE-NAME-consul-test
  namespace: default
spec:
  containers:
  - command:
    - /bin/sh
    - -ec
    - |
      consul members | tee members.txt
      if [ $(grep -c consul-server members.txt) != $(grep consul-server members.txt | grep -c alive) ]
      then
        echo "Failed because not all consul servers are available"
        exit 1
      fi
    env:
    - name: HOST_IP
      valueFrom:
        fieldRef:
          fieldPath: status.hostIP
    - name: CONSUL_HTTP_ADDR
      value: http://$(HOST_IP):8500
    image: hashicorp/consul:1.11.2
    name: consul-test
  restartPolicy: Never
