apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "datadog-operator.fullname" . }}
  labels:
{{ include "datadog-operator.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "datadog-operator.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "datadog-operator.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
      annotations:
        ad.datadoghq.com/{{ .Chart.Name }}.check_names: '["openmetrics"]'
        ad.datadoghq.com/{{ .Chart.Name }}.init_configs: '[{}]'
        ad.datadoghq.com/{{ .Chart.Name }}.instances: |
          [{
            "prometheus_url": "http://%%host%%:8383/metrics",
            "namespace": "datadog.operator",
            "metrics": ["*"]
          }]
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "datadog-operator.fullname" . }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            - name: WATCH_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: OPERATOR_NAME
              value: {{ .Chart.Name }}
          args:
            - --zap-level={{ .Values.logLevel }}
            - --zap-encoder=console
            # - --zap-stacktrace-level=error // TODO: uncomment after releasing v0.3.0
            - "--supportExtendedDaemonset={{ .Values.supportExtendedDaemonset}}"
            - "--probesPort={{ .Values.probesPort }}"
            - "--metricsPort={{ .Values.metricsPort }}"
          {{- if .Values.secretBackend.command }}
            - "--secretBackendCommand={{ .Values.secretBackend.command }}"
          {{- end }}
          ports:
            - name: metrics
              containerPort: {{ .Values.metricsPort }}
              protocol: TCP
          readinessProbe:
            httpGet:
              path: /ready
              port: {{ .Values.probesPort }}
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /live
              port: {{ .Values.probesPort }}
            periodSeconds: 10
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
