{{- if .Values.controller.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: akri-controller-deployment
  labels: {{- include "akri.labels" . | nindent 4 }}
    app.kubernetes.io/name: akri-controller
    app.kubernetes.io/component: controller
spec:
  replicas: 1
  selector:
    matchLabels: {{- include "akri.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/name: akri-controller
  template:
    metadata:
      labels: {{- include "akri.labels" . | nindent 8 }}
        app.kubernetes.io/name: akri-controller
        app.kubernetes.io/component: controller
    spec:
      {{- if .Values.rbac.enabled }}
      serviceAccountName: 'akri-controller-sa'
      {{- end }}
      containers:
      - name: akri-controller
        {{- if .Values.useDevelopmentContainers }}
        {{- if .Values.useLatestContainers }}
        image: {{ printf "%s:%s" .Values.controller.image.repository (default "latest-dev" .Values.controller.image.tag) | quote }}
        {{- else }}
        image: {{ printf "%s:%s" .Values.controller.image.repository (default (printf "v%s-dev" .Chart.AppVersion) .Values.controller.image.tag) | quote }}
        {{- end }}
        {{- else }}
        {{- if .Values.useLatestContainers }}
        image: {{ printf "%s:%s" .Values.controller.image.repository (default "latest" .Values.controller.image.tag) | quote }}
        {{- else }}
        image: {{ printf "%s:%s" .Values.controller.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.controller.image.tag) | quote }}
        {{- end }}
        {{- end }}
        {{- with .Values.controller.image.pullPolicy }}
        imagePullPolicy: {{ . }}
        {{- end }}
        {{- if .Values.controller.securityContext }}
        securityContext:
        {{- toYaml .Values.controller.securityContext | nindent 10 }}
        {{- end}}
        resources:
          requests:
            memory: {{ .Values.controller.resources.memoryRequest }}
            cpu: {{ .Values.controller.resources.cpuRequest }}
          limits:
            memory: {{ .Values.controller.resources.memoryLimit }}
            cpu: {{ .Values.controller.resources.cpuLimit }}
        {{- if .Values.prometheus.enabled }}
        ports:
          - name: {{ .Values.prometheus.portName | quote }}
            containerPort: {{ .Values.prometheus.port }}
        {{- end }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.controller.allowOnControlPlane }}
      tolerations:
        {{- /* Allow this pod to run on the master. */}}
        - key: node-role.kubernetes.io/master
          effect: NoSchedule
      {{- end }}
      nodeSelector:
        {{- if .Values.controller.onlyOnControlPlane }}
        node-role.kubernetes.io/master: ""
        {{- end }}
        "kubernetes.io/os": linux
        {{- if .Values.controller.nodeSelectors }}
          {{- toYaml .Values.controller.nodeSelectors | nindent 8 }}
        {{- end }}
{{- end }}
