[COMAC-175] CDN-Remote code refactoring
- remove unnecessary values in values.yaml
- use camelcase way
- rename remote-streaming with video-archive
- add dependency on antmedia
- allow CDN-Local to pull all quality videos {360, 480, 720}
- define Roles, RoleBinding, ServicAccount
- Split each POD yaml file into Service, ConfigMap, and StatefulSet
- Remove hard coded values in Service, ConfigMap, and StatefulSet and
locate them to values.yaml
Change-Id: Ifef695d463e77c1208e43be51114181e2b7f6350
diff --git a/cdn-services/cdn-remote/templates/_helpers.tpl b/cdn-services/cdn-remote/templates/_helpers.tpl
new file mode 100644
index 0000000..13c5543
--- /dev/null
+++ b/cdn-services/cdn-remote/templates/_helpers.tpl
@@ -0,0 +1,104 @@
+{{- /*
+Copyright 2019-present Open Networking Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/ -}}
+
+{{/*
+Renders a set of standardised labels
+*/}}
+{{- define "cdn-remote.metadata_labels" -}}
+{{- $application := index . 0 -}}
+{{- $context := index . 1 -}}
+release: {{ $context.Release.Name }}
+app: {{ $application }}
+{{- end -}}
+
+{{/*
+Render the given template.
+*/}}
+{{- define "cdn-remote.template" -}}
+{{- $name := index . 0 -}}
+{{- $context := index . 1 -}}
+{{- $last := base $context.Template.Name }}
+{{- $wtf := $context.Template.Name | replace $last $name -}}
+{{ include $wtf $context }}
+{{- end -}}
+
+{{/*
+Get Domain name
+*/}}
+{{- define "cdn-remote.get_domain" -}}
+{{- $service := index . 0 -}}
+{{- $context := index . 1 -}}
+{{- printf "%s-0.%s.%s.%s" $service $service $context.Release.Namespace "svc.cluster.local" -}}
+{{- end -}}
+
+{{/*
+Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint.
+*/}}
+{{- define "cdn-remote.service_account" -}}
+{{- $saName := index . 0 -}}
+{{- $context := index . 1 -}}
+{{- $saNamespace := $context.Release.Namespace }}
+---
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+ name: {{ $saName }}
+ namespace: {{ $saNamespace }}
+ labels:
+{{ tuple $saName $context | include "cdn-remote.metadata_labels" | indent 4 }}
+---
+apiVersion: rbac.authorization.k8s.io/v1beta1
+kind: RoleBinding
+metadata:
+ name: {{ $saName }}
+ namespace: {{ $saNamespace }}
+ labels:
+{{ tuple $saName $context | include "cdn-remote.metadata_labels" | indent 4 }}
+roleRef:
+ apiGroup: rbac.authorization.k8s.io
+ kind: Role
+ name: {{ $saName }}
+subjects:
+ - kind: ServiceAccount
+ name: {{ $saName }}
+ namespace: {{ $saNamespace }}
+---
+apiVersion: rbac.authorization.k8s.io/v1beta1
+kind: Role
+metadata:
+ name: {{ $saName }}
+ namespace: {{ $saNamespace }}
+ labels:
+{{ tuple $saName $context | include "cdn-remote.metadata_labels" | indent 4 }}
+rules:
+ - apiGroups:
+ - ""
+ - extensions
+ - batch
+ - apps
+ verbs:
+ - get
+ - list
+ - patch
+ resources:
+ - statefulsets
+ - daemonsets
+ - jobs
+ - pods
+ - services
+ - endpoints
+ - configmaps
+{{- end -}}
\ No newline at end of file
diff --git a/cdn-services/cdn-remote/templates/ant-media.yaml b/cdn-services/cdn-remote/templates/ant-media.yaml
deleted file mode 100644
index c3d4a61..0000000
--- a/cdn-services/cdn-remote/templates/ant-media.yaml
+++ /dev/null
@@ -1,71 +0,0 @@
----
-# Copyright 2019-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
----
-apiVersion: v1
-kind: Service
-metadata:
- name: antmedia
-spec:
- selector:
- app: antmedia
- type: NodePort
- ports:
- - name: httpui
- port: {{ .Values.antmedia.ports.httpui }}
- nodePort: {{ .Values.antmedia.ports.httpui_np }}
- protocol: TCP
- - name: rtmp
- port: {{ .Values.antmedia.ports.rtmp }}
- nodePort: {{ .Values.antmedia.ports.rtmp_np }}
- protocol: TCP
-
----
-apiVersion: apps/v1
-kind: StatefulSet
-metadata:
- name: antmedia
- labels:
- name: antmedia
- app: antmedia
-spec:
- replicas: {{ .Values.antmedia.replicas }}
- selector:
- matchLabels:
- app: antmedia
- serviceName: "antmedia"
- template:
- metadata:
- labels:
- app: antmedia
- name: antmedia
- spec:
- terminationGracePeriodSeconds: 1
- containers:
- - name: antmedia
- image: {{ .Values.antmedia.images.antmedia_image }}
- imagePullPolicy: IfNotPresent
- ports:
- - containerPort: {{ .Values.antmedia.ports.httpui }}
- - containerPort: {{ .Values.antmedia.ports.rtmp }}
- stdin: true
- tty: true
- command: [ "bash", "-xc"]
- args:
- - cd /usr/local/antmedia && ./start.sh | tee /opt/start.log
- resources:
- limits:
- cpu: {{ .Values.antmedia.resources.cpu }}
- memory: {{ .Values.antmedia.resources.mem }}
\ No newline at end of file
diff --git a/cdn-services/cdn-remote/templates/cm.yaml b/cdn-services/cdn-remote/templates/bin/_start-stream.sh.tpl
similarity index 63%
rename from cdn-services/cdn-remote/templates/cm.yaml
rename to cdn-services/cdn-remote/templates/bin/_start-stream.sh.tpl
index 6b419c5..2d928b3 100644
--- a/cdn-services/cdn-remote/templates/cm.yaml
+++ b/cdn-services/cdn-remote/templates/bin/_start-stream.sh.tpl
@@ -1,4 +1,5 @@
----
+#!/bin/bash
+#
# Copyright 2019-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,12 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
----
-apiVersion: v1
-kind: ConfigMap
-metadata:
- name: start-remote-stream
-data:
- start-remote-stream.sh: |+
- #!/bin/bash
- while true; do ffmpeg -re -i /opt/cdn/movies/{{ .Values.remote_streaming.video_quality }}.mp4 -c copy -f flv rtmp://{{ .Values.remote_streaming.antmedia_ip }}:30935/LiveApp/{{ .Values.stream_name }}; done
\ No newline at end of file
+QUALITY=$1
+
+while true; do
+ ffmpeg -re -i /opt/cdn/movies/$QUALITY.mp4 -c copy -f flv rtmp://{{ tuple "ant-media" . | include "cdn-remote.get_domain" }}:1935/LiveApp/$QUALITY;
+done
\ No newline at end of file
diff --git a/cdn-services/cdn-remote/templates/configmap-video-archive.yaml b/cdn-services/cdn-remote/templates/configmap-video-archive.yaml
new file mode 100644
index 0000000..ce73787
--- /dev/null
+++ b/cdn-services/cdn-remote/templates/configmap-video-archive.yaml
@@ -0,0 +1,26 @@
+{{/*
+Copyright 2019-present Open Networking Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/}}
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: start-stream
+ labels:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 4 }}
+data:
+ start-stream.sh: |
+{{ tuple "bin/_start-stream.sh.tpl" . | include "cdn-remote.template" | indent 4 }}
diff --git a/cdn-services/cdn-remote/templates/remote-streamer.yaml b/cdn-services/cdn-remote/templates/remote-streamer.yaml
deleted file mode 100644
index 8fd2574..0000000
--- a/cdn-services/cdn-remote/templates/remote-streamer.yaml
+++ /dev/null
@@ -1,78 +0,0 @@
----
-# Copyright 2019-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
----
-apiVersion: v1
-kind: Service
-metadata:
- name: remote-streaming
-spec:
- selector:
- app: remote-streaming
- type: NodePort
- ports:
- - name: vlc
- port: {{ .Values.remote_streaming.ports.vlc }}
- nodePort: {{ .Values.remote_streaming.ports.vlc_np }}
- protocol: TCP
- - name: http
- port: {{ .Values.remote_streaming.ports.http }}
- nodePort: {{ .Values.remote_streaming.ports.http_np }}
- protocol: TCP
-
----
-apiVersion: apps/v1beta1
-kind: StatefulSet
-metadata:
- name: remote-streaming
-spec:
- replicas: {{ .Values.remote_streaming.replicas }}
- selector:
- matchLabels:
- app: remote-streaming
- serviceName: "remote-streaming"
- template:
- metadata:
- labels:
- app: remote-streaming
- name: remote-streaming
- spec:
- terminationGracePeriodSeconds: 1
- containers:
- - name: streaming
- image: {{ .Values.remote_streaming.images.remote_streaming_image }}
- imagePullPolicy: IfNotPresent
- ports:
- - containerPort: {{ .Values.remote_streaming.ports.vlc }}
- - containerPort: {{ .Values.remote_streaming.ports.http }}
- stdin: true
- tty: true
- command: [ "bash", "-xc"]
- args:
- - sed -i 's/geteuid/getppid/' /usr/bin/vlc;
- /opt/start-remote-stream.sh
- resources:
- limits:
- cpu: {{ .Values.remote_streaming.resources.cpu }}
- memory: {{ .Values.remote_streaming.resources.mem }}
- volumeMounts:
- - name: start-script
- mountPath: /opt/start-remote-stream.sh
- subPath: start-remote-stream.sh
- volumes:
- - name: start-script
- configMap:
- name: start-remote-stream
- defaultMode: 493
\ No newline at end of file
diff --git a/cdn-services/cdn-remote/templates/service-ant-media.yaml b/cdn-services/cdn-remote/templates/service-ant-media.yaml
new file mode 100644
index 0000000..ba31e53
--- /dev/null
+++ b/cdn-services/cdn-remote/templates/service-ant-media.yaml
@@ -0,0 +1,54 @@
+{{/*
+Copyright 2019-present Open Networking Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/}}
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: ant-media
+ labels:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 4 }}
+spec:
+ selector:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 4 }}
+ ports:
+ - name: httpui
+ port: {{ .Values.config.antMedia.ports.httpui }}
+ protocol: TCP
+ - name: rtmp
+ port: {{ .Values.config.antMedia.ports.rtmp }}
+ protocol: TCP
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: ant-media-external
+ labels:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 4 }}
+spec:
+ selector:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 4 }}
+ type: NodePort
+ ports:
+ - name: httpui
+ port: {{ .Values.config.antMedia.ports.httpui }}
+ protocol: TCP
+ nodePort: {{ .Values.config.antMedia.ports.nodePorts.httpui }}
+ - name: rtmp
+ port: {{ .Values.config.antMedia.ports.rtmp }}
+ protocol: TCP
+ nodePort: {{ .Values.config.antMedia.ports.nodePorts.rtmp }}
diff --git a/cdn-services/cdn-remote/templates/statefulset-ant-media.yaml b/cdn-services/cdn-remote/templates/statefulset-ant-media.yaml
new file mode 100644
index 0000000..1e9778a
--- /dev/null
+++ b/cdn-services/cdn-remote/templates/statefulset-ant-media.yaml
@@ -0,0 +1,57 @@
+{{/*
+Copyright 2019-present Open Networking Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/}}
+
+{{ tuple "ant-media" . | include "cdn-remote.service_account" }}
+---
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+ name: ant-media
+ labels:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 4 }}
+spec:
+ replicas: {{ .Values.config.antMedia.replicas }}
+ selector:
+ matchLabels:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 6 }}
+ serviceName: "ant-media"
+ template:
+ metadata:
+ labels:
+{{ tuple "ant-media" . | include "cdn-remote.metadata_labels" | indent 8 }}
+ spec:
+ {{- if .Values.nodeSelectors.enabled }}
+ nodeSelector:
+ {{ .Values.nodeSelectors.antMedia.label }}: {{ .Values.nodeSelectors.antMedia.value }}
+ {{- end }}
+ serviceAccountName: ant-media
+ containers:
+ - name: ant-media
+ image: {{ .Values.images.tags.antMedia | quote }}
+ imagePullPolicy: {{ .Values.images.pullPolicy }}
+ securityContext:
+ allowPrivilegeEscalation: false
+ readOnlyRootFilesystem: false
+ runAsUser: 0
+ stdin: true
+ tty: true
+ command: [ "bash", "-xc"]
+ args:
+ - cd /usr/local/antmedia && ./start.sh | tee /opt/start.log
+ {{- if .Values.resources.enabled }}
+ resources:
+{{ toYaml .Values.resources.antMedia | indent 10 }}
+ {{- end }}
\ No newline at end of file
diff --git a/cdn-services/cdn-remote/templates/statefulset-video-archive.yaml b/cdn-services/cdn-remote/templates/statefulset-video-archive.yaml
new file mode 100644
index 0000000..4f515d1
--- /dev/null
+++ b/cdn-services/cdn-remote/templates/statefulset-video-archive.yaml
@@ -0,0 +1,135 @@
+{{/*
+Copyright 2019-present Open Networking Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/}}
+
+{{ tuple "video-archive" . | include "cdn-remote.service_account" }}
+---
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+ name: video-archive
+ labels:
+{{ tuple "video-archive" . | include "cdn-remote.metadata_labels" | indent 4 }}
+spec:
+ replicas: {{ .Values.config.videoArchive.replicas }}
+ selector:
+ matchLabels:
+{{ tuple "video-archive" . | include "cdn-remote.metadata_labels" | indent 6 }}
+ serviceName: "video-archive"
+ template:
+ metadata:
+ labels:
+{{ tuple "video-archive" . | include "cdn-remote.metadata_labels" | indent 8 }}
+ spec:
+ {{- if .Values.nodeSelectors.enabled }}
+ nodeSelector:
+ {{ .Values.nodeSelectors.videoArchive.label }}: {{ .Values.nodeSelectors.videoArchive.value }}
+ {{- end }}
+ serviceAccountName: video-archive
+ initContainers:
+ - name: video-archive-dep-check
+ image: {{ .Values.images.tags.depCheck | quote }}
+ imagePullPolicy: {{ .Values.images.pullPolicy }}
+ securityContext:
+ allowPrivilegeEscalation: false
+ readOnlyRootFilesystem: false
+ runAsUser: 0
+ env:
+ - name: POD_NAME
+ valueFrom:
+ fieldRef:
+ apiVersion: v1
+ fieldPath: metadata.name
+ - name: NAMESPACE
+ valueFrom:
+ fieldRef:
+ apiVersion: v1
+ fieldPath: metadata.namespace
+ - name: PATH
+ value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/
+ - name: COMMAND
+ value: "echo done"
+ - name: DEPENDENCY_POD_JSON
+ value: '[{"labels": {"app": "ant-media"}, "requireSameNode": false}]'
+ command:
+ - kubernetes-entrypoint
+ volumeMounts:
+ []
+ containers:
+ - name: streaming-720
+ image: {{ .Values.images.tags.videoArchive | quote }}
+ imagePullPolicy: {{ .Values.images.pullPolicy }}
+ securityContext:
+ allowPrivilegeEscalation: false
+ readOnlyRootFilesystem: false
+ runAsUser: 0
+ stdin: true
+ tty: true
+ command: [ "bash", "-xc"]
+ args:
+ - /opt/start-stream.sh 720
+ {{- if .Values.resources.enabled }}
+ resources:
+{{ toYaml .Values.resources.videoArchive | indent 10 }}
+ {{- end }}
+ volumeMounts:
+ - name: start-script
+ mountPath: /opt/start-stream.sh
+ subPath: start-stream.sh
+ - name: streaming-480
+ image: {{ .Values.images.tags.videoArchive | quote }}
+ imagePullPolicy: {{ .Values.images.pullPolicy }}
+ securityContext:
+ allowPrivilegeEscalation: false
+ readOnlyRootFilesystem: false
+ runAsUser: 0
+ stdin: true
+ tty: true
+ command: [ "bash", "-xc"]
+ args:
+ - /opt/start-stream.sh 480
+ {{- if .Values.resources.enabled }}
+ resources:
+{{ toYaml .Values.resources.videoArchive | indent 10 }}
+ {{- end }}
+ volumeMounts:
+ - name: start-script
+ mountPath: /opt/start-stream.sh
+ subPath: start-stream.sh
+ - name: streaming-360
+ image: {{ .Values.images.tags.videoArchive | quote }}
+ imagePullPolicy: {{ .Values.images.pullPolicy }}
+ securityContext:
+ allowPrivilegeEscalation: false
+ readOnlyRootFilesystem: false
+ runAsUser: 0
+ stdin: true
+ tty: true
+ command: [ "bash", "-xc"]
+ args:
+ - /opt/start-stream.sh 360
+ {{- if .Values.resources.enabled }}
+ resources:
+{{ toYaml .Values.resources.videoArchive | indent 10 }}
+ {{- end }}
+ volumeMounts:
+ - name: start-script
+ mountPath: /opt/start-stream.sh
+ subPath: start-stream.sh
+ volumes:
+ - name: start-script
+ configMap:
+ name: start-stream
+ defaultMode: 493
\ No newline at end of file