Aehter-1255 - Add a new container to push the netcfg to ONOS

- Change the apiversion to v2. (v1 for Helmv2, v2 for Helmv3).

Change-Id: Ia1d4a4662ca55d97196ff63d5874a83b03432e04
diff --git a/apps/dbuf/Chart.yaml b/apps/dbuf/Chart.yaml
index 7483562..77eec5e 100644
--- a/apps/dbuf/Chart.yaml
+++ b/apps/dbuf/Chart.yaml
@@ -18,7 +18,7 @@
 # This is the chart version. This version number should be incremented each time you make changes
 # to the chart and its templates, including the app version.
 # Versions are expected to follow Semantic Versioning (https://semver.org/)
-version: 0.1.3
+version: 0.1.4
 
 # This is the version number of the application being deployed. This version number should be
 # incremented each time you make changes to the application. Versions are not expected to
diff --git a/apps/dbuf/templates/configmap-config.yaml b/apps/dbuf/templates/configmap-config.yaml
new file mode 100644
index 0000000..2df6d11
--- /dev/null
+++ b/apps/dbuf/templates/configmap-config.yaml
@@ -0,0 +1,45 @@
+{{/*
+# Copyright 2021-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "dbuf.fullname" . }}
+  labels:
+    {{- include "dbuf.labels" . | nindent 4 }}
+data:
+  push-onos: |
+    #!/bin/sh
+    set -e -x
+    env
+    ifconfig
+    while true
+    do
+        echo "Get the IP Address from interface $DP_INTERFACE"
+        ifconfig $DP_INTERFACE
+        #IP Address from ifconfig is addr:10.71.126.127, have to cut it off
+        DP_IP=$(ifconfig $DP_INTERFACE | awk '/inet addr:/ {print $2}' | cut -d':' -f2)
+        echo "IP Address is $DP_IP"
+
+        echo "Generate the netcfg json"
+    cat <<EOF > /tmp/netcfg.json
+        {
+          "apps": {
+            "org.omecproject.up4": {
+              "dbuf": {
+                "serviceAddr": "$GRPC_SERVICE_NAME.$NAMESPACE:$GRPC_PORT",
+                "dataplaneAddr": "$DP_IP:$DP_PORT"
+              }
+            }
+          }
+        }
+    EOF
+
+        cat /tmp/netcfg.json
+        curl --fail -sSL --user $ONOS_USERNAME:$ONOS_PASSWORD --noproxy $ONOS_SERVER -X POST -H 'Content-Type:application/json' \
+        http://$ONOS_SERVER:$ONOS_PORT/onos/v1/network/configuration -d@/tmp/netcfg.json
+        sleep 1m
+    done
diff --git a/apps/dbuf/templates/deployment.yaml b/apps/dbuf/templates/deployment.yaml
index d364ece..b820acb 100644
--- a/apps/dbuf/templates/deployment.yaml
+++ b/apps/dbuf/templates/deployment.yaml
@@ -47,6 +47,36 @@
           - name: exporter
             containerPort: 8080
             protocol: {{ .Values.service.stats.protocol }}
+        # Push data plane address to ONOS via netcfgc
+        - name: push-onos
+          image: curlimages/curl:7.75.0
+          imagePullPolicy: IfNotPresent
+          env:
+            - name: NAMESPACE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.namespace
+            - name: ONOS_SERVER
+              value: "{{ .Values.onos.server }}"
+            - name: ONOS_PORT
+              value: "{{ .Values.onos.port }}"
+            - name: ONOS_USERNAME
+              value: "{{ .Values.onos.username }}"
+            - name: ONOS_PASSWORD
+              value: "{{ .Values.onos.password }}"
+            - name: GRPC_SERVICE_NAME
+              value: {{ include "dbuf.fullname" . }}
+            - name: GRPC_PORT
+              value: "{{ .Values.service.grpc.port }}"
+            - name: DP_INTERFACE
+              value: "{{ .Values.dataplane.interface }}"
+            - name: DP_PORT
+              value: "{{ .Values.dataplane.port }}"
+          volumeMounts:
+            - name: onos-push-script
+              mountPath: /tmp/push-onos
+              subPath: push-onos
+          command: ["sh", "-c", "/tmp/push-onos"]
       {{- with .Values.nodeSelector }}
       nodeSelector:
         {{- toYaml . | nindent 8 }}
@@ -59,3 +89,8 @@
       tolerations:
         {{- toYaml . | nindent 8 }}
       {{- end }}
+      volumes:
+        - name: onos-push-script
+          configMap:
+            name: {{ include "dbuf.fullname" . }}
+            defaultMode: 0755
diff --git a/apps/dbuf/values.yaml b/apps/dbuf/values.yaml
index 792f970..0373f03 100644
--- a/apps/dbuf/values.yaml
+++ b/apps/dbuf/values.yaml
@@ -21,7 +21,7 @@
 # Change both in the same time
 multusNetworkName: dbuf-sriov
 podAnnotations:
-  k8s.v1.cni.cncf.io/networks: dbuf-sriov
+  k8s.v1.cni.cncf.io/networks: dbuf-sriov@net0
 
 podSecurityContext: {}
 resources:
@@ -36,6 +36,17 @@
 
 affinity: {}
 
+# onos inforamtion
+onos:
+  server: onos-tost-onos-classic-hs.tost
+  port: 8181
+  username: onos
+  password: rocks
+
+dataplane:
+  port: 2152
+  interface: "net0"
+
 service:
   stats:
     port: 8080