Skip to content

Commit

Permalink
Merge pull request #565 from procrypt/ux
Browse files Browse the repository at this point in the history
sort output when creating kubernetes/openshift objects
  • Loading branch information
cdrage authored May 10, 2017
2 parents ebd9dcf + 529e6c6 commit f66a11f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
11 changes: 11 additions & 0 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
deployapi "github.com/openshift/origin/pkg/deploy/api"
"github.com/pkg/errors"
"k8s.io/kubernetes/pkg/api/resource"
"sort"
)

/**
Expand Down Expand Up @@ -542,3 +543,13 @@ func (k *Kubernetes) VolumesFrom(objects *[]runtime.Object, komposeObject kobjec
}
return nil
}

//Ensure the kubernetes objects are in a consistent order
func SortedKeys(komposeObject kobject.KomposeObject) []string {
var sortedKeys []string
for name := range komposeObject.ServiceConfigs {
sortedKeys = append(sortedKeys, name)
}
sort.Strings(sortedKeys)
return sortedKeys
}
21 changes: 21 additions & 0 deletions pkg/transformer/kubernetes/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pkg/errors"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
"reflect"
)

/*
Expand Down Expand Up @@ -275,3 +276,23 @@ func TestRecreateStrategyWithVolumesPresent(t *testing.T) {
}
}
}

func TestSortedKeys(t *testing.T) {
service := kobject.ServiceConfig{
ContainerName: "name",
Image: "image",
}
service1 := kobject.ServiceConfig{
ContainerName: "name",
Image: "image",
}
c := []string{"a", "b"}

komposeObject := kobject.KomposeObject{
ServiceConfigs: map[string]kobject.ServiceConfig{"b": service, "a": service1},
}
a := SortedKeys(komposeObject)
if !reflect.DeepEqual(a, c) {
t.Logf("Test Fail output should be %s", c)
}
}
9 changes: 1 addition & 8 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package kubernetes
import (
"fmt"
"reflect"
"sort"
"strconv"
"time"

Expand Down Expand Up @@ -533,13 +532,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
// this will hold all the converted data
var allobjects []runtime.Object

// Need to ensure the kubernetes objects are in a consistent order
var sortedKeys []string
for name := range komposeObject.ServiceConfigs {
sortedKeys = append(sortedKeys, name)
}
sort.Strings(sortedKeys)

sortedKeys := SortedKeys(komposeObject)
for _, name := range sortedKeys {
service := komposeObject.ServiceConfigs[name]
var objects []runtime.Object
Expand Down
4 changes: 3 additions & 1 deletion pkg/transformer/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
buildRepo := opt.BuildRepo
buildBranch := opt.BuildBranch

for name, service := range komposeObject.ServiceConfigs {
sortedKeys := kubernetes.SortedKeys(komposeObject)
for _, name := range sortedKeys {
service := komposeObject.ServiceConfigs[name]
var objects []runtime.Object

// Generate pod only and nothing more
Expand Down

0 comments on commit f66a11f

Please sign in to comment.