Test cases for resolving the helm templates 61/105061/5
authorRajamohan Raj <rajamohan.raj@intel.com>
Fri, 3 Apr 2020 07:43:11 +0000 (07:43 +0000)
committerRitu Sood <Ritu.Sood@intel.com>
Mon, 13 Apr 2020 16:46:10 +0000 (16:46 +0000)
Added test cases for overriding values and
resolving the helm charts.
Also addressed the merge conflicts
and review comments

Issue-ID: MULTICLOUD-1041
Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com>
Change-Id: I511e8e2e71c60e878df434370fc053f09cda1f66

42 files changed:
kud/tests/plugin_collection_v2.sh
kud/tests/vnfs/comp-app/collection/app1/profile/override_values.yaml
kud/tests/vnfs/comp-app/collection/app2/helm/prometheus/templates/service.yaml
kud/tests/vnfs/comp-app/collection/app2/helm/prometheus/values.yaml
kud/tests/vnfs/comp-app/collection/app2/profile/override_values.yaml
src/k8splugin/go.mod
src/k8splugin/internal/rb/profile.go
src/orchestrator/api/instantiation_handler.go
src/orchestrator/mock_files/mock_charts/testchart1/Chart.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/Chart.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/templates/service.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/values.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/Chart.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/templates/service.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/values.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/templates/NOTES.txt [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/templates/service.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart1/values.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/Chart.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/Chart.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/templates/service.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/values.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/Chart.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/templates/service.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/values.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/delete.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/templates/NOTES.txt [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/templates/service.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_charts/testchart2/values.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_profiles/profile1/faulty-dest-manifest.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_profiles/profile1/faulty-manifest.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_profiles/profile1/faulty-src-manifest.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_profiles/profile1/manifest.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_profiles/profile1/override_values.yaml [new file with mode: 0644]
src/orchestrator/mock_files/mock_profiles/profile1/subdir/p1.yaml [new file with mode: 0644]
src/orchestrator/pkg/module/instantiation.go
src/orchestrator/pkg/rtcontext/rtcontext_test.go
src/orchestrator/utils/helm/helm.go
src/orchestrator/utils/helm/helm_test.go [new file with mode: 0644]
src/orchestrator/utils/helm/profile_yaml.go [moved from src/orchestrator/utils/profile_yaml.go with 99% similarity]
src/orchestrator/utils/types/types.go [deleted file]
src/orchestrator/utils/utils.go [moved from src/orchestrator/utils/util-functions.go with 100% similarity]

index 5af4c00..ffa366f 100755 (executable)
@@ -351,14 +351,14 @@ payload="$(cat <<EOF
             "app-name":"${app1_name}",
             "values":
                {
-                  "collectd_prometheus.service.name":"collectd-override-by-set-value"
+                  "collectd_prometheus.service.targetPort":"9104"
                }
          },
          {
             "app-name":"${app2_name}",
             "values":
                {
-                  "service.name":"Prometheus-override-by-set-value"
+                  "prometheus.service.nameOfPort":"WebPort9090"
                }
          }
       ]
index 3a99b73..b3c3680 100644 (file)
@@ -1,8 +1,7 @@
 collectd_prometheus:
   service:
     type: ClusterIP
-    name: collectd-override-by-file
-    port: 9103
+    port: 9104
     targetPort: 9103
     selector:
       app: collectd
index 0114ed2..56fbb5f 100644 (file)
@@ -26,12 +26,12 @@ spec:
   {{- end }}
 {{- end }}
   ports:
-  - name: web
+  - name: {{ .Values.prometheus.service.nameOfPort }}
     {{- if eq .Values.prometheus.service.type "NodePort" }}
     nodePort: {{ .Values.global.nodePortPrefix }}{{ .Values.prometheus.service.nodePort }}
     {{- end }}
     port: 9090
-    targetPort: web
+    targetPort: {{ .Values.prometheus.service.nameOfPort }}
   selector:
     app: prometheus
     prometheus: {{ template "prometheus.fullname" . }}-prometheus
index 19bf047..fa52890 100644 (file)
@@ -40,8 +40,8 @@ prometheus:
 
   resources: {}
   service:
+    nameOfPort: web
     type: ClusterIP
-    name: Prometheus-value-file
     annotations: {}
     labels: {}
     clusterIP: ""
index ec55166..041fc40 100644 (file)
@@ -1,6 +1,6 @@
 service:
     type: ClusterIP
-    name: Prometheus-override-by-file
+    nameOfPort: webPort
     annotations: {}
     labels: {}
     clusterIP: ""
