Skip to content

Commit

Permalink
Remove hardcoded parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sjug committed Oct 27, 2017
1 parent eecb026 commit 3a03293
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions test/extended/cluster/cl.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ var _ = g.Describe("[Feature:Performance][Serial][Slow] Load cluster", func() {
}
allArgs = append(allArgs, templateObj.Name)

if template.Parameters == (ParameterConfigType{}) {
if template.Parameters == nil {
e2e.Logf("Pod environment variables will not be modified.")
} else {
params := convertVariablesToString(template.Parameters)
allArgs = append(allArgs, params...)
}

config, err := oc.AdminTemplateClient().Template().Templates(nsName).Create(templateObj)
e2e.Logf("Template %v created, config: %+v", templateObj.Name, config)
e2e.Logf("Template %v created, arguments: %v, config: %+v", templateObj.Name, allArgs, config)

err = oc.SetNamespace(nsName).Run("new-app").Args(allArgs...).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
Expand All @@ -110,7 +110,7 @@ var _ = g.Describe("[Feature:Performance][Serial][Slow] Load cluster", func() {
// Parse Pod file into struct
config := ParsePods(mkPath(pod.File))
// Check if environment variables are defined in CL config
if pod.Parameters == (ParameterConfigType{}) {
if pod.Parameters == nil {
e2e.Logf("Pod environment variables will not be modified.")
} else {
// Override environment variables for Pod using ConfigMap
Expand Down
2 changes: 1 addition & 1 deletion test/extended/cluster/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ClusterLoaderObjectType struct {
Image string
Basename string
File string
Parameters ParameterConfigType
Parameters map[string]interface{}
}

// ParameterConfigType contains config parameters for each object
Expand Down
14 changes: 5 additions & 9 deletions test/extended/cluster/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"time"
"unicode"

"github.com/fatih/structs"

exutil "github.com/openshift/origin/test/extended/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -164,10 +162,9 @@ func firstLowercase(s string) string {
}

// convertVariables takes our loaded struct and converts it into a map[string]string.
func convertVariablesToMap(params ParameterConfigType) map[string]string {
m := structs.Map(params)
func convertVariablesToMap(params map[string]interface{}) map[string]string {
values := make(map[string]string)
for k, v := range m {
for k, v := range params {
k = firstLowercase(k)
if v != 0 && v != "" {
if _, ok := v.(int); ok {
Expand All @@ -180,9 +177,8 @@ func convertVariablesToMap(params ParameterConfigType) map[string]string {
return values
}

func convertVariablesToString(params ParameterConfigType) (args []string) {
m := structs.Map(params)
for k, v := range m {
func convertVariablesToString(params map[string]interface{}) (args []string) {
for k, v := range params {
k = strings.ToUpper(k)
if v != 0 && v != "" {
args = append(args, "-p")
Expand All @@ -193,7 +189,7 @@ func convertVariablesToString(params ParameterConfigType) (args []string) {
}

// InjectConfigMap modifies the pod struct and replaces the environment variables.
func InjectConfigMap(c kclientset.Interface, ns string, vars ParameterConfigType, config kapiv1.Pod) string {
func InjectConfigMap(c kclientset.Interface, ns string, vars map[string]interface{}, config kapiv1.Pod) string {
configMapName := ns + "-configmap"
freshConfigVars := convertVariablesToMap(vars)
dirtyConfigVars := getClusterData(c, freshConfigVars)
Expand Down

0 comments on commit 3a03293

Please sign in to comment.