apiVersion: apps/v1
kind: Deployment
metadata:
  name: tigera-operator
  namespace: tigera-operator
  labels:
    k8s-app: tigera-operator
spec:
  replicas: 1
  selector:
    matchLabels:
      name: tigera-operator
  template:
    metadata:
      labels:
        name: tigera-operator
        k8s-app: tigera-operator
    spec:
      tolerations:
        - effect: NoExecute
          operator: Exists
        - effect: NoSchedule
          operator: Exists
      serviceAccountName: tigera-operator
      hostNetwork: true
      # This must be set when hostNetwork is true or else the cluster services won't resolve
      dnsPolicy: ClusterFirstWithHostNet
      containers:
        - name: tigera-operator
          image: {{ template "tigera-operator.image" .Values.tigeraOperator}}
          imagePullPolicy: IfNotPresent
          command:
            - operator
          env:
            - name: WATCH_NAMESPACE
              value: ""
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: OPERATOR_NAME
              value: "tigera-operator"
            - name: TIGERA_OPERATOR_INIT_IMAGE_VERSION
              value: {{.Values.tigeraOperator.version}}
{{- if eq .Values.installation.kubernetesProvider "openshift" }}
      initContainers:
        - name: create-initial-resources
          image: {{.Values.calicoctl.image}}:{{.Values.calicoctl.tag}}
          env:
            - name: DATASTORE_TYPE
              value: kubernetes
          command:
            - /script/install.sh
          volumeMounts:
            - name: calico-resources
              mountPath: /calico-resources
            - name: install-resources-script
              mountPath: /script/install.sh
              subPath: install.sh
      volumes:
        - name: calico-resources
          configMap:
            defaultMode: 0400
            name: calico-resources
        - name: install-resources-script
          configMap:
            defaultMode: 0777
            name: install-resources-script
{{- end}}
