From 991ffbbdfc2ad37c3e0178a974b3c388a2e27174 Mon Sep 17 00:00:00 2001 From: Jingfang Liu Date: Fri, 22 Jun 2018 10:19:41 -0700 Subject: [PATCH] populate the map from a slice --- pkg/resmap/idslice.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/resmap/idslice.go b/pkg/resmap/idslice.go index 7d04230dc..3b4652608 100644 --- a/pkg/resmap/idslice.go +++ b/pkg/resmap/idslice.go @@ -37,15 +37,15 @@ func (a IdSlice) Less(i, j int) bool { return a[i].Name() < a[j].Name() } -var typeOrders = map[string]int{ - "Namespace": 0, - "CustomResourceDefinition": 1, - "ServiceAccount": 2, - "Role": 3, - "ClusterRole": 4, - "RoleBinding": 5, - "ClusterRoleBinding": 6, -} +var order = []string{"Namespace", "CustomResourceDefinition", "ServiceAccount", + "Role", "ClusterRole", "RoleBinding", "ClusterRoleBinding"} +var typeOrders = func() map[string]int { + m := map[string]int{} + for i, n := range order { + m[n] = i + } + return m +}() func gvkLess(i, j schema.GroupVersionKind) bool { indexi, foundi := typeOrders[i.Kind]