{{- if .Values.enabled.enabled }}
{{- $namespace := .Release.Namespace -}}
{{- $applicationName := .Values.deploy.name -}}

{{- if and .Values.enabled.cluster ( not .Values.enabled.webrtc )}}
{{- /*
开启集群模式的情况
*/}}
---
{{/*
srsog: used to get srs-og stateful-set's ip.
*/}}
apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.apps.srs.service.headless.og }}
  namespace: {{ $namespace }}
spec:
  type: ClusterIP
  clusterIP: None
  selector:
    {{- include "srs.matchLabels.origin" . | nindent 4 }}
  ports:
    - name: srsog-rtmp
      port: {{ .Values.apps.srs.ports.rtmp }}
      targetPort: {{ .Values.apps.srs.ports.rtmp }}
    - name: srsog-hls
      port: {{ .Values.apps.srs.ports.flv }}
      targetPort: {{ .Values.apps.srs.ports.flv }}

---

apiVersion: v1
kind: Service
metadata:
  name: {{ $applicationName }}-origin-svc
  namespace: {{ $namespace }}
spec:
  type: NodePort
  selector:
    {{- include "srs.matchLabels.origin" . | nindent 4 }}
  ports:
    - name: srsog-api
      port: {{ .Values.apps.srs.ports.api }}
      targetPort: {{ .Values.apps.srs.ports.api }}
      nodePort: {{ .Values.apps.srs.ports.api }}
    {{- if lt .Values.apps.srs.replicas.origin 2.0 }}
    - name: srsog-rtc
      port: {{ .Values.apps.srs.ports.rtc }}
      targetPort: {{ .Values.apps.srs.ports.rtc }}
      nodePort: {{ .Values.apps.srs.ports.rtc }}
      protocol: UDP
    {{- end }}

---

apiVersion: v1
kind: Service
metadata:
  name: {{ $applicationName }}-edge-svc
  namespace: {{ $namespace }}
spec:
  type: NodePort
  selector:
  {{- include "srs.matchLabels.edge" . | nindent 4 }}
  ports:
    - name: srseg-rtmp
      port: {{ .Values.apps.srs.ports.rtmp }}
      targetPort: {{ .Values.apps.srs.ports.rtmp }}
      nodePort: {{ .Values.apps.srs.ports.rtmp }}
    - name: srseg-flv
      port: {{ .Values.apps.srs.ports.flv }}
      targetPort: {{ .Values.apps.srs.ports.flv }}
      nodePort: {{ .Values.apps.srs.ports.flv }}

{{- end }}
---
{{- if and  .Values.enabled.webrtc  (not .Values.enabled.cluster) }}
  {{- /*
  默认的模式！ web-rtc
*/}}
---
{{/*
srsrtc: used to get srs-rtc stateful-set's ip.
*/}}
apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.apps.srs.service.headless.rtc }}
  namespace: {{ $namespace }}
spec:
  type: ClusterIP
  clusterIP: None
  selector:
  {{- include "srs.matchLabels.webrtc" . | nindent 4 }}
  ports:
    - name: srsrtc-rtmp
      port: {{ .Values.apps.srs.ports.rtmp }}
      targetPort: {{ .Values.apps.srs.ports.rtmp }}
    - name: srsrtc-hls
      port: {{ .Values.apps.srs.ports.flv }}
      targetPort: {{ .Values.apps.srs.ports.flv }}

---
apiVersion: v1
kind: Service
metadata:
  name: {{ $applicationName }}-rtc-svc
  namespace: {{ $namespace }}
spec:
  type: NodePort
  selector:
  {{- include "srs.matchLabels.webrtc" . | nindent 4 }}
  ports:
    - name: srs-rtmp
      port: {{ .Values.apps.srs.ports.rtmp }}
      targetPort: {{ .Values.apps.srs.ports.rtmp }}
      nodePort: {{ .Values.apps.srs.ports.rtmp }}
    - name: srs-api
      port: {{ .Values.apps.srs.ports.api }}
      targetPort: {{ .Values.apps.srs.ports.api }}
      nodePort: {{ .Values.apps.srs.ports.api }}
    - name: srs-rtc
      port: {{ .Values.apps.srs.ports.rtc }}
      targetPort: {{ .Values.apps.srs.ports.rtc }}
      nodePort: {{ .Values.apps.srs.ports.rtc }}
      protocol: UDP
    - name: srs-flv
      port: {{ .Values.apps.srs.ports.flv }}
      targetPort: {{ .Values.apps.srs.ports.flv }}
      nodePort: {{ .Values.apps.srs.ports.flv }}

{{- end }}

---

apiVersion: v1
kind: Service
metadata:
  name: {{ $applicationName }}-op-svc
  namespace: {{ $namespace }}
spec:
  type: ClusterIP
  selector:
  {{- include "srs.matchLabels.op" . | nindent 4 }}
  ports:
    - port: 8080
      targetPort: 8080

---
{{- end }}