Created
October 3, 2017 17:51
-
-
Save ncdc/edc1ed3abefa36d9650a524ebd5f3f8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go | |
index 18c6c2b745..3e57720b12 100644 | |
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go | |
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go | |
@@ -18,12 +18,12 @@ package customresource | |
import ( | |
"fmt" | |
+ "reflect" | |
"github.com/go-openapi/validate" | |
"k8s.io/apimachinery/pkg/api/meta" | |
"k8s.io/apimachinery/pkg/api/validation" | |
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | |
"k8s.io/apimachinery/pkg/fields" | |
"k8s.io/apimachinery/pkg/labels" | |
@@ -92,20 +92,31 @@ func (a customResourceDefinitionStorageStrategy) GetAttrs(obj runtime.Object) (l | |
if err != nil { | |
return nil, nil, false, err | |
} | |
- return labels.Set(accessor.GetLabels()), objectMetaFieldsSet(accessor, a.namespaceScoped), accessor.GetInitializers() != nil, nil | |
-} | |
- | |
-// objectMetaFieldsSet returns a fields that represent the ObjectMeta. | |
-func objectMetaFieldsSet(objectMeta metav1.Object, namespaceScoped bool) fields.Set { | |
- if namespaceScoped { | |
- return fields.Set{ | |
- "metadata.name": objectMeta.GetName(), | |
- "metadata.namespace": objectMeta.GetNamespace(), | |
+ customResourceObject := obj.(*unstructured.Unstructured) | |
+ customResource := customResourceObject.UnstructuredContent() | |
+ f := make(fields.Set) | |
+ customResourceFieldSet(customResource, "", f) | |
+ return labels.Set(accessor.GetLabels()), f, accessor.GetInitializers() != nil, nil | |
+} | |
+ | |
+func customResourceFieldSet(item map[string]interface{}, parent string, f fields.Set) { | |
+ var prefix string | |
+ if parent != "" { | |
+ prefix = parent + "." | |
+ } | |
+ for k, v := range item { | |
+ rv := reflect.ValueOf(v) | |
+ | |
+ switch rv.Kind() { | |
+ case reflect.Map: | |
+ customResourceFieldSet(v.(map[string]interface{}), prefix+k, f) | |
+ case reflect.Slice: | |
+ continue | |
+ default: | |
+ fmt.Printf("ANDY k=%s, type=%T\n", k, v) | |
+ f[prefix+k] = fmt.Sprintf("%v", v) | |
} | |
} | |
- return fields.Set{ | |
- "metadata.name": objectMeta.GetName(), | |
- } | |
} | |
func (a customResourceDefinitionStorageStrategy) MatchCustomResourceDefinitionStorage(label labels.Selector, field fields.Selector) storage.SelectionPredicate { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment