[COMAC-116] Write Accelleran CU Helm chart - SR-IOV enabled

Change-Id: Ica899d80145505a35d7d593e9ca6d22f2d7f24b8
diff --git a/comac-cu/Chart.yaml b/comac-cu/Chart.yaml
new file mode 100644
index 0000000..fa85512
--- /dev/null
+++ b/comac-cu/Chart.yaml
@@ -0,0 +1,21 @@
+---
+# 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.
+
+name: comac-cu
+description: A Helm chart to install CU/BBU in COMAC
+icon: https://guide.opencord.org/logos/cord.svg
+
+version: 0.0.1
+appVersion: 0.0.2
\ No newline at end of file
diff --git a/comac-cu/templates/configmap-accelleran.yaml b/comac-cu/templates/configmap-accelleran.yaml
new file mode 100644
index 0000000..fc1d934
--- /dev/null
+++ b/comac-cu/templates/configmap-accelleran.yaml
@@ -0,0 +1,24 @@
+---
+# 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: l3-config
+data:
+  bootstrap.txt: |
+    redis.hostname:{{ .Values.cu.name }}
+    redis.port:6379
+    instance.filter:{{ .Values.cu.accelleran.instid }}
\ No newline at end of file
diff --git a/comac-cu/templates/networks.yaml b/comac-cu/templates/networks.yaml
new file mode 100644
index 0000000..af46aa5
--- /dev/null
+++ b/comac-cu/templates/networks.yaml
@@ -0,0 +1,39 @@
+---
+# 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: "k8s.cni.cncf.io/v1"
+kind: NetworkAttachmentDefinition
+metadata:
+  name: f1-net-cu
+{{- if $.Values.network.sriov.enabled }}
+  annotations:
+    k8s.v1.cni.cncf.io/resourceName: intel.com/sriov_netdevice
+{{- end }}
+spec:
+  config: '{
+    "type": {{ .Values.network.f1.cni_plugin | quote }},
+    "ipam": {
+        "type": {{ .Values.network.f1.ipam | quote }},
+    {{- if eq .Values.network.f1.ipam "host-local" }}
+        "subnet": {{ .Values.network.f1.subnet | quote }},
+        "gateway": {{ .Values.network.f1.gateway | quote }}
+    {{- else if eq .Values.network.f1.ipam "centralip" }}
+        "ipType": "cluster",
+        "network": {{ .Values.network.f1.subnet | quote }},
+        "etcdURL": {{ .Values.network.etcdurl | quote }}
+    {{- end }}
+    }
+  }'
\ No newline at end of file
diff --git a/comac-cu/templates/service-accelleran.yaml b/comac-cu/templates/service-accelleran.yaml
new file mode 100644
index 0000000..89e0ee8
--- /dev/null
+++ b/comac-cu/templates/service-accelleran.yaml
@@ -0,0 +1,42 @@
+---
+# 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: {{ .Values.cu.name }}
+spec:
+  selector:
+    app: {{ .Values.cu.name }}
+  clusterIP: None
+  ports:
+    - name: s1ap
+      port: {{ .Values.cu.accelleran.ports.s1ap_external }}
+      protocol: SCTP
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Values.cu.name }}-external
+spec:
+  selector:
+    app: {{ .Values.cu.name }}
+  type: NodePort
+  ports:
+    - port: {{ .Values.cu.accelleran.ports.s1ap }}
+      nodePort: {{ .Values.cu.accelleran.ports.s1ap_external }}
+      protocol: SCTP
\ No newline at end of file
diff --git a/comac-cu/templates/statefulset-accelleran.yaml b/comac-cu/templates/statefulset-accelleran.yaml
new file mode 100644
index 0000000..9782d39
--- /dev/null
+++ b/comac-cu/templates/statefulset-accelleran.yaml
@@ -0,0 +1,139 @@
+---
+# 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: apps/v1
+kind: StatefulSet
+metadata:
+  name: {{ .Values.cu.name }}
+  labels:
+    app: {{ .Values.cu.name }}
+spec:
+  replicas: {{ .Values.cu.accelleran.replicas }}
+  selector:
+    matchLabels:
+      app: {{ .Values.cu.name }}
+  serviceName: {{ .Values.cu.name | quote }}
+  template:
+    metadata:
+      labels:
+        app: {{ .Values.cu.name }}
+      annotations:
+        k8s.v1.cni.cncf.io/networks: '[
+          { "name": "f1-net-cu", "interface": "f1-net-cu" }
+        ]'
+
+    spec:
+      nodeSelector:
+{{ toYaml .Values.cu.nodeselector | indent 8 }}
+      initContainers:
+      - name: init-iptables
+        image: {{ .Values.cu.accelleran.images.init }}
+        command: [ "sh", "-c"]
+        args:
+        - iptables -I OUTPUT -p icmp --icmp-type destination-unreachable -j DROP;
+        securityContext:
+          capabilities:
+            add:
+              - NET_ADMIN
+      terminationGracePeriodSeconds: 1
+      containers:
+      - name: nats
+        image: {{ .Values.cu.accelleran.images.nats }}
+        imagePullPolicy: IfNotPresent
+        stdin: true
+        tty: true
+        env:
+        - name: NATS_SERVICE_NAME
+          value: {{ .Values.cu.accelleran.nats.servicename }}
+        command: [ "sh", "-c"]
+        args:
+        - gnatsd -DV -c /etc/gnatsd.conf;
+        resources:
+          limits:
+            cpu: {{ .Values.cu.accelleran.resources.cpu }}
+            memory: {{ .Values.cu.accelleran.resources.mem }}
+{{- if .Values.network.sriov.enabled }}
+            intel.com/sriov_netdevice: '2'
+{{- end }}
+        securityContext:
+          capabilities:
+            add:
+            - NET_ADMIN
+            - IPC_LOCK
+      - name: redis
+        image: {{ .Values.cu.accelleran.images.redis }}
+        imagePullPolicy: IfNotPresent
+        stdin: true
+        tty: true
+        command: ["sh", "-c"]
+        args:
+        # FIXME: Redis can't support with dns resolution, can't set hostname at here.
+        - (sleep 5; redis-cli -h localhost -p 6379 set NATS_SERVICE_URL "nat://$(ip route get 116 | awk '{print $NF;exit}'):4222";) &
+          /usr/local/bin/redis-server
+        resources:
+          limits:
+            cpu: {{ .Values.cu.accelleran.resources.cpu }}
+            memory: {{ .Values.cu.accelleran.resources.mem }}
+{{- if .Values.network.sriov.enabled }}
+            intel.com/sriov_netdevice: '2'
+{{- end }}
+        securityContext:
+          capabilities:
+            add:
+            - NET_ADMIN
+            - IPC_LOCK
+      - name: bbu
+        image: {{ .Values.cu.accelleran.images.bbu }}
+        imagePullPolicy: Always
+        env:
+          - name: MME_IP
+            value: {{ .Values.mme.nodeport_ip_addr }}
+        stdin: true
+        tty: true
+        command: ["sh", "-c"]
+        # Configure BBU SCTP source port to `s1ap_external`, MME endpoint port to `mme_port` and configure BBU to use
+        # Removed ProgRAN-related command - you can see about it in `helm-chart/mcord/mcord-bbu`
+        args:
+        - sqlite3 /mnt/app/datastore.db "update cellS1apConfig set enbSctpPort={{ .Values.cu.accelleran.ports.s1ap }};";
+          sqlite3 /mnt/app/datastoreRemRw.db "update FapServiceFapControlLteGateway set S1SigLinkPort={{ .Values.mme.port }};";
+          sqlite3 /mnt/app/datastore.db "insert into enbSctpSocketInterface ('interfaceName') values ('{{ .Values.enb.socket_interface }}');";
+          sqlite3 /mnt/app/datastore.db "update logging set severity=7 where id=25;";
+          sleep 10;
+          /l3/l3start;
+        volumeMounts:
+        - name: bbu-config
+          mountPath: /mnt/app/bootstrap.txt
+          subPath: bootstrap.txt
+        resources:
+          limits:
+            cpu: {{ .Values.cu.accelleran.resources.cpu }}
+            memory: {{ .Values.cu.accelleran.resources.mem }}
+{{- if .Values.network.sriov.enabled }}
+            intel.com/sriov_netdevice: '2'
+{{- end }}
+        securityContext:
+          capabilities:
+            add:
+            - NET_ADMIN
+            - IPC_LOCK
+            - SYS_NICE
+      volumes:
+        - name: bbu-config
+          configMap:
+            name: l3-config
+            items:
+              - key: bootstrap.txt
+                path: bootstrap.txt
\ No newline at end of file
diff --git a/comac-cu/values.yaml b/comac-cu/values.yaml
new file mode 100644
index 0000000..3092051
--- /dev/null
+++ b/comac-cu/values.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.
+
+mme:
+  nodeport_ip_addr: "10.90.0.152"
+  port: 36412
+
+enb:
+  socket_interface: eth0
+
+cu:
+  location: remote # {remote: MME - same cluster, local: MME - different cluster}
+  name: accelleran
+  type: accelleran
+  nodeselector:
+    sriov: netdevice
+  accelleran:
+    images:
+      init: "ngick8stesting/c3po-mmeinit"
+      nats: "node1:30500/accelleran/vran-nats:20190121"
+      redis: "node1:30500/accelleran/vran-redis:20190121"
+      bbu: "node1:30500/accelleran/vran-l3-fdd:onf-dns"
+    ports:
+      s1ap: 36412
+      s1ap_external: 31412
+    replicas: 1
+    instid: "enb_key"
+    nats:
+      servicename: "nats-cluster"
+    resources:
+      cpu: 3
+      mem: "1Gi"
+
+network:
+  sriov:
+    enabled: true
+  etcdurl: http://node1:32379
+  f1:
+    cni_plugin: sriov
+    ipam: centralip
+    subnet: 116.0.0.0/24
+    gateway: 116.0.0.254