---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: controller-manager
  namespace: system
  labels:
    control-plane: capa-controller-manager
spec:
  selector:
    matchLabels:
      control-plane: capa-controller-manager
  replicas: 1
  template:
    metadata:
      labels:
        control-plane: capa-controller-manager
    spec:
      containers:
      - args:
        - "--metrics-bind-addr=127.0.0.1:8080"
        - "--leader-elect"
        - "--feature-gates=EKS=${CAPA_EKS:=true},EKSEnableIAM=${CAPA_EKS_IAM:=false},EKSAllowAddRoles=${CAPA_EKS_ADD_ROLES:=false},EKSFargate=${EXP_EKS_FARGATE:=false},MachinePool=${EXP_MACHINE_POOL:=false},EventBridgeInstanceState=${EVENT_BRIDGE_INSTANCE_STATE:=false},AutoControllerIdentityCreator=${AUTO_CONTROLLER_IDENTITY_CREATOR:=true}"
        image: controller:latest
        imagePullPolicy: Always
        name: manager
        ports:
        - containerPort: 9440
          name: healthz
          protocol: TCP
        readinessProbe:
          httpGet:
            path: /readyz
            port: healthz
        livenessProbe:
          httpGet:
            path: /healthz
            port: healthz
      terminationGracePeriodSeconds: 10
      tolerations:
        - effect: NoSchedule
          key: node-role.kubernetes.io/master
        - effect: NoSchedule
          key: node-role.kubernetes.io/control-plane
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 10
            preference:
              matchExpressions:
              - key: ${K8S_CP_LABEL:=node-role.kubernetes.io/control-plane}
                operator: Exists
            # remove once usage of node-role.kubernetes.io/master is removed from Kubernetes
          - weight: 10
            preference:
              matchExpressions:
              - key: node-role.kubernetes.io/master
                operator: Exists
      serviceAccountName: manager
