{{- if eq .Values.interceptor.enabled true }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "edp-tekton-interceptor.name" . }}
  labels:
    {{- include "edp-tekton-interceptor.labels" . | nindent 4 }}
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "edp-tekton-interceptor.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.interceptor.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "edp-tekton-interceptor.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.interceptor.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "edp-tekton-interceptor.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.interceptor.podSecurityContext | nindent 8 }}
      containers:
        - command:
          - /edpinterceptor
          args:
            - '-logtostderr'
            - '-stderrthreshold'
            - INFO
          env:
            - name: SYSTEM_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: CONFIG_LOGGING_NAME
              value: config-logging-triggers
            - name: CONFIG_OBSERVABILITY_NAME
              value: config-observability-triggers
            - name: METRICS_DOMAIN
              value: tekton.dev/triggers
            - name: INTERCEPTOR_NAME
              value: edp
          name: tekton-triggers-edp-interceptor
          securityContext:
            {{- toYaml .Values.interceptor.securityContext | nindent 12 }}
          image: "{{ .Values.interceptor.image.repository }}:{{ .Values.interceptor.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.interceptor.image.pullPolicy }}
          ports:
            - name: https
              containerPort: 8443
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /ready
              port: 8443
              scheme: HTTPS
            initialDelaySeconds: 5
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          resources:
            {{- toYaml .Values.interceptor.resources | nindent 12 }}
      {{- with .Values.interceptor.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.interceptor.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.interceptor.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
