apiVersion: v1
kind: ServiceAccount
metadata:
  name: node-maintenance-operator-controller-manager
  namespace: {{ .Release.Namespace }}
  labels:
    node-maintenance-operator: ""
  {{- include "chart.labels" . | nindent 4 }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-maintenance-operator-controller-manager
  namespace: {{ .Release.Namespace }}
  labels:
    control-plane: controller-manager
    node-maintenance-operator: ""
  {{- include "chart.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.controllerManager.replicas }}
  selector:
    matchLabels:
      control-plane: controller-manager
      node-maintenance-operator: ""
    {{- include "chart.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        control-plane: controller-manager
        node-maintenance-operator: ""
      {{- include "chart.selectorLabels" . | nindent 8 }}
      annotations:
        kubectl.kubernetes.io/default-container: manager
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role.kubernetes.io/master
                operator: Exists
            - matchExpressions:
              - key: node-role.kubernetes.io/control-plane
                operator: Exists
      containers:
      - args:
        - --health-probe-bind-address=:8081
        - --metrics-bind-address=:8080
        - --leader-elect
        command:
        - /manager
        env:
        - name: OPERATOR_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: KUBERNETES_CLUSTER_DOMAIN
          value: {{ .Values.kubernetesClusterDomain | quote }}
        image: {{ .Values.controllerManager.manager.image | quote }}
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8081
          initialDelaySeconds: 15
          periodSeconds: 20
        name: manager
        ports:
        - containerPort: 9443
          name: webhook-server
          protocol: TCP
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8081
          initialDelaySeconds: 5
          periodSeconds: 10
        resources: {{- toYaml .Values.controllerManager.manager.resources | nindent 10 }}
        securityContext:
          allowPrivilegeEscalation: false
        volumeMounts:
        - mountPath: /tmp/k8s-webhook-server/serving-certs
          name: cert
          readOnly: true
      priorityClassName: system-cluster-critical
      securityContext:
        runAsNonRoot: true
      serviceAccountName: node-maintenance-operator-controller-manager
      terminationGracePeriodSeconds: 10
      tolerations:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
      - effect: NoSchedule
        key: node-role.kubernetes.io/control-plane
      volumes:
      - name: cert
        secret:
          defaultMode: 420
          secretName: webhook-server-cert
