apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "wetty.fullname" . }}
  labels:
    {{- include "wetty.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "wetty.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "wetty.selectorLabels" . | nindent 8 }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "wetty.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 3000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 5
            periodSeconds: 5
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 5
            periodSeconds: 5
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - mountPath: /src/.ssh
            name: ssh
          - mountPath: /usr/src/app/config.json
            name: config
            subPath: config.json
      initContainers:
        - command:
          - /bin/sh
          - /tmp/key-copy.sh
          image: alpine
          imagePullPolicy: Always
          name: init
          resources:
            limits:
              cpu: 100m
              memory: 64Mi
            requests:
              cpu: 10m
              memory: 16Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
          - mountPath: /src/.ssh
            name: ssh
          - mountPath: /src
            name: sshkeys
          - mountPath: /tmp/key-copy.sh
            name: wetty-key-copy
            subPath: key-copy.sh
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
        - emptyDir: {}
          name: ssh
        - name: sshkeys
          secret:
            defaultMode: 400
            secretName: wetty-ssh-keys
        - configMap:
            defaultMode: 420
            name: wetty-config
          name: config
        - configMap:
            defaultMode: 0755
            name: wetty-key-copy
          name: wetty-key-copy
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
