package d_app

const CmiiSrsTemplate = `
kind: ConfigMap
apiVersion: v1
metadata:
  name: helm-live-srs-cm
  namespace: {{ .Namespace }}
  labels:
    cmii.app: live-srs
    cmii.type: live
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
    helm.sh/chart: cmlc-live-srs-rtc-2.0.0
data:
  srs.rtc.conf: |-
    listen              {{ .RtmpPort }};
    max_connections     4096;
    srs_log_tank        console;
    srs_log_level       info;
    srs_log_file        /home/srs.log;
    daemon              off;
    http_api {
        enabled         on;
        listen          1985;
        crossdomain     on;
    }
    stats {
        network         0;
    }
    http_server {
        enabled         on;
        listen          8080;
        dir             /home/hls;
    }
    srt_server {
        enabled         on;
        listen          30556;
        maxbw           1000000000;
        connect_timeout 4000;
        peerlatency     600;
        recvlatency     600;
    }
    rtc_server {
        enabled         on;
        listen          {{ .WebRTCPort }};
        candidate       $CANDIDATE;
    }
    vhost __defaultVhost__ {
        http_hooks {
            enabled       on;
            on_publish    http://helm-live-op-svc-v2:8080/hooks/on_push;
        }
        http_remux {
            enabled     on;
        }
        rtc {
            enabled     on;
            rtmp_to_rtc on;
            rtc_to_rtmp on;
            keep_bframe off;
        }
        tcp_nodelay     on;
        min_latency     on;
        play {
            gop_cache       off;
            mw_latency      100;
            mw_msgs         10;
        }
        publish {
            firstpkt_timeout    8000;
            normal_timeout      4000;
            mr on;
        }
        dvr {
            enabled         off;
            dvr_path        /home/dvr/[app]/[stream]/[2006][01]/[timestamp].mp4;
            dvr_plan        session;
        }
        hls {
            enabled          on;
            hls_path         /home/hls;
            hls_fragment     10;
            hls_window       60;
            hls_m3u8_file    [app]/[stream].m3u8;
            hls_ts_file      [app]/[stream]/[2006][01][02]/[timestamp]-[duration].ts;
            hls_cleanup      on;
	        {{- if .WebPort }}
            hls_entry_prefix http://{{ .WebIP }}:{{ .WebPort }};
            {{- else }}
            hls_entry_prefix http://{{ .WebIP }};
            {{- end }}
        }
    }
---
kind: Service
apiVersion: v1
metadata:
  name: helm-live-srs-svc-exporter
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
spec:
  ports:
    - name: rtmp
      protocol: TCP
      port: {{ .RtmpPort }}
      targetPort: {{ .RtmpPort }}
      nodePort: {{ .RtmpPort }}
    - name: rtc
      protocol: UDP
      port: {{ .WebRTCPort }}
      targetPort: {{ .WebRTCPort }}
      nodePort: {{ .WebRTCPort }}
    - name: rtc-tcp
      protocol: TCP
      port: {{ .WebRTCPort }}
      targetPort: {{ .WebRTCPort }}
      nodePort: {{ .WebRTCPort }}
    - name: srt
      protocol: UDP
      port: 30556
      targetPort: 30556
      nodePort: {{ .SrtPort }}
    - name: api
      protocol: TCP
      port: 1985
      targetPort: 1985
      nodePort: {{ .WebApiPort }}
  selector:
    srs-role: rtc
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster

---
kind: Service
apiVersion: v1
metadata:
  name: helm-live-srs-svc
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
spec:
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
    - name: api
      protocol: TCP
      port: 1985
      targetPort: 1985
  selector:
    srs-role: rtc
  type: ClusterIP
  sessionAffinity: None

---
kind: Service
apiVersion: v1
metadata:
  name: helm-live-srsrtc-svc
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
spec:
  ports:
    - name: rtmp
      protocol: TCP
      port: {{ .RtmpPort }}
      targetPort: {{ .RtmpPort }}
  selector:
    srs-role: rtc
  type: ClusterIP
  sessionAffinity: None

---
kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: helm-live-srs-rtc
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
    cmii.app: live-srs
    cmii.type: live
    helm.sh/chart: cmlc-live-srs-rtc-2.0.0
    srs-role: rtc
spec:
  replicas: 1
  selector:
    matchLabels:
      srs-role: rtc
  template:
    metadata:
      labels:
        srs-role: rtc
    spec:
      volumes:
        - name: srs-conf-file
          configMap:
            name: helm-live-srs-cm
            items:
              - key: srs.rtc.conf
                path: docker.conf
            defaultMode: 420
        - name: srs-vol
          emptyDir:
            sizeLimit: 8Gi
      containers:
        - name: srs-rtc
          {{- if .HarborPort }}
          image: {{ .HarborIPOrCustomImagePrefix }}:{{ .HarborPort }}/cmii/srs:v5.0.195
          {{- else }}
          image: {{ .HarborIPOrCustomImagePrefix }}srs:v5.0.195
          {{- end }}
          ports:
            - name: srs-rtmp
              containerPort: {{ .RtmpPort }}
              protocol: TCP
            - name: srs-api
              containerPort: 1985
              protocol: TCP
            - name: srs-flv
              containerPort: 8080
              protocol: TCP
            - name: srs-webrtc
              containerPort: {{ .WebRTCPort }}
              protocol: UDP
            - name: srs-webrtc-tcp
              containerPort: {{ .WebRTCPort }}
              protocol: TCP
            - name: srs-srt
              containerPort: 30556
              protocol: UDP
          env:
            - name: CANDIDATE
              value: {{ .WebIP }}
          resources:
            limits:
              cpu: 2000m
              memory: 4Gi
            requests:
              cpu: 100m
              memory: 256Mi
          volumeMounts:
            - name: srs-conf-file
              mountPath: /usr/local/srs/conf/docker.conf
              subPath: docker.conf
            - name: srs-vol
              mountPath: /home/dvr
              subPath: {{ .Namespace }}/helm-live/dvr
            - name: srs-vol
              mountPath: /home/hls
              subPath: {{ .Namespace }}/helm-live/hls
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
        - name: oss-adaptor
          {{- if .HarborPort }}
          image: {{ .HarborIPOrCustomImagePrefix }}:{{ .HarborPort }}/cmii/cmii-srs-oss-adaptor:2023-SA-skip-CHL
          {{- else }}
          image: {{ .HarborIPOrCustomImagePrefix }}cmii-srs-oss-adaptor:2023-SA-skip-CHL
          {{- end }}
          env:
            - name: OSS_ENDPOINT
              value: 'http://{{ .MinioInnerIP }}:9000'
            - name: OSS_AK
              value: cmii
            - name: OSS_SK
              value: 'B#923fC7mk'
            - name: OSS_BUCKET
              value: live-cluster-hls
            - name: SRS_OP
              value: 'http://helm-live-op-svc-v2:8080'
            - name: MYSQL_ENDPOINT
              value: 'helm-mysql:3306'
            - name: MYSQL_USERNAME
              value: k8s_admin
            - name: MYSQL_PASSWORD
              value: {{ .MySQLK8sAdminPassword }}
            - name: MYSQL_DATABASE
              value: cmii_live_srs_op
            - name: MYSQL_TABLE
              value: live_segment
            - name: LOG_LEVEL
              value: info
            - name: OSS_META
              value: 'yes'
          resources:
            limits:
              cpu: 2000m
              memory: 4Gi
            requests:
              cpu: 100m
              memory: 256Mi
          volumeMounts:
            - name: srs-vol
              mountPath: /cmii/share/hls
              subPath: {{ .Namespace }}/helm-live/hls
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      imagePullSecrets:
        - name: harborsecret
      affinity: {}
      schedulerName: default-scheduler
  serviceName: helm-live-srsrtc-svc
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      partition: 0
  revisionHistoryLimit: 10
---
# live-srs部分
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: helm-live-op-v2
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
    cmii.app: live-engine
    cmii.type: live
    helm.sh/chart: cmlc-live-live-op-2.0.0
    live-role: op-v2
spec:
  replicas: 1
  selector:
    matchLabels:
      live-role: op-v2
  template:
    metadata:
      labels:
        live-role: op-v2
    spec:
      volumes:
        - name: srs-conf-file
          configMap:
            name: helm-live-op-cm-v2
            items:
              - key: live.op.conf
                path: bootstrap.yaml
            defaultMode: 420
      containers:
        - name: helm-live-op-v2
          {{- if .HarborPort }}
          image: {{ .HarborIPOrCustomImagePrefix }}:{{ .HarborPort }}/cmii/cmii-live-operator:5.2.0
          {{- else }}
          image: {{ .HarborIPOrCustomImagePrefix }}cmii-live-operator:5.2.0
          {{- end }}
          ports:
            - name: operator
              containerPort: 8080
              protocol: TCP
          resources:
            limits:
              cpu: 4800m
              memory: 4Gi
            requests:
              cpu: 100m
              memory: 256Mi
          volumeMounts:
            - name: srs-conf-file
              mountPath: /cmii/bootstrap.yaml
              subPath: bootstrap.yaml
          livenessProbe:
            httpGet:
              path: /cmii/health
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 60
            timeoutSeconds: 5
            periodSeconds: 20
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /cmii/health
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 60
            timeoutSeconds: 5
            periodSeconds: 20
            successThreshold: 1
            failureThreshold: 3
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      imagePullSecrets:
        - name: harborsecret
      affinity: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
---
kind: Service
apiVersion: v1
metadata:
  name: helm-live-op-svc-v2
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30333
  selector:
    live-role: op-v2
  type: NodePort
  sessionAffinity: None
---
kind: Service
apiVersion: v1
metadata:
  name: helm-live-op-svc
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  selector:
    live-role: op
  type: ClusterIP
  sessionAffinity: None
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: helm-live-op-cm-v2
  namespace: {{ .Namespace }}
  labels:
    octopus.control: wdd
    app.kubernetes.io/managed-by: octopus
    cmii.app: live-engine
    cmii.type: live
data:
  live.op.conf: |-
    server:
      port: 8080
    spring:
      main:
        allow-bean-definition-overriding: true
        allow-circular-references: true
      application:
        name: cmii-live-operator
      platform:
        info:
          name: cmii-live-operator
          description: cmii-live-operator
          version: {{ .TagVersion }}
          scanPackage: com.cmii.live.op
      cloud:
        nacos:
          config:
            username: nacos
            password: KingKong@95461234
            server-addr: helm-nacos:8848
            extension-configs:
              - data-id: cmii-live-operator.yml
                group: {{ .TagVersion }}
                refresh: true
            shared-configs:
              - data-id: cmii-backend-system.yml
                group: {{ .TagVersion }}
                refresh: true
          discovery:
            enabled: false

    live:
      engine:
        type: srs
        endpoint:  'http://helm-live-srs-svc:1985'
      proto:
        rtmp: 'rtmp://{{ .WebIP }}:{{ .RtmpPort }}'
        rtsp: 'rtsp://{{ .WebIP }}:30554'
        srt: 'srt://{{ .WebIP }}:{{ .SrtPort }}'
        flv: 'http://{{ .WebIP }}:30500'
        hls: 'http://{{ .WebIP }}:30500'
        rtc: 'webrtc://{{ .WebIP }}:30080'
        replay: 'https://{{ .WebIP }}:30333'
      minio:
        endpoint: http://{{ .MinioInnerIP }}:9000
        access-key: cmii
        secret-key: B#923fC7mk
        bucket: live-cluster-hls
`
