From a5a2b94c5f7bd2ae2a180a0f0b9b9581b950338a Mon Sep 17 00:00:00 2001 From: Weixu Zhuang Date: Fri, 20 Nov 2015 11:37:24 -0800 Subject: [PATCH] In pkg/kubectl/describe.go function Matches support unordered types matches. The argument of function need to be matched. It did not support unorder matches. This is a TODO and I fix it.(line 1763 in pkg/kubectl/describe.go) I use a map to solve it which could compare two types array's difference. --- pkg/kubectl/describe.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index 788f898d59a..da3353cbd9e 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -1732,13 +1732,18 @@ type typeFunc struct { } // Matches returns true when the passed types exactly match the Extra list. -// TODO: allow unordered types to be matched and reorderd. func (fn typeFunc) Matches(types []reflect.Type) bool { if len(fn.Extra) != len(types) { return false } + // reorder the items in array types and fn.Extra + // convert the type into string and sort them, check if they are matched + varMap := make(map[reflect.Type]bool) + for i := range fn.Extra { + varMap[fn.Extra[i]] = true + } for i := range types { - if fn.Extra[i] != types[i] { + if _, found := varMap[types[i]]; !found { return false } }