\ No newline at end of file
index d26de6e..f924828 100644 (file)
@@ -108,5 +108,3 @@ replace (
        k8s.io/client-go => k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
        k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20190409023720-1bc0c81fa51d
 )
-
-go 1.13
index d81e857..6efa23b 100644 (file)
@@ -25,6 +25,7 @@ import (
 
        "github.com/onap/multicloud-k8s/src/k8splugin/internal/db"
        "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm"
+
        pkgerrors "github.com/pkg/errors"
 )
 
index d9da218..c95785f 100644 (file)
@@ -29,23 +29,6 @@ type instantiationHandler struct {
        client moduleLib.InstantiationManager
 }
 
-// func (h instantiationHandler) approveInstantiationHandler(w http.ResponseWriter, r *http.Request) {
-
-//     vars := mux.Vars(r)
-//     p := vars["project-name"]
-//     ca := vars["composite-app-name"]
-//     v := vars["composite-app-version"]
-//     di := vars["deployment-intent-group-name"]
-
-//     instantiateErr := h.client.ApproveInstantiation(p, ca, v, di)
-//     if instantiateErr != nil {
-//             http.Error(w, instantiateErr.Error(), http.StatusInternalServerError)
-//             return
-//     }
-
-//     w.WriteHeader(http.StatusCreated)
-// }
-
 func (h instantiationHandler) instantiateHandler(w http.ResponseWriter, r *http.Request) {
 
        vars := mux.Vars(r)
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/Chart.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/Chart.yaml
new file mode 100644 (file)
index 0000000..91a641b
--- /dev/null
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: testchart1
+version: 0.1.0
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/Chart.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/Chart.yaml
new file mode 100644 (file)
index 0000000..be3edce
--- /dev/null
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: subcharta
+version: 0.1.0
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/templates/service.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/templates/service.yaml
new file mode 100644 (file)
index 0000000..fdf75aa
--- /dev/null
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Chart.Name }}
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+  - port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
+    protocol: TCP
+    name: {{ .Values.service.name }}
+  selector:
+    app: {{ .Chart.Name }}
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/values.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/charts/subcharta/values.yaml
new file mode 100644 (file)
index 0000000..f0381ae
--- /dev/null
@@ -0,0 +1,17 @@
+# Default values for subchart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+# subchartA
+service:
+  name: apache
+  type: ClusterIP
+  externalPort: 80
+  internalPort: 80
+SCAdata:
+  SCAbool: false
+  SCAfloat: 3.1
+  SCAint: 55
+  SCAstring: "jabba"
+  SCAnested1:
+    SCAnested2: true
+
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/Chart.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/Chart.yaml
new file mode 100644 (file)
index 0000000..c3c6bba
--- /dev/null
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: subchartb
+version: 0.1.0
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/templates/service.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/templates/service.yaml
new file mode 100644 (file)
index 0000000..fdf75aa
--- /dev/null
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Chart.Name }}
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+  - port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
+    protocol: TCP
+    name: {{ .Values.service.name }}
+  selector:
+    app: {{ .Chart.Name }}
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/values.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/charts/subchartb/values.yaml
new file mode 100644 (file)
index 0000000..774fdd7
--- /dev/null
@@ -0,0 +1,35 @@
+# Default values for subchart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+service:
+  name: nginx
+  type: ClusterIP
+  externalPort: 80
+  internalPort: 80
+
+SCBdata:
+  SCBbool: true
+  SCBfloat: 7.77
+  SCBint: 33
+  SCBstring: "boba"
+
+exports:
+  SCBexported1:
+    SCBexported1A:
+      SCBexported1B: 1965
+
+  SCBexported2:
+    SCBexported2A: "blaster"
+
+global:
+  kolla:
+    nova:
+      api:
+        all:
+          port: 8774
+      metadata:
+        all:
+          port: 8775
+
+
+
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/templates/NOTES.txt b/src/orchestrator/mock_files/mock_charts/testchart1/templates/NOTES.txt
new file mode 100644 (file)
index 0000000..4bdf443
--- /dev/null
@@ -0,0 +1 @@
+Sample notes for {{ .Chart.Name }}
\ No newline at end of file
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/templates/service.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/templates/service.yaml
new file mode 100644 (file)
index 0000000..e06d19b
--- /dev/null
@@ -0,0 +1,22 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Chart.Name }}
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+    namespace: "{{ .Release.Namespace }}"
+    release-name: "{{ .Release.Name }}"
+    release-is-upgrade: "{{ .Release.IsUpgrade }}"
+    release-is-install: "{{ .Release.IsInstall }}"
+    kube-version/major: "{{ .Capabilities.KubeVersion.Major }}"
+    kube-version/minor: "{{ .Capabilities.KubeVersion.Minor }}"
+    kube-version/gitversion: "v{{ .Capabilities.KubeVersion.Major }}.{{ .Capabilities.KubeVersion.Minor }}.0"
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+  - port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
+    protocol: TCP
+    name: {{ .Values.service.name }}
+  selector:
+    app: {{ .Chart.Name }}
diff --git a/src/orchestrator/mock_files/mock_charts/testchart1/values.yaml b/src/orchestrator/mock_files/mock_charts/testchart1/values.yaml
new file mode 100644 (file)
index 0000000..72d3fa5
--- /dev/null
@@ -0,0 +1,55 @@
+# Default values for subchart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+# subchart1
+service:
+  name: nginx
+  type: ClusterIP
+  externalPort: 80
+  internalPort: 80
+
+
+SC1data:
+  SC1bool: true
+  SC1float: 3.14
+  SC1int: 100
+  SC1string: "dollywood"
+  SC1extra1: 11
+
+imported-chartA:
+  SC1extra2: 1.337
+
+overridden-chartA:
+  SCAbool: true
+  SCAfloat: 3.14
+  SCAint: 100
+  SCAstring: "jabathehut"
+  SC1extra3: true
+
+imported-chartA-B:
+  SC1extra5: "tiller"
+
+overridden-chartA-B:
+  SCAbool: true
+  SCAfloat: 3.33
+  SCAint: 555
+  SCAstring: "wormwood"
+  SCAextra1: 23
+
+  SCBbool: true
+  SCBfloat: 0.25
+  SCBint: 98
+  SCBstring: "murkwood"
+  SCBextra1: 13
+
+  SC1extra6: 77
+
+SCBexported1A:
+  SC1extra7: true
+
+exports:
+  SC1exported1:
+    global:
+      SC1exported2:
+        all:
+          SC1exported3: "SC1expstr"
\ No newline at end of file
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/Chart.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/Chart.yaml
new file mode 100644 (file)
index 0000000..f2818e5
--- /dev/null
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: testchart2
+version: 0.1.0
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/Chart.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/Chart.yaml
new file mode 100644 (file)
index 0000000..be3edce
--- /dev/null
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: subcharta
+version: 0.1.0
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/templates/service.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/templates/service.yaml
new file mode 100644 (file)
index 0000000..fdf75aa
--- /dev/null
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Chart.Name }}
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+  - port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
+    protocol: TCP
+    name: {{ .Values.service.name }}
+  selector:
+    app: {{ .Chart.Name }}
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/values.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/charts/subcharta/values.yaml
new file mode 100644 (file)
index 0000000..f0381ae
--- /dev/null
@@ -0,0 +1,17 @@
+# Default values for subchart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+# subchartA
+service:
+  name: apache
+  type: ClusterIP
+  externalPort: 80
+  internalPort: 80
+SCAdata:
+  SCAbool: false
+  SCAfloat: 3.1
+  SCAint: 55
+  SCAstring: "jabba"
+  SCAnested1:
+    SCAnested2: true
+
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/Chart.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/Chart.yaml
new file mode 100644 (file)
index 0000000..c3c6bba
--- /dev/null
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: subchartb
+version: 0.1.0
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/templates/service.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/templates/service.yaml
new file mode 100644 (file)
index 0000000..fdf75aa
--- /dev/null
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Chart.Name }}
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+  - port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
+    protocol: TCP
+    name: {{ .Values.service.name }}
+  selector:
+    app: {{ .Chart.Name }}
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/values.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/charts/subchartb/values.yaml
new file mode 100644 (file)
index 0000000..774fdd7
--- /dev/null
@@ -0,0 +1,35 @@
+# Default values for subchart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+service:
+  name: nginx
+  type: ClusterIP
+  externalPort: 80
+  internalPort: 80
+
+SCBdata:
+  SCBbool: true
+  SCBfloat: 7.77
+  SCBint: 33
+  SCBstring: "boba"
+
+exports:
+  SCBexported1:
+    SCBexported1A:
+      SCBexported1B: 1965
+
+  SCBexported2:
+    SCBexported2A: "blaster"
+
+global:
+  kolla:
+    nova:
+      api:
+        all:
+          port: 8774
+      metadata:
+        all:
+          port: 8775
+
+
+
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/delete.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/delete.yaml
new file mode 100644 (file)
index 0000000..70efc67
--- /dev/null
@@ -0,0 +1,22 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: testchart2
+  labels:
+    chart: "testchart2-0.1.0"
+    namespace: "testnamespace"
+    release-name: "testreleasename"
+    release-is-upgrade: "false"
+    release-is-install: "true"
+    kube-version/major: "1"
+    kube-version/minor: "14"
+    kube-version/gitversion: "v1.14.0"
+spec:
+  type: ClusterIP
+  ports:
+  - port: 80
+    targetPort: 80
+    protocol: TCP
+    name: nginx
+  selector:
+    app: testchart2
\ No newline at end of file
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/templates/NOTES.txt b/src/orchestrator/mock_files/mock_charts/testchart2/templates/NOTES.txt
new file mode 100644 (file)
index 0000000..4bdf443
--- /dev/null
@@ -0,0 +1 @@
+Sample notes for {{ .Chart.Name }}
\ No newline at end of file
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/templates/service.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/templates/service.yaml
new file mode 100644 (file)
index 0000000..e06d19b
--- /dev/null
@@ -0,0 +1,22 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Chart.Name }}
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+    namespace: "{{ .Release.Namespace }}"
+    release-name: "{{ .Release.Name }}"
+    release-is-upgrade: "{{ .Release.IsUpgrade }}"
+    release-is-install: "{{ .Release.IsInstall }}"
+    kube-version/major: "{{ .Capabilities.KubeVersion.Major }}"
+    kube-version/minor: "{{ .Capabilities.KubeVersion.Minor }}"
+    kube-version/gitversion: "v{{ .Capabilities.KubeVersion.Major }}.{{ .Capabilities.KubeVersion.Minor }}.0"
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+  - port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
+    protocol: TCP
+    name: {{ .Values.service.name }}
+  selector:
+    app: {{ .Chart.Name }}
diff --git a/src/orchestrator/mock_files/mock_charts/testchart2/values.yaml b/src/orchestrator/mock_files/mock_charts/testchart2/values.yaml
new file mode 100644 (file)
index 0000000..72d3fa5
--- /dev/null
@@ -0,0 +1,55 @@
+# Default values for subchart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+# subchart1
+service:
+  name: nginx
+  type: ClusterIP
+  externalPort: 80
+  internalPort: 80
+
+
+SC1data:
+  SC1bool: true
+  SC1float: 3.14
+  SC1int: 100
+  SC1string: "dollywood"
+  SC1extra1: 11
+
+imported-chartA:
+  SC1extra2: 1.337
+
+overridden-chartA:
+  SCAbool: true
+  SCAfloat: 3.14
+  SCAint: 100
+  SCAstring: "jabathehut"
+  SC1extra3: true
+
+imported-chartA-B:
+  SC1extra5: "tiller"
+
+overridden-chartA-B:
+  SCAbool: true
+  SCAfloat: 3.33
+  SCAint: 555
+  SCAstring: "wormwood"
+  SCAextra1: 23
+
+  SCBbool: true
+  SCBfloat: 0.25
+  SCBint: 98
+  SCBstring: "murkwood"
+  SCBextra1: 13
+
+  SC1extra6: 77
+
+SCBexported1A:
+  SC1extra7: true
+
+exports:
+  SC1exported1:
+    global:
+      SC1exported2:
+        all:
+          SC1exported3: "SC1expstr"
\ No newline at end of file
diff --git a/src/orchestrator/mock_files/mock_profiles/profile1/faulty-dest-manifest.yaml b/src/orchestrator/mock_files/mock_profiles/profile1/faulty-dest-manifest.yaml
new file mode 100644 (file)
index 0000000..8c61a4e
--- /dev/null
@@ -0,0 +1,7 @@
+---
+version: v1
+type:
+  values: "override_values.yaml"
+  configresource:
+    - filepath: subdir/p1.yaml
+      chartpath: testchart1/folderdoesNOTexist/p1.yaml
diff --git a/src/orchestrator/mock_files/mock_profiles/profile1/faulty-manifest.yaml b/src/orchestrator/mock_files/mock_profiles/profile1/faulty-manifest.yaml
new file mode 100644 (file)
index 0000000..a123111
--- /dev/null
@@ -0,0 +1,8 @@
+---
+version: v1
+type:
+  values: 
+    - override_values.yaml
+  configresource:
+  - filepath: subdir/p1.yaml
+    chartpath: testchart1/templates/p1.yaml
diff --git a/src/orchestrator/mock_files/mock_profiles/profile1/faulty-src-manifest.yaml b/src/orchestrator/mock_files/mock_profiles/profile1/faulty-src-manifest.yaml
new file mode 100644 (file)
index 0000000..eff534b
--- /dev/null
@@ -0,0 +1,7 @@
+---
+version: v1
+type:
+  values: "override_values.yaml"
+  configresource:
+    - filepath: subdir/filedoesNOTexist.yaml
+      chartpath: testchart1/templates/p1.yaml
diff --git a/src/orchestrator/mock_files/mock_profiles/profile1/manifest.yaml b/src/orchestrator/mock_files/mock_profiles/profile1/manifest.yaml
new file mode 100644 (file)
index 0000000..e4beada
--- /dev/null
@@ -0,0 +1,7 @@
+---
+version: v1
+type:
+  values: "override_values.yaml"
+  configresource:
+    - filepath: subdir/p1.yaml
+      chartpath: testchart1/templates/p1.yaml
diff --git a/src/orchestrator/mock_files/mock_profiles/profile1/override_values.yaml b/src/orchestrator/mock_files/mock_profiles/profile1/override_values.yaml
new file mode 100644 (file)
index 0000000..0186c66
--- /dev/null
@@ -0,0 +1,9 @@
+# Default values for subchart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+# subchart1
+service:
+  name: nginx
+  type: ClusterIP
+  externalPort: 8080
+  internalPort: 8080
\ No newline at end of file
diff --git a/src/orchestrator/mock_files/mock_profiles/profile1/subdir/p1.yaml b/src/orchestrator/mock_files/mock_profiles/profile1/subdir/p1.yaml
new file mode 100644 (file)
index 0000000..2dad677
--- /dev/null
@@ -0,0 +1,22 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Chart.Name }}-override
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+    namespace: "{{ .Release.Namespace }}"
+    release-name: "{{ .Release.Name }}"
+    release-is-upgrade: "{{ .Release.IsUpgrade }}"
+    release-is-install: "{{ .Release.IsInstall }}"
+    kube-version/major: "{{ .Capabilities.KubeVersion.Major }}"
+    kube-version/minor: "{{ .Capabilities.KubeVersion.Minor }}"
+    kube-version/gitversion: "v{{ .Capabilities.KubeVersion.Major }}.{{ .Capabilities.KubeVersion.Minor }}.0"
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+  - port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
+    protocol: TCP
+    name: {{ .Values.service.name }}
+  selector:
+    app: {{ .Chart.Name }}
index 3c70418..5fabe81 100644 (file)
@@ -20,7 +20,6 @@ import (
        "fmt"
        "github.com/onap/multicloud-k8s/src/orchestrator/utils/helm"
 
-       "github.com/onap/multicloud-k8s/src/orchestrator/utils/types"
        pkgerrors "github.com/pkg/errors"
 
        "encoding/base64"
@@ -67,11 +66,11 @@ func getOverrideValuesByAppName(ov []OverrideValues, a string) map[string]string
 
 // GetSortedTemplateForApp returns the sorted templates.
 //It takes in arguments - appName, project, compositeAppName, releaseName, compositeProfileName, array of override values
-func GetSortedTemplateForApp(appName, p, ca, v, rName, cp string, overrideValues []OverrideValues) ([]types.KubernetesResourceTemplate, error) {
+func GetSortedTemplateForApp(appName, p, ca, v, rName, cp string, overrideValues []OverrideValues) ([]helm.KubernetesResourceTemplate, error) {
 
        log.Println("Processing App.. ", appName)
 
-       var sortedTemplates []types.KubernetesResourceTemplate
+       var sortedTemplates []helm.KubernetesResourceTemplate
 
        aC, err := NewAppClient().GetAppContent(appName, p, ca, v)
        if err != nil {
@@ -107,7 +106,7 @@ func GetSortedTemplateForApp(appName, p, ca, v, rName, cp string, overrideValues
        sortedTemplates, err = helm.NewTemplateClient("", "default", rName,
                ManifestFileName).Resolve(appContent,
                appProfileContent, overrideValuesOfAppStr,
-               rName, appName)
+               appName)
 
        log.Printf("The len of the sortedTemplates :: %d", len(sortedTemplates))
 
index e9610ef..eedbeb8 100644 (file)
@@ -59,7 +59,7 @@ func (c *MockContextDb) Delete(key string) error {
 
 // Delete all function
 func (c *MockContextDb) DeleteAll(key string) error {
-       for kvKey, _ := range c.Items {
+       for kvKey := range c.Items {
                delete(c.Items, kvKey)
        }
        return c.Err
@@ -69,7 +69,7 @@ func (c *MockContextDb) DeleteAll(key string) error {
 func (c *MockContextDb) GetAllKeys(path string) ([]string, error) {
        var keys []string
 
-       for k, _ := range c.Items {
+       for k := range c.Items {
                keys = append(keys, string(k))
        }
        return keys, c.Err
index f0d15fb..80cdfe5 100644 (file)
@@ -19,7 +19,6 @@ package helm
 import (
        "bytes"
        utils "github.com/onap/multicloud-k8s/src/orchestrator/utils"
-       "github.com/onap/multicloud-k8s/src/orchestrator/utils/types"
 
        pkgerrors "github.com/pkg/errors"
        "log"
@@ -46,6 +45,15 @@ import (
        "k8s.io/helm/pkg/timeconv"
 )
 
+//KubernetesResourceTemplate - Represents the template that is used to create a particular
+//resource in Kubernetes
+type KubernetesResourceTemplate struct {
+       // Tracks the apiVersion and Kind of the resource
+       GVK schema.GroupVersionKind
+       // Path to the file that contains the resource info
+       FilePath string
+}
+
 // Template is the interface for all helm templating commands
 // Any backend implementation will implement this interface and will
 // access the functionality via this.
@@ -144,10 +152,10 @@ func (h *TemplateClient) mergeValues(dest map[string]interface{}, src map[string
 
 // GenerateKubernetesArtifacts a mapping of type to fully evaluated helm template
 func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFiles []string,
-       values []string) ([]types.KubernetesResourceTemplate, error) {
+       values []string) ([]KubernetesResourceTemplate, error) {
 
        var outputDir, chartPath, namespace, releaseName string
-       var retData []types.KubernetesResourceTemplate
+       var retData []KubernetesResourceTemplate
 
        releaseName = h.releaseName
        namespace = h.kubeNameSpace
@@ -255,7 +263,7 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile
                        return retData, err
                }
 
-               kres := types.KubernetesResourceTemplate{
+               kres := KubernetesResourceTemplate{
                        GVK:      gvk,
                        FilePath: mfilePath,
                }
@@ -281,13 +289,20 @@ func getGroupVersionKind(data string) (schema.GroupVersionKind, error) {
 
 // Resolver is an interface exposes the helm related functionalities
 type Resolver interface {
-       Resolve(appContent, appProfileContent []byte, overrideValuesOfAppStr []string, rName string) ([]types.KubernetesResourceTemplate, error)
+       Resolve(appContent, appProfileContent []byte, overrideValuesOfAppStr []string, appName string) ([]KubernetesResourceTemplate, error)
 }
 
 // Resolve function
-func (h *TemplateClient) Resolve(appContent []byte, appProfileContent []byte, overrideValuesOfAppStr []string, rName, appName string) ([]types.KubernetesResourceTemplate, error) {
+func (h *TemplateClient) Resolve(appContent []byte, appProfileContent []byte, overrideValuesOfAppStr []string, appName string) ([]KubernetesResourceTemplate, error) {
+
+       var sortedTemplates []KubernetesResourceTemplate
 
-       var sortedTemplates []types.KubernetesResourceTemplate
+       //chartBasePath is the tmp path where the appContent(rawHelmCharts) is extracted.
+       chartBasePath, err := utils.ExtractTarBall(bytes.NewBuffer(appContent))
+       if err != nil {
+               return sortedTemplates, pkgerrors.Wrap(err, "Extracting appContent")
+       }
+       log.Printf("The chartBasePath :: %s", chartBasePath)
 
        //prPath is the tmp path where the appProfileContent is extracted.
        prPath, err := utils.ExtractTarBall(bytes.NewBuffer(appProfileContent))
@@ -296,16 +311,12 @@ func (h *TemplateClient) Resolve(appContent []byte, appProfileContent []byte, ov
        }
        log.Printf("The profile path:: %s", prPath)
 
-       prYamlClient, err := utils.ProcessProfileYaml(prPath, h.manifestName)
+       prYamlClient, err := ProcessProfileYaml(prPath, h.manifestName)
        if err != nil {
                return sortedTemplates, pkgerrors.Wrap(err, "Processing Profile Manifest")
        }
        log.Println("Got the profileYamlClient..")
 
-       //chartBasePath is the tmp path where the appContent(rawHelmCharts) is extracted.
-       chartBasePath, err := utils.ExtractTarBall(bytes.NewBuffer(appContent))
-       log.Printf("The chartBasePath :: %s", chartBasePath)
-
        err = prYamlClient.CopyConfigurationOverrides(chartBasePath)
        if err != nil {
                return sortedTemplates, pkgerrors.Wrap(err, "Copying configresources to chart")
diff --git a/src/orchestrator/utils/helm/helm_test.go b/src/orchestrator/utils/helm/helm_test.go
new file mode 100644 (file)
index 0000000..e9442e8
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2020 Intel Corporation, Inc
+ *
+ * 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.
+ */
+
+package helm
+
+import (
+       "crypto/sha256"
+       "fmt"
+
+       "io/ioutil"
+       "path/filepath"
+       "strings"
+       "testing"
+)
+
+func TestProcessValues(t *testing.T) {
+
+       chartDir := "../../mock_files/mock_charts/testchart2"
+       profileDir := "../../mock_files/mock_profiles/profile1"
+
+       testCases := []struct {
+               label         string
+               valueFiles    []string
+               values        []string
+               expectedHash  string
+               expectedError string
+       }{
+               {
+                       label: "Process Values with Value Files Override",
+                       valueFiles: []string{
+                               filepath.Join(chartDir, "values.yaml"),
+                               filepath.Join(profileDir, "override_values.yaml"),
+                       },
+                       //Hash of a combined values.yaml file that is expected
+                       expectedHash:  "c18a70f426933de3c051c996dc34fd537d0131b2d13a2112a2ecff674db6c2f9",
+                       expectedError: "",
+               },
+               {
+                       label: "Process Values with Values Pair Override",
+                       valueFiles: []string{
+                               filepath.Join(chartDir, "values.yaml"),
+                       },
+                       //Use the same convention as specified in helm template --set
+                       values: []string{
+                               "service.externalPort=82",
+                       },
+                       //Hash of a combined values.yaml file that is expected
+                       expectedHash:  "028a3521fc9f8777ea7e67a6de0c51f2c875b88ca91734999657f0ca924ddb7a",
+                       expectedError: "",
+               },
+               {
+                       label: "Process Values with Both Overrides",
+                       valueFiles: []string{
+                               filepath.Join(chartDir, "values.yaml"),
+                               filepath.Join(profileDir, "override_values.yaml"),
+                       },
+                       //Use the same convention as specified in helm template --set
+                       //Key takes precedence over the value from override_values.yaml
+                       values: []string{
+                               "service.externalPort=82",
+                       },
+                       //Hash of a combined values.yaml file that is expected
+                       expectedHash:  "516fab4ab7b76ba2ff35a97c2a79b74302543f532857b945f2fe25e717e755be",
+                       expectedError: "",
+               },
+               {
+                       label: "Process complex Pair Override",
+                       values: []string{
+                               "name={a,b,c}",
+                               "servers[0].port=80",
+                       },
+                       expectedError: "",
+                       expectedHash:  "50d9401b003f65c1ccfd1c5155106fff88c8201ab8b7d66bd6ffa4fe2883bead",
+               },
+       }
+
+       h := sha256.New()
+
+       for _, testCase := range testCases {
+               t.Run(testCase.label, func(t *testing.T) {
+                       tc := NewTemplateClient("1.12.3", "testnamespace", "testreleasename", "manifest.yaml")
+                       out, err := tc.processValues(testCase.valueFiles, testCase.values)
+                       if err != nil {
+                               if testCase.expectedError == "" {
+                                       t.Fatalf("Got an error %s", err)
+                               }
+                               if strings.Contains(err.Error(), testCase.expectedError) == false {
+                                       t.Fatalf("Got unexpected error message %s", err)
+                               }
+                       } else {
+                               //Compute the hash of returned data and compare
+                               h.Write(out)
+                               gotHash := fmt.Sprintf("%x", h.Sum(nil))
+                               h.Reset()
+                               if gotHash != testCase.expectedHash {
+                                       t.Fatalf("Got unexpected hash '%s' of values.yaml:\n%s", gotHash, out)
+                               }
+                       }
+               })
+       }
+}
+
+func TestGenerateKubernetesArtifacts(t *testing.T) {
+
+       chartDir := "../../mock_files/mock_charts/testchart2"
+       profileDir := "../../mock_files/mock_profiles/profile1"
+
+       testCases := []struct {
+               label           string
+               chartPath       string
+               valueFiles      []string
+               values          []string
+               expectedHashMap map[string]string
+               expectedError   string
+       }{
+               {
+                       label:      "Generate artifacts without any overrides",
+                       chartPath:  chartDir,
+                       valueFiles: []string{},
+                       values:     []string{},
+                       //sha256 hash of the evaluated templates in each chart
+                       expectedHashMap: map[string]string{
+                               "testchart2/templates/service.yaml": "fdd6a2b6795486f0dd1d8c44379afb5ffe4072c09f9cf6594738e8ded4dd872d",
+                               "subcharta/templates/service.yaml":  "570389588fffdb7193ab265888d781f3d751f3a40362533344f9aa7bb93a8bb0",
+                               "subchartb/templates/service.yaml":  "5654e03d922e8ec49649b4bbda9dfc9e643b3b7c9c18b602cc7e26fd36a39c2a",
+                       },
+                       expectedError: "",
+               },
+               {
+                       label:     "Generate artifacts with overrides",
+                       chartPath: chartDir,
+                       valueFiles: []string{
+                               filepath.Join(profileDir, "override_values.yaml"),
+                       },
+                       values: []string{
+                               "service.externalPort=82",
+                       },
+                       //sha256 hash of the evaluated templates in each chart
+                       expectedHashMap: map[string]string{
+                               "testchart2/templates/service.yaml": "2bb96e791ecb6a3404bc5de3f6c4182aed881630269e2aa6766df38b0f852724",
+                               "subcharta/templates/service.yaml":  "570389588fffdb7193ab265888d781f3d751f3a40362533344f9aa7bb93a8bb0",
+                               "subchartb/templates/service.yaml":  "5654e03d922e8ec49649b4bbda9dfc9e643b3b7c9c18b602cc7e26fd36a39c2a",
+                       },
+                       expectedError: "",
+               },
+       }
+
+       h := sha256.New()
+
+       for _, testCase := range testCases {
+               t.Run(testCase.label, func(t *testing.T) {
+                       tc := NewTemplateClient("1.12.3", "testnamespace", "testreleasename", "manifest.yaml")
+                       out, err := tc.GenerateKubernetesArtifacts(testCase.chartPath, testCase.valueFiles,
+                               testCase.values)
+                       if err != nil {
+                               if testCase.expectedError == "" {
+                                       t.Fatalf("Got an error %s", err)
+                               }
+                               if strings.Contains(err.Error(), testCase.expectedError) == false {
+                                       t.Fatalf("Got unexpected error message %s", err)
+                               }
+                       } else {
+                               //Compute the hash of returned data and compare
+                               for _, v := range out {
+                                       f := v.FilePath
+                                       data, err := ioutil.ReadFile(f)
+                                       if err != nil {
+                                               t.Errorf("Unable to read file %s", v)
+                                       }
+                                       h.Write(data)
+                                       gotHash := fmt.Sprintf("%x", h.Sum(nil))
+                                       h.Reset()
+
+                                       //Find the right hash from expectedHashMap
+                                       expectedHash := ""
+                                       for k1, v1 := range testCase.expectedHashMap {
+                                               if strings.Contains(f, k1) == true {
+                                                       expectedHash = v1
+                                                       break
+                                               }
+                                       }
+                                       if gotHash != expectedHash {
+                                               t.Fatalf("Got unexpected hash for %s", f)
+                                       }
+                               }
+                       }
+               })
+       }
+
+}
similarity index 99%
rename from src/orchestrator/utils/profile_yaml.go
rename to src/orchestrator/utils/helm/profile_yaml.go
index 91687c0..e72fdbd 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package utils
+package helm
 
 import (
        "io/ioutil"
diff --git a/src/orchestrator/utils/types/types.go b/src/orchestrator/utils/types/types.go
deleted file mode 100644 (file)
index 4ffb418..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2020 Intel Corporation, Inc
- *
- * 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.
- */
-
-package types
-
-import (
-       "k8s.io/apimachinery/pkg/runtime/schema"
-)
-
-// KubernetesResourceTemplate - Represents the template that is used to create a particular
-// resource in Kubernetes
-type KubernetesResourceTemplate struct {
-       // Tracks the apiVersion and Kind of the resource
-       GVK schema.GroupVersionKind
-       // Path to the file that contains the resource info
-       FilePath string
-}
-
-// KubernetesResource is the resource that is created in Kubernetes
-// It is the type that will be used for tracking a resource.
-// Any future information such as status, time can be added here
-// for tracking.
-type KubernetesResource struct {
-       // Tracks the apiVersion and Kind of the resource
-       GVK schema.GroupVersionKind
-       // Name of resource in Kubernetes
-       Name string
-}