apiVersion: apps/v1
kind: Deployment
metadata:
  name: olm-operator
  namespace: {{ .Values.namespace }}
  labels:
    app: olm-operator
spec:
  strategy:
    type: RollingUpdate
  replicas: {{ .Values.olm.replicaCount }}
  selector:
    matchLabels:
      app: olm-operator
  template:
    metadata:
      labels:
        app: olm-operator
    spec:
      serviceAccountName: olm-operator-serviceaccount
      {{- if and .Values.installType (eq .Values.installType "ocp") }}
      priorityClassName: "system-cluster-critical"
      {{- end }}
      containers:
        - name: olm-operator
          command:
          - /bin/olm
          args:
          - -namespace
          - $(OPERATOR_NAMESPACE)
          {{- if .Values.watchedNamespaces }}
          - -watchedNamespaces
          - {{ .Values.watchedNamespaces }}
          {{- end }}
          {{- if .Values.olm.commandArgs }}
          - {{ .Values.olm.commandArgs }}
          {{- end }}
          {{- if .Values.debug }}
          - -debug
          {{- end }}
          {{- if .Values.writeStatusName }}
          - -writeStatusName
          - {{ .Values.writeStatusName }}
          {{- end }}
          {{- if .Values.writePackageServerStatusName }}
          - -writePackageServerStatusName
          - {{ .Values.writePackageServerStatusName }}
          {{- end }}
          {{- if .Values.olm.tlsCertPath }}
          - -tls-cert
          - {{ .Values.olm.tlsCertPath }}
          {{- end }}
          {{- if .Values.olm.tlsKeyPath }}
          - -tls-key
          - {{ .Values.olm.tlsKeyPath }}
          {{- end }}
          image: {{ .Values.olm.image.ref }}
          imagePullPolicy: {{ .Values.olm.image.pullPolicy }}
          ports:
            - containerPort: {{ .Values.olm.service.internalPort }}
            - containerPort: 8081
              name: metrics
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /healthz
              port: {{ .Values.olm.service.internalPort }}
          readinessProbe:
            httpGet:
              path: /healthz
              port: {{ .Values.olm.service.internalPort }}
          terminationMessagePolicy: FallbackToLogsOnError
          env:
        {{ if and .Values.installType (eq .Values.installType "ocp") }}
          - name: RELEASE_VERSION
            value: "0.0.1-snapshot"
        {{ end }}
          - name: OPERATOR_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: OPERATOR_NAME
            value: olm-operator
          {{- if .Values.olm.resources }}
          resources:
{{ toYaml .Values.olm.resources | indent 12 }}
          {{- end}}
          {{ if and .Values.installType (eq .Values.installType "ocp") }}
          volumeMounts:
          - mountPath: /var/run/secrets/serving-cert
            name: serving-cert
          {{ end }}
      {{ if and .Values.installType (eq .Values.installType "ocp") }}
      volumes:
      - name: serving-cert
        secret:
          secretName: olm-operator-serving-cert
      {{ end }}
    {{- if .Values.olm.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.olm.nodeSelector | indent 8 }}
    {{- end }}
    {{- if .Values.olm.tolerations }}
      tolerations:
{{ toYaml .Values.olm.tolerations | indent 6 }}
    {{- end }}
