Skip to content

Commit

Permalink
Merge pull request #17072 from sjug/cl_param_fix
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 17072, 17616).

Remove hardcoded fields for parameter substitution configuration in Cluster Loader

Fixes #17068

This should enable us to remove `fatih/structs` as a vendor dep as well.
  • Loading branch information
openshift-merge-robot authored Dec 21, 2017
2 parents b5db059 + 2277f3d commit f37047b
Show file tree
Hide file tree
Showing 15 changed files with 10 additions and 3,250 deletions.
2 changes: 0 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 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{}) {
e2e.Logf("Pod environment variables will not be modified.")
if template.Parameters == nil {
e2e.Logf("Template 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
11 changes: 1 addition & 10 deletions test/extended/cluster/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ type ClusterLoaderObjectType struct {
Image string
Basename string
File string
Parameters ParameterConfigType
}

// ParameterConfigType contains config parameters for each object
type ParameterConfigType struct {
Run string `mapstructure:"run"`
RouterIP string `mapstructure:"router_ip"`
TargetHost string `mapstructure:"target_host"`
DurationSec int `mapstructure:"duration"`
Megabytes int
Parameters map[string]interface{}
}

// TuningSetType is nested type for controlling Cluster Loader deployment pattern
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"

kapiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -165,10 +163,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 @@ -181,9 +178,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 @@ -194,7 +190,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
23 changes: 0 additions & 23 deletions vendor/github.com/fatih/structs/.gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions vendor/github.com/fatih/structs/.travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/fatih/structs/LICENSE

This file was deleted.

163 changes: 0 additions & 163 deletions vendor/github.com/fatih/structs/README.md

This file was deleted.

Loading

0 comments on commit f37047b

Please sign in to comment.