aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdeployments/_functions.sh11
-rw-r--r--deployments/helm/v2/emco/Chart.yaml2
-rwxr-xr-xdeployments/start.sh1
-rw-r--r--kud/deployment_infra/playbooks/configure-optane.yml2
-rw-r--r--kud/deployment_infra/playbooks/preconfigure-optane.yml16
-rwxr-xr-xkud/tests/emco.sh2
-rwxr-xr-xkud/tests/plugin_fw.sh4
-rwxr-xr-xkud/tests/topology-manager.sh5
-rw-r--r--src/k8splugin/internal/helm/helm.go34
-rw-r--r--src/k8splugin/internal/helm/helm_test.go29
-rw-r--r--src/k8splugin/mock_files/mock_charts/testchart3/Chart.yaml4
-rw-r--r--src/k8splugin/mock_files/mock_charts/testchart3/templates/always-empty.yaml9
-rw-r--r--src/k8splugin/mock_files/mock_charts/testchart3/templates/multi.yaml34
-rw-r--r--src/k8splugin/mock_files/mock_charts/testchart3/templates/only-comment.yaml6
-rw-r--r--src/k8splugin/mock_files/mock_charts/testchart3/values.yaml1
15 files changed, 131 insertions, 29 deletions
diff --git a/deployments/_functions.sh b/deployments/_functions.sh
index 47074433..c0feed0d 100755
--- a/deployments/_functions.sh
+++ b/deployments/_functions.sh
@@ -34,3 +34,14 @@ EOF
function start_all {
docker-compose up -d
}
+
+function wait_for_service {
+ for try in {0..59}; do
+ echo "$(date +%H:%M:%S) - Waiting for service up"
+ sleep 1
+ if $(curl http://localhost:9015/v1 &>/dev/null); then
+ return 0
+ fi
+ done
+ exit 1
+}
diff --git a/deployments/helm/v2/emco/Chart.yaml b/deployments/helm/v2/emco/Chart.yaml
index 6998dcaa..9c015819 100644
--- a/deployments/helm/v2/emco/Chart.yaml
+++ b/deployments/helm/v2/emco/Chart.yaml
@@ -1,5 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
-name: onap4k8s
+name: emco
version: 0.1.0
diff --git a/deployments/start.sh b/deployments/start.sh
index e7ff1334..61af504c 100755
--- a/deployments/start.sh
+++ b/deployments/start.sh
@@ -21,3 +21,4 @@ stop_all
start_mongo
generate_k8sconfig
start_all
+wait_for_service
diff --git a/kud/deployment_infra/playbooks/configure-optane.yml b/kud/deployment_infra/playbooks/configure-optane.yml
index 8e000aa4..01189808 100644
--- a/kud/deployment_infra/playbooks/configure-optane.yml
+++ b/kud/deployment_infra/playbooks/configure-optane.yml
@@ -12,4 +12,4 @@
- hosts: localhost
tasks:
- name: Apply Optane PMEM CSI Daemonset
- command: "{{ base_dest }}/optane/deploy_optane.sh"
+ command: "{{ optane_dest }}/deploy_optane.sh"
diff --git a/kud/deployment_infra/playbooks/preconfigure-optane.yml b/kud/deployment_infra/playbooks/preconfigure-optane.yml
index 64622895..135371ea 100644
--- a/kud/deployment_infra/playbooks/preconfigure-optane.yml
+++ b/kud/deployment_infra/playbooks/preconfigure-optane.yml
@@ -22,6 +22,14 @@
state: directory
path: "{{ optane_dest }}"
ignore_errors: yes
+ - copy:
+ src: "{{ playbook_dir }}/deploy_optane.sh"
+ dest: "{{ optane_dest }}"
+ - name: Changing perm of "sh", adding "+x"
+ shell: "chmod +x deploy_optane.sh"
+ args:
+ chdir: "{{ optane_dest }}"
+ warn: False
- hosts: kube-node
become: yes
@@ -61,14 +69,6 @@
chdir: "optane"
warn: False
- copy:
- src: "{{ playbook_dir }}/deploy_optane.sh"
- dest: optane
- - name: Changing perm of "sh", adding "+x"
- shell: "chmod +x deploy_optane.sh"
- args:
- chdir: "optane"
- warn: False
- - copy:
src: "{{ playbook_dir }}/../images/pmem-csi-lvm.yaml"
dest: optane
- copy:
diff --git a/kud/tests/emco.sh b/kud/tests/emco.sh
index 8b459b97..2b8eab1e 100755
--- a/kud/tests/emco.sh
+++ b/kud/tests/emco.sh
@@ -424,7 +424,7 @@ function deleteOrchestratorData {
delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}"
- delete_resource "${base_url_orchestrator}/projects/${projectname}"
+ delete_resource_nox "${base_url_orchestrator}/projects/${projectname}"
print_msg "deleteOrchestratorData done"
}
diff --git a/kud/tests/plugin_fw.sh b/kud/tests/plugin_fw.sh
index a503d661..de9c12e2 100755
--- a/kud/tests/plugin_fw.sh
+++ b/kud/tests/plugin_fw.sh
@@ -124,9 +124,9 @@ print_msg "Retrieving VNF details"
response="$(call_api "${base_url}/instance/${vnf_id}")"
echo "$response"
print_msg "Assert additional label has been assigned to rb instance"
-test "$(jq -r .request.labels.testCaseName <<< "${response}")" == plugin_fw.sh
+test "$(jq -r '.request.labels.testCaseName' <<< "${response}")" == plugin_fw.sh
print_msg "Assert ReleaseName has been correctly overriden"
-test "$(jq -r .request.release-name <<< "${response}")" == "${release_name}"
+test "$(jq -r '.request."release-name"' <<< "${response}")" == "${release_name}"
#Teardown
print_msg "Deleting VNF Instance"
diff --git a/kud/tests/topology-manager.sh b/kud/tests/topology-manager.sh
index bbffd4d7..7d434386 100755
--- a/kud/tests/topology-manager.sh
+++ b/kud/tests/topology-manager.sh
@@ -15,9 +15,8 @@ set -o pipefail
source _common.sh
source _functions.sh
-ethernet_adpator_version=$( lspci | grep "Ethernet Controller XL710" | head -n 1 | cut -d " " -f 8 )
-if [ -z "$ethernet_adpator_version" ]; then
- echo " Ethernet adapator version is not set. Topology manager test case cannot run on this machine"
+if [ -z "$( lspci | grep "Ethernet Controller XL710" | head -n 1 | cut -d " " -f 8 )" ]; then
+ echo "Ethernet adaptor version is not set. Topology manager test case cannot run on this machine"
exit 0
else
echo "NIC card specs match. Topology manager option avaiable for this version."
diff --git a/src/k8splugin/internal/helm/helm.go b/src/k8splugin/internal/helm/helm.go
index 2150758b..d3715fce 100644
--- a/src/k8splugin/internal/helm/helm.go
+++ b/src/k8splugin/internal/helm/helm.go
@@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"regexp"
+ "sort"
"strings"
utils "github.com/onap/multicloud-k8s/src/k8splugin/internal"
@@ -55,16 +56,17 @@ type Template interface {
// TemplateClient implements the Template interface
// It will also be used to maintain any localized state
type TemplateClient struct {
- whitespaceRegex *regexp.Regexp
- kubeVersion string
- kubeNameSpace string
- releaseName string
+ emptyRegex *regexp.Regexp
+ kubeVersion string
+ kubeNameSpace string
+ releaseName string
}
// NewTemplateClient returns a new instance of TemplateClient
func NewTemplateClient(k8sversion, namespace, releasename string) *TemplateClient {
return &TemplateClient{
- whitespaceRegex: regexp.MustCompile(`^\s*$`),
+ // emptyRegex defines template content that could be considered empty yaml-wise
+ emptyRegex: regexp.MustCompile(`(?m)\A(^(\s*#.*|\s*)$\n?)*\z`),
// defaultKubeVersion is the default value of --kube-version flag
kubeVersion: k8sversion,
kubeNameSpace: namespace,
@@ -209,11 +211,19 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile
continue
}
rmap := releaseutil.SplitManifests(v)
- count := 0
- for _, v1 := range rmap {
- key := fmt.Sprintf("%s-%d", k, count)
- newRenderedTemplates[key] = v1
- count = count + 1
+
+ // Iterating over map can yield different order at times
+ // so first we'll sort keys
+ sortedKeys := make([]string, len(rmap))
+ for k1, _ := range rmap {
+ sortedKeys = append(sortedKeys, k1)
+ }
+ // This makes empty files have the lowest indices
+ sort.Strings(sortedKeys)
+
+ for k1, v1 := range sortedKeys {
+ key := fmt.Sprintf("%s-%d", k, k1)
+ newRenderedTemplates[key] = rmap[v1]
}
}
@@ -232,7 +242,7 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile
}
// blank template after execution
- if h.whitespaceRegex.MatchString(data) {
+ if h.emptyRegex.MatchString(data) {
continue
}
@@ -260,7 +270,7 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile
func getGroupVersionKind(data string) (schema.GroupVersionKind, error) {
out, err := k8syaml.ToJSON([]byte(data))
if err != nil {
- return schema.GroupVersionKind{}, pkgerrors.Wrap(err, "Converting yaml to json")
+ return schema.GroupVersionKind{}, pkgerrors.Wrap(err, "Converting yaml to json:\n"+data)
}
simpleMeta := json.SimpleMetaFactory{}
diff --git a/src/k8splugin/internal/helm/helm_test.go b/src/k8splugin/internal/helm/helm_test.go
index 1e676c52..817bbaa3 100644
--- a/src/k8splugin/internal/helm/helm_test.go
+++ b/src/k8splugin/internal/helm/helm_test.go
@@ -155,6 +155,33 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
},
expectedError: "",
},
+ {
+ label: "Generate artifacts from multi-template and empty files v1",
+ chartPath: "../../mock_files/mock_charts/testchart3",
+ valueFiles: []string{},
+ values: []string{
+ "goingEmpty=false",
+ },
+ expectedHashMap: map[string]string{
+ "testchart3/templates/multi.yaml-2": "e24cbbefac2c2f700880b8fd041838f2dd48bbc1e099e7c1d2485ae7feb3da0d",
+ "testchart3/templates/multi.yaml-3": "592a8e5b2c35b8469aa45703a835bc00657bfe36b51eb08427a46e7d22fb1525",
+ },
+ expectedError: "",
+ },
+ {
+ label: "Generate artifacts from multi-template and empty files v2",
+ chartPath: "../../mock_files/mock_charts/testchart3",
+ valueFiles: []string{},
+ values: []string{
+ "goingEmpty=true",
+ },
+ expectedHashMap: map[string]string{
+ "testchart3/templates/multi.yaml-3": "e24cbbefac2c2f700880b8fd041838f2dd48bbc1e099e7c1d2485ae7feb3da0d",
+ "testchart3/templates/multi.yaml-4": "0bea01e65148584609ede5000c024241ba1c35b440b32ec0a4f7013015715bfe",
+ "testchart3/templates/multi.yaml-5": "6a5af22538c273b9d4a3156e3b6bb538c655041eae31e93db21a9e178f73ecf0",
+ },
+ expectedError: "",
+ },
}
h := sha256.New()
@@ -192,7 +219,7 @@ func TestGenerateKubernetesArtifacts(t *testing.T) {
}
}
if gotHash != expectedHash {
- t.Fatalf("Got unexpected hash for %s", f)
+ t.Fatalf("Got unexpected hash for %s: '%s'; expected: '%s'", f, gotHash, expectedHash)
}
}
}
diff --git a/src/k8splugin/mock_files/mock_charts/testchart3/Chart.yaml b/src/k8splugin/mock_files/mock_charts/testchart3/Chart.yaml
new file mode 100644
index 00000000..adf4e2fe
--- /dev/null
+++ b/src/k8splugin/mock_files/mock_charts/testchart3/Chart.yaml
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: testchart3
+version: 0.1.0
diff --git a/src/k8splugin/mock_files/mock_charts/testchart3/templates/always-empty.yaml b/src/k8splugin/mock_files/mock_charts/testchart3/templates/always-empty.yaml
new file mode 100644
index 00000000..121130fc
--- /dev/null
+++ b/src/k8splugin/mock_files/mock_charts/testchart3/templates/always-empty.yaml
@@ -0,0 +1,9 @@
+---
+{{ if eq 0 1 }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: dummy
+data:
+ key1: value1
+{{ end }}
diff --git a/src/k8splugin/mock_files/mock_charts/testchart3/templates/multi.yaml b/src/k8splugin/mock_files/mock_charts/testchart3/templates/multi.yaml
new file mode 100644
index 00000000..0539cfb4
--- /dev/null
+++ b/src/k8splugin/mock_files/mock_charts/testchart3/templates/multi.yaml
@@ -0,0 +1,34 @@
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: dummy
+data:
+ key1: value1
+---
+{{ if .Values.goingEmpty }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: dummy
+spec:
+ template:
+ metadata:
+ labels:
+ app: dummy
+ spec:
+ container:
+ - name: dummy
+ image: dummy
+{{ end }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: dummy
+spec:
+ ports:
+ - port: 80
+ protocol: TCP
+ selector:
+ app: dummy
diff --git a/src/k8splugin/mock_files/mock_charts/testchart3/templates/only-comment.yaml b/src/k8splugin/mock_files/mock_charts/testchart3/templates/only-comment.yaml
new file mode 100644
index 00000000..aaacc787
--- /dev/null
+++ b/src/k8splugin/mock_files/mock_charts/testchart3/templates/only-comment.yaml
@@ -0,0 +1,6 @@
+#not so empty?
+#Copyright or something similiar
+#Some license info
+{{/*
+ empty
+*/}}
diff --git a/src/k8splugin/mock_files/mock_charts/testchart3/values.yaml b/src/k8splugin/mock_files/mock_charts/testchart3/values.yaml
new file mode 100644
index 00000000..912d0dbc
--- /dev/null
+++ b/src/k8splugin/mock_files/mock_charts/testchart3/values.yaml
@@ -0,0 +1 @@
+goingEmpty: true