Skip to content

Commit d2aebcc

Browse files
Merge pull request #22870 from sjug/cl_yaml_spec
Cluster Loader: Add switch to handle yaml as podspec in config
2 parents ddbf946 + 271c737 commit d2aebcc

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

test/extended/cluster/cl.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ var _ = g.Describe("[Feature:Performance][Serial][Slow] Load cluster", func() {
143143
// This is too familiar, create pods
144144
for _, pod := range p.Pods {
145145
// Parse Pod file into struct
146-
config := ParsePods(mkPath(pod.File))
146+
config, err := ParsePods(mkPath(pod.File))
147+
o.Expect(err).NotTo(o.HaveOccurred())
147148
// Check if environment variables are defined in CL config
148149
if pod.Parameters == nil {
149150
e2e.Logf("Pod environment variables will not be modified.")
@@ -157,7 +158,7 @@ var _ = g.Describe("[Feature:Performance][Serial][Slow] Load cluster", func() {
157158
}
158159
// TODO sjug: pass label via config
159160
labels := map[string]string{"purpose": "test"}
160-
err := CreatePods(c, pod.Basename, nsName, labels, config.Spec, pod.Number, tuning, &pod.Sync)
161+
err = CreatePods(c, pod.Basename, nsName, labels, config.Spec, pod.Number, tuning, &pod.Sync)
161162
o.Expect(err).NotTo(o.HaveOccurred())
162163
}
163164
}

test/extended/cluster/utils.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
"net"
88
"net/http"
99
"os"
10+
"path/filepath"
1011
"strconv"
1112
"strings"
1213
"time"
1314
"unicode"
1415

16+
"github.com/ghodss/yaml"
1517
kapiv1 "k8s.io/api/core/v1"
1618
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1719
"k8s.io/apimachinery/pkg/labels"
@@ -26,20 +28,31 @@ import (
2628
// The number of times we re-try to create a pod
2729
const maxRetries = 4
2830

29-
// ParsePods unmarshalls the json file defined in the CL config into a struct
30-
func ParsePods(jsonFile string) (configStruct kapiv1.Pod) {
31-
configFile, err := ioutil.ReadFile(jsonFile)
31+
// ParsePods unmarshalls the pod spec file defined in the CL config into a struct
32+
func ParsePods(file string) (kapiv1.Pod, error) {
33+
var configStruct kapiv1.Pod
34+
35+
configFile, err := ioutil.ReadFile(file)
3236
if err != nil {
33-
framework.Failf("Cant read pod config file. Error: %v", err)
37+
return configStruct, err
3438
}
3539

36-
err = json.Unmarshal(configFile, &configStruct)
37-
if err != nil {
38-
e2e.Failf("Unable to unmarshal pod config. Error: %v", err)
40+
switch filepath.Ext(file) {
41+
case ".yaml", ".yml":
42+
err = yaml.Unmarshal(configFile, &configStruct)
43+
if err != nil {
44+
return configStruct, err
45+
}
46+
case ".json":
47+
err = json.Unmarshal(configFile, &configStruct)
48+
if err != nil {
49+
return configStruct, err
50+
}
51+
default:
52+
return configStruct, fmt.Errorf("Unknown config file extension")
3953
}
4054

41-
e2e.Logf("The loaded config file is: %+v", configStruct.Spec.Containers)
42-
return
55+
return configStruct, nil
4356
}
4457

4558
// SyncPods waits for pods to enter a state

0 commit comments

Comments
 (0)