From 271c7372c1328bdb1465e2e161c64ded6b3ac4a1 Mon Sep 17 00:00:00 2001 From: Sebastian Jug Date: Mon, 20 May 2019 08:51:30 -0400 Subject: [PATCH] Add switch to handle yaml as podspec in config --- test/extended/cluster/cl.go | 5 +++-- test/extended/cluster/utils.go | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/test/extended/cluster/cl.go b/test/extended/cluster/cl.go index 009fe30ae2a1..2fd1059ca7a5 100644 --- a/test/extended/cluster/cl.go +++ b/test/extended/cluster/cl.go @@ -143,7 +143,8 @@ var _ = g.Describe("[Feature:Performance][Serial][Slow] Load cluster", func() { // This is too familiar, create pods for _, pod := range p.Pods { // Parse Pod file into struct - config := ParsePods(mkPath(pod.File)) + config, err := ParsePods(mkPath(pod.File)) + o.Expect(err).NotTo(o.HaveOccurred()) // Check if environment variables are defined in CL config if pod.Parameters == nil { e2e.Logf("Pod environment variables will not be modified.") @@ -157,7 +158,7 @@ var _ = g.Describe("[Feature:Performance][Serial][Slow] Load cluster", func() { } // TODO sjug: pass label via config labels := map[string]string{"purpose": "test"} - err := CreatePods(c, pod.Basename, nsName, labels, config.Spec, pod.Number, tuning, &pod.Sync) + err = CreatePods(c, pod.Basename, nsName, labels, config.Spec, pod.Number, tuning, &pod.Sync) o.Expect(err).NotTo(o.HaveOccurred()) } } diff --git a/test/extended/cluster/utils.go b/test/extended/cluster/utils.go index 8221684f4246..ffe0b94415ab 100644 --- a/test/extended/cluster/utils.go +++ b/test/extended/cluster/utils.go @@ -7,11 +7,13 @@ import ( "net" "net/http" "os" + "path/filepath" "strconv" "strings" "time" "unicode" + "github.com/ghodss/yaml" kapiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -26,20 +28,31 @@ import ( // The number of times we re-try to create a pod const maxRetries = 4 -// ParsePods unmarshalls the json file defined in the CL config into a struct -func ParsePods(jsonFile string) (configStruct kapiv1.Pod) { - configFile, err := ioutil.ReadFile(jsonFile) +// ParsePods unmarshalls the pod spec file defined in the CL config into a struct +func ParsePods(file string) (kapiv1.Pod, error) { + var configStruct kapiv1.Pod + + configFile, err := ioutil.ReadFile(file) if err != nil { - framework.Failf("Cant read pod config file. Error: %v", err) + return configStruct, err } - err = json.Unmarshal(configFile, &configStruct) - if err != nil { - e2e.Failf("Unable to unmarshal pod config. Error: %v", err) + switch filepath.Ext(file) { + case ".yaml", ".yml": + err = yaml.Unmarshal(configFile, &configStruct) + if err != nil { + return configStruct, err + } + case ".json": + err = json.Unmarshal(configFile, &configStruct) + if err != nil { + return configStruct, err + } + default: + return configStruct, fmt.Errorf("Unknown config file extension") } - e2e.Logf("The loaded config file is: %+v", configStruct.Spec.Containers) - return + return configStruct, nil } // SyncPods waits for pods to enter a state