apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "Hipster.fullname" . }}
  labels:
    {{- include "Hipster.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "Hipster.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "Hipster.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "Hipster.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - name: data
            mountPath: /data
          - name: appsettings
            mountPath: /app/appsettings.json
            subPath: appsettings.json
            readOnly: true
          {{- if .Values.service.https }}
          - name: tls-certificates
            mountPath: /app/tls
            readOnly: true
          {{- end }}
      {{- if .Values.init.enabled }}
      initContainers:
      - name: init
        image: {{ .Values.init.image }}
        command: {{- toYaml .Values.init.command | nindent 10 }}
        volumeMounts:
        - name: data
          mountPath: /data
        - name: appsettings
          mountPath: /app/appsettings.json
          subPath: appsettings.json
          readOnly: true
      {{- end }}
      volumes:
      - name: data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistence.existingClaim | default (include "Hipster.fullname" .) }}
      {{- else }}
        emptyDir: {}
      {{- end }}
      - name: appsettings
        configMap:
          name: {{ template "Hipster.fullname" . }}-appsettings
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
