mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
add fallback for GVK comparison
only return comparison of 'Kind' indices if they do not match otherwise fall back to GVK string comparison this reduces output instability
This commit is contained in:
@@ -97,8 +97,10 @@ func (x Gvk) IsLessThan(o Gvk) bool {
|
|||||||
indexI, foundI := typeOrders[x.Kind]
|
indexI, foundI := typeOrders[x.Kind]
|
||||||
indexJ, foundJ := typeOrders[o.Kind]
|
indexJ, foundJ := typeOrders[o.Kind]
|
||||||
if foundI && foundJ {
|
if foundI && foundJ {
|
||||||
|
if indexI != indexJ {
|
||||||
return indexI < indexJ
|
return indexI < indexJ
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if foundI && !foundJ {
|
if foundI && !foundJ {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,16 @@ var lessThanTests = []struct {
|
|||||||
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
|
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
|
||||||
{Gvk{Group: "a", Version: "b", Kind: "a"},
|
{Gvk{Group: "a", Version: "b", Kind: "a"},
|
||||||
Gvk{Group: "a", Version: "b", Kind: "b"}},
|
Gvk{Group: "a", Version: "b", Kind: "b"}},
|
||||||
|
{Gvk{Group: "a", Version: "b", Kind: "Namespace"},
|
||||||
|
Gvk{Group: "a", Version: "c", Kind: "Namespace"}},
|
||||||
|
{Gvk{Group: "a", Version: "c", Kind: "Namespace"},
|
||||||
|
Gvk{Group: "b", Version: "c", Kind: "Namespace"}},
|
||||||
|
{Gvk{Group: "b", Version: "c", Kind: "Namespace"},
|
||||||
|
Gvk{Group: "a", Version: "c", Kind: "ClusterRole"}},
|
||||||
|
{Gvk{Group: "a", Version: "c", Kind: "Namespace"},
|
||||||
|
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
|
||||||
|
{Gvk{Group: "a", Version: "d", Kind: "Namespace"},
|
||||||
|
Gvk{Group: "b", Version: "c", Kind: "Namespace"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsLessThan1(t *testing.T) {
|
func TestIsLessThan1(t *testing.T) {
|
||||||
@@ -55,6 +65,9 @@ func TestIsLessThan1(t *testing.T) {
|
|||||||
if !hey.x1.IsLessThan(hey.x2) {
|
if !hey.x1.IsLessThan(hey.x2) {
|
||||||
t.Fatalf("%v should be less than %v", hey.x1, hey.x2)
|
t.Fatalf("%v should be less than %v", hey.x1, hey.x2)
|
||||||
}
|
}
|
||||||
|
if hey.x2.IsLessThan(hey.x1) {
|
||||||
|
t.Fatalf("%v should not be less than %v", hey.x2, hey.x1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user