apiVersion: apps/v1
kind: Deployment
metadata:
  name: controller-manager
  namespace: system
  labels:
    control-plane: controller-manager
spec:
  selector:
    matchLabels:
      control-plane: controller-manager
  replicas: 1
  template:
    metadata:
      labels:
        control-plane: controller-manager
    spec:
      containers:
      - command:
        - /manager
        args:
        - --leader-elect
        - "--metrics-bind-addr=127.0.0.1:8080"
        image: controller:latest
        name: manager
      terminationGracePeriodSeconds: 10
      tolerations:
        - effect: NoSchedule
          key: ${K8S_CP_LABEL:=node-role.kubernetes.io/control-plane}
        - effect: NoSchedule
          key: node-role.kubernetes.io/master
      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
