# helm_charts_sentinel-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "stolon.fullname" . }}-sentinel
  labels:
    app: {{ template "stolon.name" . }}
    chart: {{ template "stolon.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.sentinel.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "stolon.name" . }}
      release: {{ .Release.Name }}
      component: stolon-sentinel
  template:
    metadata:
      labels:
        app: {{ template "stolon.name" . }}
        release: {{ .Release.Name }}
        component: stolon-sentinel
        stolon-cluster: {{ template "stolon.fullname" . }}
      annotations:
        checksum/config: {{ include (print .Template.BasePath "/hooks/update-cluster-spec-job.yaml") . | sha256sum }}
{{- with .Values.sentinel.annotations }}
{{ toYaml . | indent 8 }}
{{- end }}
    spec:
{{- if .Values.sentinel.priorityClassName }}
      priorityClassName: "{{ .Values.sentinel.priorityClassName }}"
{{- end }}
      serviceAccountName: {{ template "stolon.serviceAccountName" . }}
{{- if .Values.image.pullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.image.pullSecrets | indent 8 }}
{{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - "/bin/bash"
            - "-ec"
            - |
              exec gosu stolon stolon-sentinel
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: STSENTINEL_CLUSTER_NAME
              value: {{ template "stolon.clusterName" . }}
            - name: STSENTINEL_STORE_BACKEND
              value: {{ .Values.store.backend | quote}}
            {{- if eq .Values.store.backend "kubernetes" }}
            - name: STSENTINEL_KUBE_RESOURCE_KIND
              value: {{ .Values.store.kubeResourceKind  | quote}}
            {{- else }}
            - name: STSENTINEL_STORE_ENDPOINTS
              value: {{ .Values.store.endpoints | quote}}
            {{- end }}
            - name: STSENTINEL_METRICS_LISTEN_ADDRESS
              value: "0.0.0.0:{{ .Values.ports.metrics.containerPort }}"
            - name: STSENTINEL_DEBUG
              value: {{ .Values.debug | quote}}
{{- if .Values.sentinel.extraEnv }}
{{ toYaml .Values.sentinel.extraEnv | indent 12 }}
{{- end }}
          ports:
{{- range $key, $value := .Values.ports }}
            - name: {{ $key }}
{{ toYaml $value | indent 14 }}
{{- end }}
          resources:
{{ toYaml .Values.sentinel.resources | indent 12 }}
{{- with .Values.sentinel.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.sentinel.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.sentinel.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
{{- end }}