---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "hydra-maester.fullname" . }}
  labels:
    {{- include "hydra-maester.labels" . | nindent 4 }}
    {{- with .Values.deployment.extraLabels }}
      {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  replicas: {{ .Values.replicaCount }}
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      control-plane: controller-manager
      app.kubernetes.io/name: {{ include "hydra-maester.fullname" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        control-plane: controller-manager
        app.kubernetes.io/name: {{ include "hydra-maester.fullname" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        {{- with .Values.deployment.extraLabels }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
        {{- with .Values.deployment.podMetadata.labels }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
      annotations:
        {{- with .Values.deployment.extraAnnotations }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
        {{- with .Values.deployment.podMetadata.annotations }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - /manager
          args:
            - --metrics-addr=127.0.0.1:8080
            - --hydra-url=http://{{ .Values.adminService.name | default ( include "hydra-maester.adminService" . ) }}
            - --hydra-port={{ .Values.adminService.port | default 4445 }}
            {{- with .Values.adminService.endpoint }}
            - --endpoint={{ . }}
            {{- end }}
            {{- if .Values.forwardedProto }}
            - --forwarded-proto={{ .Values.forwardedProto }}
            {{- end }}
            {{- if .Values.singleNamespaceMode }}
            - --namespace={{ .Release.Namespace }}
            {{- end }}
            {{- if .Values.deployment.args.syncPeriod }}
            - --sync-period={{ .Values.deployment.args.syncPeriod }}
            {{- end }}
          resources:
            {{- toYaml .Values.deployment.resources | nindent 12 }}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          {{- if .Values.deployment.securityContext }}
          securityContext:
            {{- toYaml .Values.deployment.securityContext | nindent 12 }}
          {{- end }}
      serviceAccountName: {{ include "hydra-maester.fullname" . }}-account
      automountServiceAccountToken: {{ .Values.deployment.automountServiceAccountToken }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName }}
      {{- end }}
      nodeSelector:
      {{- with .Values.deployment.nodeSelector }}
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.deployment.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.deployment.topologySpreadConstraints }}
      topologySpreadConstraints:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.deployment.dnsConfig }}
      dnsConfig:
        {{- toYaml . | nindent 8 }}
    {{- end }}
