apiVersion: apps/v1
kind: Deployment
metadata:
  name: cluster-version-operator
  namespace: openshift-cluster-version
  annotations:
    exclude.release.openshift.io/internal-openshift-hosted: "true"
    include.release.openshift.io/self-managed-high-availability: "true"
spec:
  selector:
    matchLabels:
      k8s-app: cluster-version-operator
  strategy:
    type: Recreate
  template:
    metadata:
      name: cluster-version-operator
      annotations:
        target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}'
      labels:
        k8s-app: cluster-version-operator
    spec:
      # prevents circular dependency with OpenShift service-ca CM volume injection by
      # KAS and creation of the CM by KCM
      # TODO: remove in 4.9
      automountServiceAccountToken: false
      containers:
      - name: cluster-version-operator
        image: {{.ReleaseImage}}
        imagePullPolicy: IfNotPresent
        args:
          - "start"
          - "--release-image={{.ReleaseImage}}"
          - "--enable-auto-update=false"
          - "--enable-default-cluster-version=true"
          - "--listen=0.0.0.0:9099"
          - "--serving-cert-file=/etc/tls/serving-cert/tls.crt"
          - "--serving-key-file=/etc/tls/serving-cert/tls.key"
          - "--v=5"
        resources:
          requests:
            cpu: 20m
            memory: 50Mi
        terminationMessagePolicy: FallbackToLogsOnError
        volumeMounts:
          - mountPath: /etc/ssl/certs
            name: etc-ssl-certs
            readOnly: true
          - mountPath: /etc/cvo/updatepayloads
            name: etc-cvo-updatepayloads
            readOnly: true
          - mountPath: /etc/tls/serving-cert
            name: serving-cert
            readOnly: true
          - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
            name: kube-api-access
            readOnly: true
        env:
          - name: KUBERNETES_SERVICE_PORT # allows CVO to communicate with apiserver directly on same host.  Is substituted with port from infrastructures.status.apiServerInternalURL if available.
            value: "6443"
          - name: KUBERNETES_SERVICE_HOST # allows CVO to communicate with apiserver directly on same host.  Is substituted with hostname from infrastructures.status.apiServerInternalURL if available.
            value: "127.0.0.1"
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: CLUSTER_PROFILE
            value: {{ .ClusterProfile }}
      hostNetwork: true
      nodeSelector:
        node-role.kubernetes.io/master: ""
      priorityClassName: "system-cluster-critical"
      terminationGracePeriodSeconds: 130
      tolerations:
      - key: "node-role.kubernetes.io/master"
        operator: Exists
        effect: "NoSchedule"
      - key: "node.kubernetes.io/unschedulable"
        operator: Exists
        effect: "NoSchedule"
      - key: "node.kubernetes.io/network-unavailable"
        operator: Exists
        effect: "NoSchedule"
      - key: "node.kubernetes.io/not-ready"
        operator: "Exists"
        effect: "NoSchedule" 
      - key: "node.kubernetes.io/unreachable"
        operator: "Exists"
        effect: "NoExecute"
        tolerationSeconds: 120 
      - key: "node.kubernetes.io/not-ready"
        operator: "Exists"
        effect: "NoExecute"
        tolerationSeconds: 120 
      volumes:
        - name: etc-ssl-certs
          hostPath:
            path: /etc/ssl/certs
        - name: etc-cvo-updatepayloads
          hostPath:
            path: /etc/cvo/updatepayloads
        - name: serving-cert
          secret:
            secretName: cluster-version-operator-serving-cert
        - name: kube-api-access
          projected:
            defaultMode: 420
            sources:
            - serviceAccountToken:
                expirationSeconds: 3600
                path: token
            - configMap:
                items:
                - key: ca.crt
                  path: ca.crt
                name: kube-root-ca.crt
            - downwardAPI:
                items:
                - fieldRef:
                    apiVersion: v1
                    fieldPath: metadata.namespace
                  path: namespace
