populate the map from a slice

This commit is contained in:
Jingfang Liu
2018-06-22 10:19:41 -07:00
parent 636ab874eb
commit 991ffbbdfc

View File

@@ -37,15 +37,15 @@ func (a IdSlice) Less(i, j int) bool {
return a[i].Name() < a[j].Name() return a[i].Name() < a[j].Name()
} }
var typeOrders = map[string]int{ var order = []string{"Namespace", "CustomResourceDefinition", "ServiceAccount",
"Namespace": 0, "Role", "ClusterRole", "RoleBinding", "ClusterRoleBinding"}
"CustomResourceDefinition": 1, var typeOrders = func() map[string]int {
"ServiceAccount": 2, m := map[string]int{}
"Role": 3, for i, n := range order {
"ClusterRole": 4, m[n] = i
"RoleBinding": 5, }
"ClusterRoleBinding": 6, return m
} }()
func gvkLess(i, j schema.GroupVersionKind) bool { func gvkLess(i, j schema.GroupVersionKind) bool {
indexi, foundi := typeOrders[i.Kind] indexi, foundi := typeOrders[i.Kind]