apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "woodpecker-server.fullname" . }}
  labels:
    {{- include "woodpecker-server.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    {{- toYaml .Values.updateStrategy | nindent 4 }}
  selector:
    matchLabels:
      {{- include "woodpecker-server.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        prometheus.io/scrape: 'true'
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "woodpecker-server.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "woodpecker-server.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 8000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8000
          readinessProbe:
            httpGet:
              path: /healthz
              port: 8000
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - name: storage-volume
            mountPath: {{ .Values.persistentVolume.mountPath }}
          env:
            {{- range $key, $value := .Values.env }}
            - name: {{ $key }}
              value: {{ $value | quote }}
            {{- end }}
          envFrom:
            {{- range .Values.extraSecretNamesForEnvFrom }}
            - secretRef:
                name: {{ . }}
            {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
      - name: storage-volume
        {{- if .Values.persistentVolume.enabled }}
        persistentVolumeClaim:
          claimName: {{ if .Values.persistentVolume.existingClaim }}{{ .Values.persistentVolume.existingClaim }}{{- else }}{{ template "woodpecker-server.fullname" . }}{{- end }}
        {{- end -}}
