Skip to content

Commit

Permalink
Environment variabled are populated in random order, causing function…
Browse files Browse the repository at this point in the history
…al tests in golang #518 to fail
  • Loading branch information
procrypt committed Jun 1, 2017
1 parent a6df28f commit 54369f4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
24 changes: 23 additions & 1 deletion pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import (
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/intstr"
//"k8s.io/kubernetes/pkg/controller/daemon"
"sort"

"github.com/pkg/errors"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/labels"
Expand Down Expand Up @@ -478,16 +480,36 @@ func (k *Kubernetes) ConfigPVCVolumeSource(name string, readonly bool) *api.Volu
}
}

// Sort struct
type EnvSort []api.EnvVar

// returns the number of elements in the collection.
func (env EnvSort) Len() int {
return len(env)
}

// returns whether the element with index i should sort before
// the element with index j.
func (env EnvSort) Less(i, j int) bool {
return env[i].Name < env[j].Name
}

// swaps the elements with indexes i and j.
func (env EnvSort) Swap(i, j int) {
env[i], env[j] = env[j], env[i]
}

// ConfigEnvs configures the environment variables.
func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []api.EnvVar {
envs := []api.EnvVar{}
envs := EnvSort{}
for _, v := range service.Environment {
envs = append(envs, api.EnvVar{
Name: v.Name,
Value: v.Value,
})
}

sort.Sort(envs)
return envs
}

Expand Down
18 changes: 14 additions & 4 deletions pkg/transformer/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/intstr"
"sort"
)

// OpenShift implements Transformer interface and represents OpenShift transformer
Expand Down Expand Up @@ -202,11 +203,20 @@ func (o *OpenShift) initImageStream(name string, service kobject.ServiceConfig,
func initBuildConfig(name string, service kobject.ServiceConfig, repo string, branch string) (*buildapi.BuildConfig, error) {
contextDir, err := getAbsBuildContext(service.Build)
envList := []kapi.EnvVar{}
for envName, envValue := range service.BuildArgs {
if *envValue == "\x00" {
*envValue = os.Getenv(envName)
var sortEnvName []string
for EnvName, _ := range service.BuildArgs {
sortEnvName = append(sortEnvName, EnvName)
}
sort.Strings(sortEnvName)
for _, newEnv := range sortEnvName {
for envName, envValue := range service.BuildArgs {
if envName == newEnv {
if *envValue == "\x00" {
*envValue = os.Getenv(envName)
}
envList = append(envList, kapi.EnvVar{Name: envName, Value: *envValue})
}
}
envList = append(envList, kapi.EnvVar{Name: envName, Value: *envValue})
}
if err != nil {
return nil, errors.Wrap(err, name+"buildconfig cannot be created due to error in creating build context, getAbsBuildContext failed")
Expand Down

0 comments on commit 54369f4

Please sign in to comment.