apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "chart.fullname" . }}-controller-manager
  labels:
    app.kubernetes.io/component: manager
    app.kubernetes.io/created-by: jobs-manager-operator
    app.kubernetes.io/part-of: jobs-manager-operator
    control-plane: controller-manager
  {{- include "chart.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.controllerManager.replicas }}
  selector:
    matchLabels:
      control-plane: controller-manager
    {{- include "chart.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        control-plane: controller-manager
      {{- include "chart.selectorLabels" . | nindent 8 }}
      annotations:
        kubectl.kubernetes.io/default-container: manager
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/arch
                operator: In
                values:
                - amd64
                - arm64
                - ppc64le
                - s390x
              - key: kubernetes.io/os
                operator: In
                values:
                - linux
      containers:
      - args:
        {{- toYaml .Values.controllerManager.manager.args | nindent 8 }}
        {{- if .Values.controllerManager.manager.leaderElectionId }}
        - --leader-election-id={{ .Values.controllerManager.manager.leaderElectionId }}
        {{- end }}
        {{- if .Values.controllerManager.manager.devMode }}
        - --dev-mode
        {{- end }}
        command:
        - /manager
        env:
        - name: KUBERNETES_CLUSTER_DOMAIN
          value: {{ quote .Values.kubernetesClusterDomain }}
        {{- if .Values.controllerManager.manager.env.LOG_LEVEL }}
        - name: LOG_LEVEL
          value: {{ quote .Values.controllerManager.manager.env.LOG_LEVEL }}
        {{- end }}
        image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag | default .Chart.AppVersion }}
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8081
          initialDelaySeconds: 15
          periodSeconds: 20
        name: manager
        ports:
        - containerPort: 8443
          name: https
          protocol: TCP
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8081
          initialDelaySeconds: 5
          periodSeconds: 10
        resources: {{- toYaml .Values.controllerManager.manager.resources | nindent 10 }}
        securityContext: {{- toYaml .Values.controllerManager.manager.containerSecurityContext | nindent 10 }}
      securityContext:
        runAsNonRoot: true
      serviceAccountName: {{ include "chart.fullname" . }}-controller-manager
      terminationGracePeriodSeconds: 10
