bug(tiller): sort unknown but different kinds alphabetically based on kind name

Adds additional manifest sorting logic so that different unknown kinds
are sorted alphabetically so that manifest order is more deterministic.

(cherry picked from commit ed24b3199a)
release-2.6
Justin Scott 8 years ago committed by Matthew Fisher
parent 5f1defd072
commit 685994aecf

@ -116,8 +116,12 @@ func (k *kindSorter) Less(i, j int) bool {
b := k.manifests[j] b := k.manifests[j]
first, aok := k.ordering[a.head.Kind] first, aok := k.ordering[a.head.Kind]
second, bok := k.ordering[b.head.Kind] second, bok := k.ordering[b.head.Kind]
// if same kind (including unknown) sub sort alphanumeric
if first == second { if first == second {
// same kind (including unknown) so sub sort alphanumeric // if both are unknown and of different kind sort by kind alphabetically
if !aok && !bok && a.head.Kind != b.head.Kind {
return a.head.Kind < b.head.Kind
}
return a.name < b.name return a.name < b.name
} }
// unknown kind is last // unknown kind is last

@ -176,7 +176,7 @@ func TestKindSorterSubSort(t *testing.T) {
head: &util.SimpleHead{Kind: "ClusterRoleBinding"}, head: &util.SimpleHead{Kind: "ClusterRoleBinding"},
}, },
{ {
name: "u3", name: "u2",
head: &util.SimpleHead{Kind: "Unknown"}, head: &util.SimpleHead{Kind: "Unknown"},
}, },
{ {
@ -184,8 +184,8 @@ func TestKindSorterSubSort(t *testing.T) {
head: &util.SimpleHead{Kind: "Unknown"}, head: &util.SimpleHead{Kind: "Unknown"},
}, },
{ {
name: "u2", name: "t3",
head: &util.SimpleHead{Kind: "Unknown"}, head: &util.SimpleHead{Kind: "Unknown2"},
}, },
} }
for _, test := range []struct { for _, test := range []struct {
@ -194,7 +194,7 @@ func TestKindSorterSubSort(t *testing.T) {
expected string expected string
}{ }{
// expectation is sorted by kind (unknown is last) and then sub sorted alphabetically within each group // expectation is sorted by kind (unknown is last) and then sub sorted alphabetically within each group
{"cm,clusterRole,clusterRoleBinding,Unknown", InstallOrder, "01Aa!zu1u2u3"}, {"cm,clusterRole,clusterRoleBinding,Unknown,Unknown2", InstallOrder, "01Aa!zu1u2t3"},
} { } {
var buf bytes.Buffer var buf bytes.Buffer
t.Run(test.description, func(t *testing.T) { t.Run(test.description, func(t *testing.T) {

Loading…
Cancel
Save