From 486d8ef229d10b3210de339d81080f5786391ccc Mon Sep 17 00:00:00 2001 From: deads2k Date: Tue, 18 Jul 2017 13:40:22 -0400 Subject: [PATCH] add a union category expander --- pkg/kubectl/resource/categories.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/kubectl/resource/categories.go b/pkg/kubectl/resource/categories.go index e547ab1ed7b..4fe11225c3d 100644 --- a/pkg/kubectl/resource/categories.go +++ b/pkg/kubectl/resource/categories.go @@ -79,6 +79,33 @@ func (e discoveryFilteredExpander) Expand(category string) ([]schema.GroupResour return available, ok } +type UnionCategoryExpander []CategoryExpander + +func (u UnionCategoryExpander) Expand(category string) ([]schema.GroupResource, bool) { + ret := []schema.GroupResource{} + ok := false + + for _, expansion := range u { + curr, currOk := expansion.Expand(category) + + for _, currGR := range curr { + found := false + for _, existing := range ret { + if existing == currGR { + found = true + break + } + } + if !found { + ret = append(ret, currGR) + } + } + ok = ok || currOk + } + + return ret, ok +} + // legacyUserResources are the resource names that apply to the primary, user facing resources used by // client tools. They are in deletion-first order - dependent resources should be last. // Should remain exported in order to expose a current list of resources to downstream