@@ -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
2729const 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