apiVersion: apps/v1
kind: Deployment
metadata:
  name: webrtc-be
  namespace: webrtc-be
  labels:
    app: webrtc-be
    app.kubernetes.io/name: webrtc-be
    app.kubernetes.io/component: backend
spec:
  selector:
    matchLabels:
      app: webrtc-be
  replicas: 1
  template:
    metadata:
     generateName: webrtc-be-
     labels:
      app: webrtc-be
      app.kubernetes.io/name: webrtc-be
      app.kubernetes.io/component: backend
    spec:
      hostNetwork: true
      imagePullSecrets:
        - name: gcr-json-key
      containers:
        - name: webrtc-be
          image: gcr.io/tough-craft-276813/webrtc_be:{{ .Values.webrtc_tag }}
          imagePullPolicy: Always
          #resources:
            #requests:
            #  memory: "3800Mi"
            #  cpu: "1200m"
            #limits:
            #  memory: "3800Mi"
          env:
            - name: RTC_MIN_PORT
              value: "30000"
            - name: RTC_MAX_PORT
              value: "32768"
            - name: BACKEND_URL
              value: {{ .Values.backendUrl }}
            {{ if .Values.auth }}
            - name: RESTRICT_AUTH
              value: "true"
            {{ end }}
            - name: ENABLE_DIE_ENDPOINT
              value: "{{ .Values.enableDieEndpoint }}"
            - name: MEDIASOUP_LISTEN_IP
              value: {{ .Values.mediasoup.listenIp | default "0.0.0.0" | quote }}
            - name: MEDIASOUP_ANNOUNCED_IP
              value: {{ .Values.mediasoup.announcedIp | default "" | quote }}
            - name: MEDIASOUP_USE_NETWORK_INTERFACE_IP
              value: {{ .Values.mediasoup.useNetworkInterfaceIP | default "false" | quote }}
            - name: SESSION_HEALTH_CHECK_INTERVAL
              value: {{ .Values.sessionHealthCheckInterval | default "60000" | quote }}
            - name: SESSION_OVER_GRACE_PERIOD
              value: {{ .Values.sessionOverGracePeriod | default "300000" | quote }}
          ports:
            - name: websocket-port
              containerPort: 5001
          livenessProbe:
            httpGet:
              path: /healthcheck
              port: 5001
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /healthcheck
              port: 5001
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}