# helm_charts_deployment-secrets.yaml
{{- if and (not .Values.server.kubernetes.enabled) .Values.runner.enabled .Values.secrets.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "drone.fullname" . }}-secrets
  labels:
    app: {{ template "drone.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
    component: secrets
spec:
  selector:
    matchLabels:
      app: {{ template "drone.name" . }}
      release: "{{ .Release.Name }}"
      component: secrets
  replicas: {{ .Values.secrets.replicas }}
  template:
    metadata:
{{- if .Values.secrets.annotations }}
      annotations:
{{ toYaml .Values.secrets.annotations | indent 8 }}
{{- end }}
      labels:
        app: {{ template "drone.name" . }}
        release: "{{ .Release.Name }}"
        component: secrets
    spec:
{{- if .Values.secrets.schedulerName }}
      schedulerName: "{{ .Values.secrets.schedulerName }}"
{{- end }}
{{- if .Values.secrets.affinity }}
      affinity:
{{ toYaml .Values.secrets.affinity | indent 8 }}
{{- end }}
{{- if .Values.secrets.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.secrets.nodeSelector | indent 8 }}
{{- end }}
{{- with .Values.secrets.tolerations }}
      tolerations:
        {{- toYaml . | nindent 6 }}
{{- end }}
      serviceAccountName: {{ template "drone.serviceAccountName" . }}
      containers:
      - name: secrets
        image: {{ .Values.images.secrets.repository }}:{{ .Values.images.secrets.tag }}
        imagePullPolicy: {{ .Values.images.secrets.pullPolicy }}
        resources:
          {{ toYaml .Values.secrets.resources | indent 10 }}
        ports:
        - name: http
          containerPort: {{ .Values.secrets.httpPort }}
          protocol: TCP
        livenessProbe:
          initialDelaySeconds: 2
          periodSeconds: 20
          tcpSocket:
            port: http
        env:
        - name: DEBUG
          value: {{ .Values.secrets.logs.debug | quote }}
        - name: KUBERNETES_NAMESPACE
          value: {{ .Release.Namespace }}
        - name: SERVER_ADDRESS
          value: :{{ .Values.secrets.httpPort }}
        - name: SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: {{ template "drone.fullname" . }}
              key: secret
{{- end }}