mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Merge pull request #7266 from bradskuse/kind-sorter-helm3
Fix: helm3 - kind sorter incorrectly compares unknown and namespace
This commit is contained in:
commit
8c84a0bc03
2 changed files with 26 additions and 3 deletions
|
|
@ -134,11 +134,13 @@ func (k *kindSorter) Less(i, j int) bool {
|
|||
b := k.manifests[j]
|
||||
first, aok := k.ordering[a.Head.Kind]
|
||||
second, bok := k.ordering[b.Head.Kind]
|
||||
if first == second {
|
||||
// if both are unknown and of different kind sort by kind alphabetically
|
||||
if !aok && !bok && a.Head.Kind != b.Head.Kind {
|
||||
|
||||
if !aok && !bok {
|
||||
// if both are unknown then sort alphabetically by kind, keep original order if same kind
|
||||
if a.Head.Kind != b.Head.Kind {
|
||||
return a.Head.Kind < b.Head.Kind
|
||||
}
|
||||
return first < second
|
||||
}
|
||||
// unknown kind is last
|
||||
if !aok {
|
||||
|
|
|
|||
|
|
@ -245,3 +245,24 @@ func TestKindSorterKeepOriginalOrder(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestKindSorterNamespaceAgainstUnknown(t *testing.T) {
|
||||
unknown := Manifest{
|
||||
Name: "a",
|
||||
Head: &SimpleHead{Kind: "Unknown"},
|
||||
}
|
||||
namespace := Manifest{
|
||||
Name: "b",
|
||||
Head: &SimpleHead{Kind: "Namespace"},
|
||||
}
|
||||
|
||||
manifests := []Manifest{unknown, namespace}
|
||||
sortByKind(manifests, InstallOrder)
|
||||
|
||||
expectedOrder := []Manifest{namespace, unknown}
|
||||
for i, manifest := range manifests {
|
||||
if expectedOrder[i].Name != manifest.Name {
|
||||
t.Errorf("Expected %s, got %s", expectedOrder[i].Name, manifest.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue