Commit 685994ae authored by Justin Scott's avatar Justin Scott Committed by Matthew Fisher
Browse files

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 ed24b319)
No related merge requests found
Showing with 9 additions and 5 deletions
+9 -5
...@@ -116,8 +116,12 @@ func (k *kindSorter) Less(i, j int) bool { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment