# _helpers.tpl
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "consul.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "consul.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "consul.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Return the apiVersion of statefulset.
*/}}
{{- define "statefulset.apiVersion" -}}
{{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.GitVersion -}}
{{- print "apps/v1beta2" -}}
{{- else if semverCompare ">=1.9-0" .Capabilities.KubeVersion.GitVersion -}}
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}
 # basic-acls.yaml
{{- if .Values.acl.enabled}}
apiVersion: batch/v1
kind: Job
metadata:
  name: "configure-basic-acls"
  annotations:
    "helm.sh/hook": post-install
    "helm.sh/hook-delete-policy": hook-succeeded
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
spec:
  template:
    metadata:
      name: "configure-basic-acls"
      labels:
        heritage: {{ .Release.Service | quote }}
        release: {{ .Release.Name | quote }}
        chart: {{ template "consul.chart" . }}
        component: "{{ .Release.Name }}-{{ .Values.Component }}"
    spec:
      restartPolicy: Never
      containers:
      - name: "add-agent-acl"
        image: appropriate/curl:latest
        args:
        - -X 
        - PUT
        - --header
        - 'X-Consul-Token: {{ .Values.acl.masterToken }}'
        - --data
        - '{ "Name": "Agent Token", "Type": "client", "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"read\" } key \"_rexec\" { policy = \"write\" }", "ID": "{{ .Values.acl.agentToken }}"}'
        - 'http://{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.HttpPort }}/v1/acl/create'
      - name: "modify-anonymous-acl"
        image: appropriate/curl:latest
        args:
        - -X 
        - PUT
        - --header
        - 'X-Consul-Token: {{ .Values.acl.masterToken }}'
        - --data
        - '{ "Name": "Anonymous Token", "Type": "client", "Rules": "node \"\" { policy = \"read\" }", "ID": "anonymous"}'
        - 'http://{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.HttpPort }}/v1/acl/create'
{{- end }} # consul-ingress.yaml
{{- if .Values.uiIngress.enabled -}}
{{- $releaseName := .Release.Name -}}
{{- $servicePort := .Values.HttpPort -}}
{{- $serviceName := include "consul.fullname" . -}}
{{- $serviceHost := .Values.uiIngress.path }}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
  {{- range $key, $value := .Values.uiIngress.annotations }}
    {{ $key }}: {{ $value | quote }}
  {{- end }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
    {{- range $key, $value := .Values.uiIngress.labels }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
  name: "{{ template "consul.fullname" . }}-ui"
spec:
  rules:
  {{- range .Values.uiIngress.hosts }}
    - host: {{ . }}
      http:
        paths:
          - backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
          {{- if $serviceHost }}
            path: {{ $serviceHost }}
          {{- end }}
  {{- end -}}
  {{- if .Values.uiIngress.tls }}
  tls:
{{ toYaml .Values.uiIngress.tls | indent 4 }}
  {{- end -}}
{{- end }}
 # consul-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: "{{ template "consul.fullname" . }}"
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
  ports:
  - name: http
    port: {{ .Values.HttpPort }}
  - name: rpc
    port: {{ .Values.RpcPort }}
  - name: serflan-tcp
    protocol: "TCP"
    port: {{ .Values.SerflanPort }}
  - name: serflan-udp
    protocol: "UDP"
    port: {{ .Values.SerflanUdpPort }}
  - name: serfwan-tcp
    protocol: "TCP"
    port: {{ .Values.SerfwanPort }}
  - name: serfwan-udp
    protocol: "UDP"
    port: {{ .Values.SerfwanUdpPort }}
  - name: server
    port: {{.Values.ServerPort}}
  - name: consuldns-tcp
    port: {{.Values.ConsulDnsPort}}
  - name: consuldns-udp
    protocol: "UDP"
    port: {{.Values.ConsulDnsPort}}
  clusterIP: None
  selector:
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
 # consul-statefulset.yaml
apiVersion: {{ template "statefulset.apiVersion" . }}
kind: StatefulSet
metadata:
  name: "{{ template "consul.fullname" . }}"
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
{{- if .Values.additionalLabels }}
{{ toYaml .Values.additionalLabels | indent 4 }}
{{- end }}
spec:
  serviceName: "{{ template "consul.fullname" . }}"
  replicas: {{ default 3 .Values.Replicas }}
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      release: {{ .Release.Name | quote }}
      component: "{{ .Release.Name }}-{{ .Values.Component }}"
  template:
    metadata:
      name: "{{ template "consul.fullname" . }}"
{{- if .Values.podAnnotations }}
      annotations:
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
      labels:
        heritage: {{ .Release.Service | quote }}
        release: {{ .Release.Name | quote }}
        chart: {{ template "consul.chart" . }}
        component: "{{ .Release.Name }}-{{ .Values.Component }}"
{{- if .Values.additionalLabels }}
{{ toYaml .Values.additionalLabels | indent 8 }}
{{- end }}
    spec:
      securityContext:
        fsGroup: 1000
{{- if .Values.priorityClassName }}
      priorityClassName: "{{ .Values.priorityClassName }}"
{{- end }}
    {{- if .Values.affinity }}
      affinity:
{{ tpl .Values.affinity . | indent 8 }}
    {{- end }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
    {{- if .Values.tolerations }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
    {{- end }}
      containers:
      - name: "{{ template "consul.fullname" . }}"
        image: "{{ .Values.Image }}:{{ .Values.ImageTag }}"
        imagePullPolicy: "{{ .Values.ImagePullPolicy }}"
        ports:
        - name: http
          containerPort: {{ .Values.HttpPort }}
        - name: rpc
          containerPort: {{ .Values.RpcPort }}
        - name: serflan-tcp
          protocol: "TCP"
          containerPort: {{ .Values.SerflanPort }}
        - name: serflan-udp
          protocol: "UDP"
          containerPort: {{ .Values.SerflanUdpPort }}
        - name: serfwan-tcp
          protocol: "TCP"
          containerPort: {{ .Values.SerfwanPort }}
        - name: serfwan-udp
          protocol: "UDP"
          containerPort: {{ .Values.SerfwanUdpPort }}
        - name: server
          containerPort: {{.Values.ServerPort}}
        - name: consuldns-tcp
          containerPort: {{.Values.ConsulDnsPort}}
        - name: consuldns-udp
          protocol: "UDP"
          containerPort: {{.Values.ConsulDnsPort}}
        resources:
{{ toYaml .Values.Resources | indent 10 }}
        env:
        - name: INITIAL_CLUSTER_SIZE
          value: {{ default 3 .Values.Replicas | quote }}
        - name: STATEFULSET_NAME
          value: "{{ template "consul.fullname" . }}"
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: STATEFULSET_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: DNSPORT
          value: "{{ .Values.ConsulDnsPort }}"
        volumeMounts:
        - name: datadir
          mountPath: /var/lib/consul
        - name: gossip-key
          mountPath: /etc/consul/secrets
          readOnly: true
        {{ range .Values.ConsulConfig }}
        - name: userconfig-{{ .name }}
          readOnly: true
          mountPath: /etc/consul/userconfig/{{ .name }}
        {{ end }}
        {{- if .Values.lifecycle }}
        lifecycle:
{{ tpl (toYaml .Values.lifecycle) . | indent 10 }}
        {{- end }}
        livenessProbe:
          exec:
            command:
            - consul
            - members
            - -http-addr=http://127.0.0.1:{{ .Values.HttpPort }}
          initialDelaySeconds: 300
          timeoutSeconds: 5
        command:
          - "/bin/sh"
          - "-ec"
          - |
            set -o pipefail

            if [ -z "$POD_IP"  ]; then
              POD_IP=$(hostname -i)
            fi
            FQDN_SUFFIX="${STATEFULSET_NAME}.${STATEFULSET_NAMESPACE}.svc{{- if .Values.ClusterDomain }}.{{ .Values.ClusterDomain }}{{- end -}}"
            NODE_NAME="$(hostname -s).${FQDN_SUFFIX}"
            {{- if .Values.Gossip.Encrypt }}
            if [ -e /etc/consul/secrets/gossip-key ]; then
              echo "{\"encrypt\": \"$(base64 /etc/consul/secrets/gossip-key)\"}" > /etc/consul/encrypt.json
              GOSSIP_KEY="-config-file /etc/consul/encrypt.json"
            fi
            {{- end }}

            JOIN_PEERS=""

            {{- if .Values.joinPeers }}
            {{- range .Values.joinPeers }}
            JOIN_PEERS="${JOIN_PEERS}${JOIN_PEERS:+ }{{ . }}"
            {{- end }}
            {{- else }}
            JOIN_PEERS=""
            for i in $( seq 0 $((${INITIAL_CLUSTER_SIZE} - 1)) ); do
              JOIN_PEERS="${JOIN_PEERS}${JOIN_PEERS:+ }${STATEFULSET_NAME}-${i}.${FQDN_SUFFIX}"
            done
            {{- end }}

            JOIN_PEERS=$( printf "%s\n" $JOIN_PEERS | sort | uniq )

            # Require multiple loops in the case of unstable DNS resolution
            SUCCESS_LOOPS=5
            while [ "$SUCCESS_LOOPS" -gt 0 ]; do
              ALL_READY=true
              JOIN_LAN=""
              for THIS_PEER in $JOIN_PEERS; do
                  # Make sure we can resolve hostname and ping IP
                  if PEER_IP="$(ping -c 1 $THIS_PEER | awk -F'[()]' '/PING/{print $2}')" && [ "$PEER_IP" != "" ]; then
                    if [ "${PEER_IP}" != "${POD_IP}" ]; then
                      JOIN_LAN="${JOIN_LAN}${JOIN_LAN:+ } -retry-join=$THIS_PEER"
                    fi
                  else
                    ALL_READY=false
                    break
                  fi
              done
              if $ALL_READY; then
                SUCCESS_LOOPS=$(( SUCCESS_LOOPS - 1 ))
                echo "LAN peers appear ready, $SUCCESS_LOOPS verifications left"
              else
                echo "Waiting for LAN peer $THIS_PEER..."
              fi
              sleep 1s
            done


            WAN_PEERS=""
            {{- range .Values.joinWan }}
            WAN_PEERS="${WAN_PEERS}${WAN_PEERS:+ }{{ . }}"
            {{- end }}

            JOIN_WAN=""
            SUCCESS_LOOPS=5
            while [ "$WAN_PEERS" != "" ] && [ "$SUCCESS_LOOPS" -gt 0 ]; do
              ALL_READY=true
              JOIN_WAN=""
              for THIS_PEER in $WAN_PEERS; do
                  # We don't care if we can ping the peer, but we do care that we can get its IP
                  if PEER_IP="$( ( ping -c 1 $THIS_PEER || true ) | awk -F'[()]' '/PING/{print $2}')" && [ "$PEER_IP" != "" ]; then
                    if [ "${PEER_IP}" != "${POD_IP}" ]; then
                      JOIN_WAN="${JOIN_WAN}${JOIN_WAN:+ } -retry-join-wan=$THIS_PEER"
                    fi
                  else
                    ALL_READY=false
                    break
                  fi
              done
              if $ALL_READY; then
                SUCCESS_LOOPS=$(( SUCCESS_LOOPS - 1 ))
                echo "WAN peers appear ready, $SUCCESS_LOOPS verifications left"
              else
                echo "Waiting for WAN peer $THIS_PEER..."
              fi
              sleep 1s
            done

            exec /bin/consul agent \
            {{- range .Values.ConsulConfig }}
              -config-dir /etc/consul/userconfig/{{ .name }} \
            {{- end}}
            {{- if .Values.ui.enabled }}
              -ui \
            {{- end }}
            {{- if .Values.DisableHostNodeId }}
              -disable-host-node-id \
            {{- end }}
            {{- if .Values.DatacenterName }}
              -datacenter {{ .Values.DatacenterName }} \
            {{- end }}
            {{- if .Values.Domain }}
              -domain={{ .Values.Domain }} \
            {{- end }}
              -data-dir=/var/lib/consul \
              -server \
              -bootstrap-expect=$( echo "$JOIN_PEERS" | wc -w ) \
              -disable-keyring-file \
            {{- if .Values.forceIpv6 }}
              -bind=:: \
            {{- else }}
              -bind=0.0.0.0 \
            {{- end }}
              -advertise=${POD_IP} \
              ${JOIN_LAN} \
              ${JOIN_WAN} \
            {{- if .Values.Gossip.Encrypt }}
              ${GOSSIP_KEY} \
            {{- end }}
            {{- if .Values.forceIpv6 }}
              -client=:: \
            {{- else }}
              -client=0.0.0.0 \
            {{- end }}
              -dns-port=${DNSPORT} \
              -http-port={{ .Values.HttpPort }}
      volumes:
      - name: gossip-key
        secret:
          secretName: {{ template "consul.fullname" . }}-gossip-key
      {{ range .Values.ConsulConfig }}
      - name: userconfig-{{ .name }}
        {{ .type }}:
          {{- if (eq .type "configMap") }}
          name: {{ .name }}
          {{- else if (eq .type "secret") }}
          secretName: {{ .name }}
          {{- end}}
      {{ end }}
  volumeClaimTemplates:
  - metadata:
      name: datadir
    spec:
      accessModes:
        - "ReadWriteOnce"
      resources:
        requests:
          # upstream recommended max is 700M
          storage: "{{ .Values.Storage }}"
    {{- if .Values.StorageClass }}
    {{- if (eq "-" .Values.StorageClass) }}
      storageClassName: ""
    {{- else }}
      storageClassName: "{{ .Values.StorageClass }}"
    {{- end }}
    {{- end }}
 # consul-test-clusterrole.yaml
{{- if .Values.test.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  labels:
    app: {{ template "consul.name" . }}
    chart: {{ template "consul.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "consul.fullname" . }}-test
rules:
- apiGroups: [""]
  resources: ["pods", "pods/log"]
  verbs: ["get", "list"]
- apiGroups: [""]
  resources: ["pods/exec"]
  verbs: ["create"]
{{- end }}
 # consul-test-clusterrolebinding.yaml
{{- if .Values.test.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  labels:
    app: {{ template "consul.name" . }}
    chart: {{ template "consul.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "consul.fullname" . }}-test
subjects:
  - kind: ServiceAccount
    name: {{ template "consul.fullname" . }}-test
    namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "consul.fullname" . }}-test
{{- end }}
 # consul-test-serviceaccount.yaml
{{- if .Values.test.rbac.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: {{ template "consul.name" . }}
    chart: {{ template "consul.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "consul.fullname" . }}-test
{{- end }}
 # consul-test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "{{ .Release.Name }}-ui-test-{{ randAlphaNum 5 | lower }}"
  annotations:
    "helm.sh/hook": test-success
spec:
  {{- if or .Values.test.rbac.create .Values.test.rbac.serviceAccountName }}
  serviceAccountName: {{ if .Values.test.rbac.create }}{{ template "consul.fullname" . }}-test{{ else }}"{{ .Values.test.rbac.serviceAccountName }}"{{ end }}
  {{- end }}
  initContainers:
    - name: test-framework
      image: dduportal/bats:0.4.0
      command:
      - "bash"
      - "-c"
      - |
        set -ex
        # copy bats to tools dir
        cp -R /usr/local/libexec/ /tools/bats/
      volumeMounts:
      - mountPath: /tools
        name: tools
  containers:
    - name: {{ .Release.Name }}-ui-test
      image: {{ .Values.test.image }}:{{ .Values.test.imageTag }}
      command: ["/tools/bats/bats", "-t", "/tests/run.sh"]
      volumeMounts:
      - mountPath: /tests
        name: tests
        readOnly: true
      - mountPath: /tools
        name: tools
  volumes:
  - name: tests
    configMap:
      name: {{ template "consul.fullname" . }}-tests
  - name: tools
    emptyDir: {}
  restartPolicy: Never
 # gossip-secret.yaml
{{ if .Values.Gossip.Create }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "consul.fullname" . }}-gossip-key
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
type: Opaque
data:
  {{ if .Values.GossipKey }}
  gossip-key: {{ .Values.GossipKey | b64enc }}
  {{ else }}
  gossip-key: {{ randAlphaNum 24 | b64enc }}
  {{ end }}
{{ end }}
 # pod-dist-budget.yaml
{{- if .Values.maxUnavailable }}
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: "{{ template "consul.fullname" . }}-pdb"
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
spec:
  maxUnavailable: {{ .Values.maxUnavailable }}
  selector:
    matchLabels:
      component: "{{ .Release.Name }}-{{ .Values.Component }}"
{{- end }}
 # test-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "consul.fullname" . }}-tests
data:
  run.sh: |-
    @test "Testing Consul cluster has quorum" {
      for i in {0..2}; do
        for n in {1..30}; do
          if [ `kubectl exec {{ template "consul.fullname" . }}-$i consul members --namespace={{ .Release.Namespace }} | grep server | wc -l` -ge "3" ]; then
            echo "{{ template "consul.fullname" . }}-$i OK. consul members returning at least 3 records."
            break
          else
            echo "{{ template "consul.fullname" . }}-$i ERROR. consul members returning less than 3 records."
          fi

          if [ "$n" -ge "30" ]; then
            echo "Failed $n times to get members from {{ template "consul.fullname" . }}-$i"
            exit 1
          fi
          sleep 10
        done
      done
    }
 # ui-service.yaml
{{- if .Values.uiService.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: "{{ template "consul.fullname" . }}-ui"
{{- with .Values.uiService.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "consul.chart" . }}
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
spec:
  ports:
  - name: http
    port: {{ .Values.HttpPort }}
  selector:
    component: "{{ .Release.Name }}-{{ .Values.Component }}"
  type: "{{ .Values.uiService.type }}"
{{- end }}

# Default values for consul.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name: value

## Consul service ports
HttpPort: 8500
RpcPort: 8400
SerflanPort: 8301
SerflanUdpPort: 8301
SerfwanPort: 8302
SerfwanUdpPort: 8302
ServerPort: 8300
ConsulDnsPort: 8600

## Specify the domain with which consul should run with
## This will be passed as a -domain parameter
Domain: consul

## Used as selector
Component: "consul"
Replicas: 3
Image: "consul"
ImageTag: "1.5.3"
ImagePullPolicy: "Always"
Resources: {}
 # requests:
 #   cpu: "100m"
 #   memory: "256Mi"
 # limits:
 #   cpu: "500m"
 #   memory: "512Mi"
## Persistent volume size

priorityClassName: ""

Storage: "1Gi"

## Needed for 0.8.0 and later IF all consul containers are spun up
## on the same machine. Without this they all generate the same
## host id.
DisableHostNodeId: false

## Datacenter name for consul. If not supplied, will use the consul
## default 'dc1'
# DatacenterName: dc1

## Explicitly set LAN hosts to join.
# Added as -retry-join argument
# If you set joinPeers then we will not auto-build the list of peers for you
# These hostnames will be verified to be resolvable and ping-able before the consul service will start
joinPeers: []

## Set list of WAN hosts to join
# Added as -retry-join-wan argument
# These hostnames will be verified to be resolvable before the consul service will start
joinWan: []

## Encrypt Gossip Traffic
Gossip:
  Encrypt: true
  Create: true

## predefined value for gossip key.
## Will use a generated random alpha numeric if not provided
# GossipKey: key

## consul data Persistent Volume Storage Class
## If defined, StorageClassName: <storageClass>
## If set to "-", StorageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
##   set, choosing the default provisioner.  (gp2 on AWS, standard on
##   GKE, AWS & OpenStack)
##
# StorageClass: "-"

## Setting maxUnavailable will create a pod disruption budget that will prevent
## voluntarty cluster administration from taking down too many consul pods. If
## you set maxUnavailable, you should set it to ceil((n/2) - 1), where
## n = Replicas. For example, if you have 5 or 6 Replicas, you'll want to set
## maxUnavailable = 2. If you are using the default of 3 Replicas, you'll want
## to set maxUnavailable to 1.
maxUnavailable: 1

## nodeAffinity settings
# nodeAffinity:
#   requiredDuringSchedulingIgnoredDuringExecution:
#     nodeSelectorTerms:
#     - matchExpressions:
#       - key: cloud.google.com/gke-preemptible
#         operator: NotIn
#         values:
#         - true

## Affinity settings
affinity: |
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 1
      podAffinityTerm:
        topologyKey: kubernetes.io/hostname
        labelSelector:
          matchExpressions:
          - key: component
            operator: In
            values:
            - "{{ .Release.Name }}-{{ .Values.Component }}"

## Enable Consul Web UI
##
ui:
  enabled: true
## Create dedicated UI service
##
uiService:
  enabled: true
  type: "NodePort"
  annotations: {}

ConsulConfig: []
#  - type: secret
#    name: consul-defaults
#  - type: configMap
#    name: consul-defaults

## Create an Ingress for the Web UI
uiIngress:
  enabled: false
  annotations: {}
  labels: {}
  hosts: []
  path: /
  tls: []

## Useful when ACLs are enabled
acl:
  enabled: false
  masterToken: ""
  agentToken: ""

## test container details
test:
  image: lachlanevenson/k8s-kubectl
  imageTag: v1.4.8-bash
  rbac:
    create: false
    serviceAccountName: ""

nodeSelector: {}
tolerations: []
additionalLabels: {}
podAnnotations: {}

# Lifecycle for StatefulSet
# lifecycle:
#   preStop:
#     exec:
#       command:
#       - sh
#       - -c
#       - "sleep 60"
forceIpv6: false
