{{- if and .Values.enabled.enabled .Values.enabled.rtsp }}
{{- $namespace := .Release.Namespace -}}

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cmii-rtsp-zlm
  namespace: {{ $namespace }}
  labels:
  {{- include "rtsp.labels.zlm" . | nindent 4 }}
spec:
  replicas: 1
  selector:
    matchLabels:
  {{- include "rtsp.matchLabels.zlm" . | nindent 6 }}
  template:
    metadata:
      labels:
      {{- include "rtsp.labels.zlm" . | nindent 8 }}
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      imagePullSecrets:
        - name: {{ .Values.deploy.harbor.secret }}
      affinity:
      {{- include "rtsp.affinity" . | nindent 8 }}
      containers:
        - name: operator
          image: {{ .Values.apps.rtsp.images.zlm }}
          imagePullPolicy: Always
          command: ["/opt/media/bin/MediaServer"]
          args: ["-s /opt/media/bin/default.pem -c /opt/media/bin/config/config.ini"]
          resources:
            limits:
              memory: 4Gi
              cpu: 4800m
            requests:
              memory: 256Mi
              cpu: 100m
          ports:
            - name: rtsp
              containerPort: 554
              protocol: TCP
            - name: rtp-tcp
              containerPort: 10000
              protocol: TCP
            - name: rtp-udp
              containerPort: 10000
              protocol: UDP
          volumeMounts:
            - name: zlm-conf-file
              subPath: config.ini
              mountPath: /opt/media/bin/config/config.ini
      volumes:
        - name: zlm-conf-file
          configMap:
            name: cmii-rtsp-cm
            items:
              - key: "zlm.conf"
                path: "config.ini"

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cmii-rtsp-op
  namespace: {{ $namespace }}
  labels:
  {{- include "rtsp.labels.zlm" . | nindent 4 }}
spec:
  replicas: 1
  selector:
    matchLabels:
  {{- include "rtsp.matchLabels.op" . | nindent 6 }}
  template:
    metadata:
      labels:
      {{- include "rtsp.labels.op" . | nindent 8 }}
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      imagePullSecrets:
        - name: {{ .Values.deploy.harbor.secret }}
      affinity:
      {{- include "rtsp.affinity" . | nindent 8 }}
      containers:
        - name: operator
          image: {{ .Values.apps.rtsp.images.operator }}
          imagePullPolicy: Always
          command: ["python"]
          args: ["rtsp_engine.py"]
          resources:
            limits:
              memory: 4Gi
              cpu: 4800m
            requests:
              memory: 256Mi
              cpu: 100m
          volumeMounts:
            - name: zlm-conf-file
              subPath: rtsp_engine_config.yml
              mountPath: /workspace/rtsp_engine_config.yml
      volumes:
        - name: zlm-conf-file
          configMap:
            name: cmii-rtsp-cm
            items:
              - key: "op.conf"
                path: "rtsp_engine_config.yml"

---

{{- end }}