mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 16:42:51 +00:00
correct ordering of the k8s objects:
NameSpace, CRD, ServiceAccount, Role, ClusterRole, RoleBinding, ClusterRoleBinding
This commit is contained in:
@@ -37,12 +37,27 @@ func (a IdSlice) Less(i, j int) bool {
|
||||
return a[i].Name() < a[j].Name()
|
||||
}
|
||||
|
||||
func gvkLess(i, j schema.GroupVersionKind) bool {
|
||||
if i.Kind == "Namespace" {
|
||||
return true
|
||||
} else if j.Kind == "Namespace" {
|
||||
return false
|
||||
} else {
|
||||
return i.String() < j.String()
|
||||
}
|
||||
var typeOrders = map[string]int{
|
||||
"Namespace": 0,
|
||||
"CustomResourceDefinition": 1,
|
||||
"ServiceAccount": 2,
|
||||
"Role": 3,
|
||||
"ClusterRole": 4,
|
||||
"RoleBinding": 5,
|
||||
"ClusterRoleBinding": 6,
|
||||
}
|
||||
|
||||
func gvkLess(i, j schema.GroupVersionKind) bool {
|
||||
indexi, foundi := typeOrders[i.Kind]
|
||||
indexj, foundj := typeOrders[j.Kind]
|
||||
if foundi && foundj {
|
||||
return indexi < indexj
|
||||
}
|
||||
if foundi && !foundj {
|
||||
return true
|
||||
}
|
||||
if !foundi && foundj {
|
||||
return false
|
||||
}
|
||||
return i.String() < j.String()
|
||||
}
|
||||
|
||||
@@ -31,10 +31,18 @@ func TestLess(t *testing.T) {
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"),
|
||||
}
|
||||
expected := IdSlice{
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "ConfigMap"}, "cm"),
|
||||
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user