{{- if .Values.detached_integrations.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "oncall.detached_integrations.fullname" . }}
  labels:
    {{- include "oncall.detached_integrations.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.detached_integrations.replicaCount }}
  selector:
    matchLabels:
      {{- include "oncall.detached_integrations.selectorLabels" . | nindent 6 }}
  strategy:
    {{- toYaml .Values.detached_integrations.updateStrategy | nindent 4 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        random-annotation: {{ randAlphaNum 10 | lower }}
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "oncall.detached_integrations.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "oncall.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      initContainers:
        {{- include "oncall.initContainer" . | indent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: {{ include "oncall.engine.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- if .Values.oncall.devMode }}
          command: ["sh", "-c", "uwsgi --disable-logging --py-autoreload 3 --ini uwsgi.ini"]
          {{- end }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          env:
            {{- include "snippet.oncall.engine.env" . | nindent 12 }}
            - name: ROOT_URLCONF
              value: "engine.integrations_urls"
          livenessProbe:
            httpGet:
              path: /health/
              port: http
            periodSeconds: 60
            timeoutSeconds: 3
          readinessProbe:
            httpGet:
              path: /ready/
              port: http
            periodSeconds: 60
            timeoutSeconds: 3
          startupProbe:
            httpGet:
              path: /startupprobe/
              port: http
            periodSeconds: 10
            timeoutSeconds: 3
          resources:
            {{- toYaml .Values.detached_integrations.resources | nindent 12 }}
          {{- with .Values.detached_integrations.extraVolumeMounts }}
          volumeMounts: {{- . | toYaml | nindent 12 }}
          {{- end }}
      {{- with .Values.detached_integrations.extraContainers }}
        {{- tpl . $ | nindent 8 }}
      {{- end }}
      {{- with .Values.detached_integrations.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.detached_integrations.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.detached_integrations.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.detached_integrations.topologySpreadConstraints }}
      topologySpreadConstraints:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.detached_integrations.priorityClassName }}
      priorityClassName: {{ . }}
      {{- end }}
      {{- with .Values.detached_integrations.extraVolumes }}
      volumes: {{- . | toYaml | nindent 8 }}
      {{- end }}
{{- end -}}
