Migrate ott-services to member-only

Change-Id: Ia9e849e60143e9394605c5a7ec528486ea86de8e
diff --git a/aether-apps/ott-services/cdn-remote/templates/_helpers.tpl b/aether-apps/ott-services/cdn-remote/templates/_helpers.tpl
new file mode 100644
index 0000000..69921bd
--- /dev/null
+++ b/aether-apps/ott-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.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
+{{- 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/aether-apps/ott-services/cdn-remote/templates/bin/_start-stream.sh.tpl b/aether-apps/ott-services/cdn-remote/templates/bin/_start-stream.sh.tpl
new file mode 100644
index 0000000..2d928b3
--- /dev/null
+++ b/aether-apps/ott-services/cdn-remote/templates/bin/_start-stream.sh.tpl
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# 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.
+
+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/aether-apps/ott-services/cdn-remote/templates/configmap-video-archive.yaml b/aether-apps/ott-services/cdn-remote/templates/configmap-video-archive.yaml
new file mode 100644
index 0000000..29fa3c8
--- /dev/null
+++ b/aether-apps/ott-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 "video-archive" . | 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/aether-apps/ott-services/cdn-remote/templates/service-ant-media.yaml b/aether-apps/ott-services/cdn-remote/templates/service-ant-media.yaml
new file mode 100644
index 0000000..ba31e53
--- /dev/null
+++ b/aether-apps/ott-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/aether-apps/ott-services/cdn-remote/templates/statefulset-ant-media.yaml b/aether-apps/ott-services/cdn-remote/templates/statefulset-ant-media.yaml
new file mode 100644
index 0000000..1e9778a
--- /dev/null
+++ b/aether-apps/ott-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/aether-apps/ott-services/cdn-remote/templates/statefulset-video-archive.yaml b/aether-apps/ott-services/cdn-remote/templates/statefulset-video-archive.yaml
new file mode 100644
index 0000000..2f5460a
--- /dev/null
+++ b/aether-apps/ott-services/cdn-remote/templates/statefulset-video-archive.yaml
@@ -0,0 +1,141 @@
+{{/*
+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:
+{{- if .Values.config.videoArchive.q720p.enabled }}
+      - 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
+{{- end }}
+{{- if .Values.config.videoArchive.q480p.enabled }}
+      - 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
+{{- end }}
+{{- if .Values.config.videoArchive.q360p.enabled }}
+      - 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
+{{- end }}
+      volumes:
+      - name: start-script
+        configMap:
+          name: start-stream
+          defaultMode: 493
\ No newline at end of file