From 67f6754e0fe95b33a652eb3a9a5af35e36d6ebf0 Mon Sep 17 00:00:00 2001 From: AdoHe Date: Sat, 19 Nov 2016 13:03:39 +0800 Subject: [PATCH] kubectl resource filter convert unstructured obj before apply filter func --- pkg/kubectl/resource_filter.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/kubectl/resource_filter.go b/pkg/kubectl/resource_filter.go index 8ca31d83ac3..cd6470ba23e 100644 --- a/pkg/kubectl/resource_filter.go +++ b/pkg/kubectl/resource_filter.go @@ -58,6 +58,17 @@ func filterPods(obj runtime.Object, options PrintOptions) bool { // Filter loops through a collection of FilterFuncs until it finds one that can filter the given resource func (f Filters) Filter(obj runtime.Object, opts *PrintOptions) (bool, error) { + // check if the object is unstructured. If so, let's attempt to convert it to a type we can understand + // before apply filter func. + switch obj.(type) { + case *runtime.UnstructuredList, *runtime.Unstructured, *runtime.Unknown: + if objBytes, err := runtime.Encode(api.Codecs.LegacyCodec(), obj); err == nil { + if decodedObj, err := runtime.Decode(api.Codecs.UniversalDecoder(), objBytes); err == nil { + obj = decodedObj + } + } + } + for _, filter := range f { if ok := filter(obj, *opts); ok { return true, nil