{{ include "common.deployment.common_config" . | nindent 0 }}
spec: {{ include "common.deployment.common_spec" . | nindent 2 }}
  template: {{ include "common.deployment.pod.metadata" . | nindent 4 }}
    spec:
    {{- if .Values.hostNetwork }}
      hostNetwork: {{ .Values.hostNetwork }}
      dnsPolicy: ClusterFirstWithHostNet
    {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          {{ include "common.containers.imageConfig" .Values.image | nindent 10 }}
          {{ include "common.containers.gpuConfiguration" .Values | nindent 10 }}
          volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }}
            - name: plex-probe-check
              mountPath: /bin/plex_probe_check.sh
              readOnly: true
              subPath: entrypoint.sh
          ports:
          - name: pms
            protocol: TCP
            containerPort: 32400
          {{- if .Values.hostNetwork }}
            hostPort: {{ .Values.plexServiceTCP.port }}
          {{- end }}
          - name: plex-dlna
            protocol: TCP
            containerPort: 32469
          - name: plex-dlna-udp
            protocol: UDP
            containerPort: 1900
          - name: plex-gdm1
            protocol: UDP
            containerPort: 32410
          - name: plex-gdm2
            protocol: UDP
            containerPort: 32412
          - name: plex-gdm3
            protocol: UDP
            containerPort: 32413
          - name: plex-gdm4
            protocol: UDP
            containerPort: 32414
          env:
            - name: KUBE_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            {{ $envList := (default list .Values.environmentVariables) }}
            {{ if and .Values.gpuConfiguration (hasKey .Values.gpuConfiguration "nvidia.com/gpu") (gt (get .Values.gpuConfiguration "nvidia.com/gpu" | toDecimal) 0) }}
            {{ $envList = mustAppend $envList (dict "name" "NVIDIA_DRIVER_CAPABILITIES" "value" "all") }}
            {{ end }}
            {{ $envList = mustAppend $envList (dict "name" "TZ" "value" .Values.timezone) }}
            {{ $envList = mustAppend $envList (dict "name" "PLEX_CLAIM" "value" .Values.claimToken) }}
            {{ $envList = mustAppend $envList (dict "name" "PMS_INTERNAL_ADDRESS" "value" (printf "http://%s:32400" (include "common.names.fullname" .))) }}
            {{ $envList = mustAppend $envList (dict "name" "PMS_IMAGE" "value" (printf "%s:%s" .Values.image.repository .Values.image.tag))}}
            {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }}
          readinessProbe:
            exec:
              command:
                - /bin/plex_probe_check.sh
            failureThreshold: 5
            periodSeconds: 15
          livenessProbe:
            exec:
              command:
                - /bin/plex_probe_check.sh
            failureThreshold: 5
            periodSeconds: 15
          startupProbe:
            exec:
              command:
                - /bin/plex_probe_check.sh
            initialDelaySeconds: 5
            failureThreshold: 40
            periodSeconds: 15
      volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
        - name: plex-probe-check
          configMap:
            defaultMode: 0700
            name: "plex-probe-check"
