From b6b8323d07aa767f5ee2038f2531517506e873da Mon Sep 17 00:00:00 2001 From: David Eads Date: Wed, 23 Aug 2017 16:16:30 -0400 Subject: [PATCH] add legacy field selector for names --- hack/import-restrictions.json | 12 +--- pkg/api/legacy/fields.go | 16 +++++ pkg/build/apis/build/fields.go | 9 --- pkg/build/apis/build/v1/conversion.go | 15 ++++- pkg/build/apis/build/v1/conversion_test.go | 7 --- pkg/build/apis/build/v1/register.go | 2 +- pkg/build/registry/buildconfig/etcd/etcd.go | 3 +- pkg/build/registry/buildconfig/strategy.go | 23 ------- pkg/deploy/apis/apps/fields.go | 11 ---- pkg/deploy/apis/apps/v1/conversion.go | 6 -- pkg/deploy/apis/apps/v1/conversion_test.go | 8 --- pkg/deploy/registry/deployconfig/etcd/etcd.go | 3 +- pkg/deploy/registry/deployconfig/strategy.go | 22 ------- pkg/image/apis/image/fields.go | 8 --- pkg/image/apis/image/v1/conversion.go | 6 -- pkg/image/apis/image/v1/conversion_test.go | 4 -- pkg/image/registry/image/etcd/etcd.go | 3 +- pkg/image/registry/image/strategy.go | 27 -------- pkg/oauth/apis/oauth/fields.go | 7 --- pkg/oauth/apis/oauth/v1/conversion.go | 6 -- pkg/oauth/apis/oauth/v1/conversion_test.go | 5 -- pkg/oauth/registry/oauthclient/etcd/etcd.go | 3 +- pkg/oauth/registry/oauthclient/strategy.go | 28 --------- pkg/quota/apis/quota/fields.go | 9 --- .../appliedclusterresourcequota/filter.go | 15 ++++- .../clusterresourcequota/etcd/etcd.go | 3 +- .../registry/clusterresourcequota/strategy.go | 23 ------- pkg/sdn/apis/network/fields.go | 32 ---------- pkg/sdn/apis/network/v1/conversion.go | 63 ------------------- pkg/sdn/apis/network/v1/conversion_test.go | 55 ---------------- pkg/sdn/apis/network/v1/register.go | 4 +- pkg/sdn/registry/clusternetwork/etcd/etcd.go | 3 +- pkg/sdn/registry/clusternetwork/strategy.go | 28 --------- .../registry/egressnetworkpolicy/etcd/etcd.go | 3 +- .../registry/egressnetworkpolicy/strategy.go | 28 --------- pkg/sdn/registry/hostsubnet/etcd/etcd.go | 3 +- pkg/sdn/registry/hostsubnet/strategy.go | 28 --------- pkg/sdn/registry/netnamespace/etcd/etcd.go | 3 +- pkg/sdn/registry/netnamespace/strategy.go | 28 --------- pkg/user/apis/user/fields.go | 16 ----- pkg/user/apis/user/v1/conversion.go | 11 ---- pkg/user/apis/user/v1/conversion_test.go | 9 --- pkg/user/registry/group/etcd/etcd.go | 3 +- pkg/user/registry/group/strategy.go | 28 --------- pkg/user/registry/user/etcd/etcd.go | 3 +- pkg/user/registry/user/strategy.go | 28 --------- 46 files changed, 58 insertions(+), 602 deletions(-) create mode 100644 pkg/api/legacy/fields.go delete mode 100644 pkg/deploy/apis/apps/fields.go delete mode 100644 pkg/quota/apis/quota/fields.go delete mode 100644 pkg/sdn/apis/network/fields.go delete mode 100644 pkg/sdn/apis/network/v1/conversion.go delete mode 100644 pkg/sdn/apis/network/v1/conversion_test.go diff --git a/hack/import-restrictions.json b/hack/import-restrictions.json index 0cee08df95f6..2b7ce43cf702 100644 --- a/hack/import-restrictions.json +++ b/hack/import-restrictions.json @@ -40,7 +40,7 @@ "vendor/k8s.io/kubernetes/pkg/api", "vendor/k8s.io/kubernetes/pkg/api/v1", "github.com/openshift/origin/pkg/api", - "github.com/openshift/origin/pkg/api", + "github.com/openshift/origin/pkg/api/legacy", "github.com/openshift/origin/pkg/api/install", "github.com/openshift/origin/pkg/util/namer", "github.com/openshift/origin/pkg/build/util", @@ -67,10 +67,8 @@ "vendor/k8s.io/kubernetes/pkg/apis/extensions/v1beta1", "vendor/k8s.io/kubernetes/pkg/api/helper", "vendor/k8s.io/kubernetes/pkg/api/install", - "github.com/openshift/origin/pkg/api", "github.com/openshift/origin/pkg/deploy/apis/apps/install", - "github.com/openshift/origin/pkg/image/apis/image", - "github.com/openshift/origin/test/util/api" + "github.com/openshift/origin/pkg/image/apis/image" ] }, @@ -182,11 +180,7 @@ "vendor/k8s.io/apimachinery", "vendor/github.com/gogo/protobuf" ], - "allowedImportPackages": [ - "github.com/openshift/origin/pkg/api", - "github.com/openshift/origin/pkg/api/install", - "github.com/openshift/origin/test/util/api" - ] + "allowedImportPackages": [] }, { diff --git a/pkg/api/legacy/fields.go b/pkg/api/legacy/fields.go new file mode 100644 index 000000000000..b38e58c8e2bc --- /dev/null +++ b/pkg/api/legacy/fields.go @@ -0,0 +1,16 @@ +package legacy + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +// LegacyMetaV1FieldSelectorConversionWithName auto-accepts metav1 values for name and namespace AND "name" +// which many of our older resources used. +func LegacyMetaV1FieldSelectorConversionWithName(label, value string) (string, string, error) { + switch label { + case "name": + return "metadata.name", value, nil + default: + return runtime.DefaultMetaV1FieldSelectorConversion(label, value) + } +} diff --git a/pkg/build/apis/build/fields.go b/pkg/build/apis/build/fields.go index 10b1bffa666b..741bbf01f260 100644 --- a/pkg/build/apis/build/fields.go +++ b/pkg/build/apis/build/fields.go @@ -12,12 +12,3 @@ func BuildToSelectableFields(build *Build) fields.Set { "podName": GetBuildPodName(build), } } - -// BuildConfigToSelectableFields returns a label set that represents the object -// changes to the returned keys require registering conversions for existing versions using Scheme.AddFieldLabelConversionFunc -func BuildConfigToSelectableFields(buildConfig *BuildConfig) fields.Set { - return fields.Set{ - "metadata.name": buildConfig.Name, - "metadata.namespace": buildConfig.Namespace, - } -} diff --git a/pkg/build/apis/build/v1/conversion.go b/pkg/build/apis/build/v1/conversion.go index 815fd55f32c7..c81df65301a4 100644 --- a/pkg/build/apis/build/v1/conversion.go +++ b/pkg/build/apis/build/v1/conversion.go @@ -5,6 +5,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" oapi "github.com/openshift/origin/pkg/api" + "github.com/openshift/origin/pkg/api/legacy" newer "github.com/openshift/origin/pkg/build/apis/build" buildutil "github.com/openshift/origin/pkg/build/util" imageapi "github.com/openshift/origin/pkg/image/apis/image" @@ -174,15 +175,23 @@ func addConversionFuncs(scheme *runtime.Scheme) error { return err } + if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Build", + oapi.GetFieldLabelConversionFunc(newer.BuildToSelectableFields(&newer.Build{}), nil), + ); err != nil { + return err + } + + return nil +} + +func addLegacyFieldLabelConversions(scheme *runtime.Scheme) error { if err := scheme.AddFieldLabelConversionFunc("v1", "Build", oapi.GetFieldLabelConversionFunc(newer.BuildToSelectableFields(&newer.Build{}), map[string]string{"name": "metadata.name"}), ); err != nil { return err } - if err := scheme.AddFieldLabelConversionFunc("v1", "BuildConfig", - oapi.GetFieldLabelConversionFunc(newer.BuildConfigToSelectableFields(&newer.BuildConfig{}), map[string]string{"name": "metadata.name"}), - ); err != nil { + if err := scheme.AddFieldLabelConversionFunc("v1", "BuildConfig", legacy.LegacyMetaV1FieldSelectorConversionWithName); err != nil { return err } return nil diff --git a/pkg/build/apis/build/v1/conversion_test.go b/pkg/build/apis/build/v1/conversion_test.go index 158fa05bc0cf..ceb550343be8 100644 --- a/pkg/build/apis/build/v1/conversion_test.go +++ b/pkg/build/apis/build/v1/conversion_test.go @@ -23,13 +23,6 @@ func TestFieldSelectorConversions(t *testing.T) { // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST "name", "status", "podName", ) - - testutil.CheckFieldLabelConversions(t, "v1", "BuildConfig", - // Ensure all currently returned labels are supported - newer.BuildConfigToSelectableFields(&newer.BuildConfig{}), - // Ensure previously supported labels have conversions. DO NOT REMOVE THINGS FROM THIS LIST - "name", - ) } func TestBinaryBuildRequestOptions(t *testing.T) { diff --git a/pkg/build/apis/build/v1/register.go b/pkg/build/apis/build/v1/register.go index b5f832d3fc66..fd3ac9dd810b 100644 --- a/pkg/build/apis/build/v1/register.go +++ b/pkg/build/apis/build/v1/register.go @@ -13,7 +13,7 @@ var ( SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes, addConversionFuncs, RegisterDefaults) + LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes, addConversionFuncs, RegisterDefaults, addLegacyFieldLabelConversions) AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes, addConversionFuncs, RegisterDefaults) diff --git a/pkg/build/registry/buildconfig/etcd/etcd.go b/pkg/build/registry/buildconfig/etcd/etcd.go index a8ee6eb6ac7c..16b05b2c758f 100644 --- a/pkg/build/registry/buildconfig/etcd/etcd.go +++ b/pkg/build/registry/buildconfig/etcd/etcd.go @@ -25,14 +25,13 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { NewFunc: func() runtime.Object { return &buildapi.BuildConfig{} }, NewListFunc: func() runtime.Object { return &buildapi.BuildConfigList{} }, DefaultQualifiedResource: buildapi.Resource("buildconfigs"), - PredicateFunc: buildconfig.Matcher, CreateStrategy: buildconfig.GroupStrategy, UpdateStrategy: buildconfig.GroupStrategy, DeleteStrategy: buildconfig.GroupStrategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: buildconfig.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/build/registry/buildconfig/strategy.go b/pkg/build/registry/buildconfig/strategy.go index 0511762695d9..d5e3cb3e5ddf 100644 --- a/pkg/build/registry/buildconfig/strategy.go +++ b/pkg/build/registry/buildconfig/strategy.go @@ -1,16 +1,11 @@ package buildconfig import ( - "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - kstorage "k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage/names" kapi "k8s.io/kubernetes/pkg/api" @@ -125,24 +120,6 @@ func (s legacyStrategy) DefaultGarbageCollectionPolicy() rest.GarbageCollectionP return rest.OrphanDependents } -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) { - buildConfig, ok := obj.(*buildapi.BuildConfig) - if !ok { - return nil, nil, false, fmt.Errorf("not a BuildConfig") - } - return labels.Set(buildConfig.ObjectMeta.Labels), buildapi.BuildConfigToSelectableFields(buildConfig), buildConfig.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) kstorage.SelectionPredicate { - return kstorage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - // CheckGracefulDelete allows a build config to be gracefully deleted. func (strategy) CheckGracefulDelete(obj runtime.Object, options *metav1.DeleteOptions) bool { return false diff --git a/pkg/deploy/apis/apps/fields.go b/pkg/deploy/apis/apps/fields.go deleted file mode 100644 index 6e90ea155af0..000000000000 --- a/pkg/deploy/apis/apps/fields.go +++ /dev/null @@ -1,11 +0,0 @@ -package apps - -import "k8s.io/apimachinery/pkg/fields" - -// DeploymentConfigToSelectableFields returns a label set that represents the object -func DeploymentConfigToSelectableFields(deploymentConfig *DeploymentConfig) fields.Set { - return fields.Set{ - "metadata.name": deploymentConfig.Name, - "metadata.namespace": deploymentConfig.Namespace, - } -} diff --git a/pkg/deploy/apis/apps/v1/conversion.go b/pkg/deploy/apis/apps/v1/conversion.go index 6a366c1097dd..03d28dc1a934 100644 --- a/pkg/deploy/apis/apps/v1/conversion.go +++ b/pkg/deploy/apis/apps/v1/conversion.go @@ -7,7 +7,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" - oapi "github.com/openshift/origin/pkg/api" newer "github.com/openshift/origin/pkg/deploy/apis/apps" imageapi "github.com/openshift/origin/pkg/image/apis/image" ) @@ -119,10 +118,5 @@ func addConversionFuncs(scheme *runtime.Scheme) error { return err } - if err := scheme.AddFieldLabelConversionFunc("v1", "DeploymentConfig", - oapi.GetFieldLabelConversionFunc(newer.DeploymentConfigToSelectableFields(&newer.DeploymentConfig{}), nil), - ); err != nil { - return err - } return nil } diff --git a/pkg/deploy/apis/apps/v1/conversion_test.go b/pkg/deploy/apis/apps/v1/conversion_test.go index ee0a66e3228a..404f69430a54 100644 --- a/pkg/deploy/apis/apps/v1/conversion_test.go +++ b/pkg/deploy/apis/apps/v1/conversion_test.go @@ -10,7 +10,6 @@ import ( kapiv1 "k8s.io/kubernetes/pkg/api/v1" newer "github.com/openshift/origin/pkg/deploy/apis/apps" - testutil "github.com/openshift/origin/test/util/api" ) func TestTriggerRoundTrip(t *testing.T) { @@ -223,10 +222,3 @@ func newInt32(val int32) *int32 { func newIntOrString(ios intstr.IntOrString) *intstr.IntOrString { return &ios } - -func TestFieldSelectors(t *testing.T) { - testutil.CheckFieldLabelConversions(t, "v1", "DeploymentConfig", - // Ensure all currently returned labels are supported - newer.DeploymentConfigToSelectableFields(&newer.DeploymentConfig{}), - ) -} diff --git a/pkg/deploy/registry/deployconfig/etcd/etcd.go b/pkg/deploy/registry/deployconfig/etcd/etcd.go index 1f55dd836edd..7f50706d4b8b 100644 --- a/pkg/deploy/registry/deployconfig/etcd/etcd.go +++ b/pkg/deploy/registry/deployconfig/etcd/etcd.go @@ -34,7 +34,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, *ScaleREST, err Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &deployapi.DeploymentConfig{} }, NewListFunc: func() runtime.Object { return &deployapi.DeploymentConfigList{} }, - PredicateFunc: deployconfig.Matcher, DefaultQualifiedResource: deployapi.Resource("deploymentconfigs"), CreateStrategy: deployconfig.Strategy, @@ -42,7 +41,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, *ScaleREST, err DeleteStrategy: deployconfig.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: deployconfig.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, nil, nil, err } diff --git a/pkg/deploy/registry/deployconfig/strategy.go b/pkg/deploy/registry/deployconfig/strategy.go index df1c75185836..02cc50bd90a8 100644 --- a/pkg/deploy/registry/deployconfig/strategy.go +++ b/pkg/deploy/registry/deployconfig/strategy.go @@ -1,16 +1,12 @@ package deployconfig import ( - "fmt" "reflect" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" - kstorage "k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage/names" kapi "k8s.io/kubernetes/pkg/api" @@ -124,21 +120,3 @@ func (statusStrategy) PrepareForUpdate(ctx apirequest.Context, obj, old runtime. func (statusStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateDeploymentConfigStatusUpdate(obj.(*deployapi.DeploymentConfig), old.(*deployapi.DeploymentConfig)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) { - deploymentConfig, ok := obj.(*deployapi.DeploymentConfig) - if !ok { - return nil, nil, false, fmt.Errorf("not a DeploymentConfig") - } - return labels.Set(deploymentConfig.ObjectMeta.Labels), deployapi.DeploymentConfigToSelectableFields(deploymentConfig), deploymentConfig.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) kstorage.SelectionPredicate { - return kstorage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} diff --git a/pkg/image/apis/image/fields.go b/pkg/image/apis/image/fields.go index 1a2d948bdf1f..dc395aeb6f11 100644 --- a/pkg/image/apis/image/fields.go +++ b/pkg/image/apis/image/fields.go @@ -2,14 +2,6 @@ package image import "k8s.io/apimachinery/pkg/fields" -// ImageToSelectableFields returns a label set that represents the object. -func ImageToSelectableFields(image *Image) fields.Set { - return fields.Set{ - "metadata.name": image.Name, - "metadata.namespace": image.Namespace, - } -} - // ImageStreamToSelectableFields returns a label set that represents the object. func ImageStreamToSelectableFields(ir *ImageStream) fields.Set { return fields.Set{ diff --git a/pkg/image/apis/image/v1/conversion.go b/pkg/image/apis/image/v1/conversion.go index 9c18f4aecf63..9c090e8b002d 100644 --- a/pkg/image/apis/image/v1/conversion.go +++ b/pkg/image/apis/image/v1/conversion.go @@ -280,12 +280,6 @@ func addConversionFuncs(scheme *runtime.Scheme) error { return err } - if err := scheme.AddFieldLabelConversionFunc("v1", "Image", - oapi.GetFieldLabelConversionFunc(newer.ImageToSelectableFields(&newer.Image{}), nil), - ); err != nil { - return err - } - if err := scheme.AddFieldLabelConversionFunc("v1", "ImageStream", oapi.GetFieldLabelConversionFunc(newer.ImageStreamToSelectableFields(&newer.ImageStream{}), map[string]string{"name": "metadata.name"}), ); err != nil { diff --git a/pkg/image/apis/image/v1/conversion_test.go b/pkg/image/apis/image/v1/conversion_test.go index d318fcfd3a91..53c0902588fa 100644 --- a/pkg/image/apis/image/v1/conversion_test.go +++ b/pkg/image/apis/image/v1/conversion_test.go @@ -50,10 +50,6 @@ func TestRoundTripVersionedObject(t *testing.T) { } func TestFieldSelectors(t *testing.T) { - testutil.CheckFieldLabelConversions(t, "v1", "Image", - // Ensure all currently returned labels are supported - newer.ImageToSelectableFields(&newer.Image{}), - ) testutil.CheckFieldLabelConversions(t, "v1", "ImageStream", // Ensure all currently returned labels are supported newer.ImageStreamToSelectableFields(&newer.ImageStream{}), diff --git a/pkg/image/registry/image/etcd/etcd.go b/pkg/image/registry/image/etcd/etcd.go index 7986e249cb74..ea05832e38bc 100644 --- a/pkg/image/registry/image/etcd/etcd.go +++ b/pkg/image/registry/image/etcd/etcd.go @@ -25,7 +25,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &imageapi.Image{} }, NewListFunc: func() runtime.Object { return &imageapi.ImageList{} }, - PredicateFunc: image.Matcher, DefaultQualifiedResource: imageapi.Resource("images"), CreateStrategy: image.Strategy, @@ -33,7 +32,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: image.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: image.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/image/registry/image/strategy.go b/pkg/image/registry/image/strategy.go index 70162a74faaf..229b4ef2b958 100644 --- a/pkg/image/registry/image/strategy.go +++ b/pkg/image/registry/image/strategy.go @@ -3,15 +3,11 @@ package image import ( "fmt" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" - "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/rest" - kstorage "k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage/names" kapi "k8s.io/kubernetes/pkg/api" @@ -125,26 +121,3 @@ func (s imageStrategy) PrepareForUpdate(ctx apirequest.Context, obj, old runtime func (imageStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateImageUpdate(old.(*imageapi.Image), obj.(*imageapi.Image)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*imageapi.Image) - if !ok { - return nil, nil, false, fmt.Errorf("not an Image") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) kstorage.SelectionPredicate { - return kstorage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *imageapi.Image) fields.Set { - return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false) -} diff --git a/pkg/oauth/apis/oauth/fields.go b/pkg/oauth/apis/oauth/fields.go index 7862a0234cc5..6f6413b78945 100644 --- a/pkg/oauth/apis/oauth/fields.go +++ b/pkg/oauth/apis/oauth/fields.go @@ -23,13 +23,6 @@ func OAuthAuthorizeTokenToSelectableFields(obj *OAuthAuthorizeToken) fields.Set } } -// OAuthClientToSelectableFields returns a label set that represents the object -func OAuthClientToSelectableFields(obj *OAuthClient) fields.Set { - return fields.Set{ - "metadata.name": obj.Name, - } -} - // OAuthClientAuthorizationToSelectableFields returns a label set that represents the object func OAuthClientAuthorizationToSelectableFields(obj *OAuthClientAuthorization) fields.Set { return fields.Set{ diff --git a/pkg/oauth/apis/oauth/v1/conversion.go b/pkg/oauth/apis/oauth/v1/conversion.go index c594c17eed0b..1353a3b4269c 100644 --- a/pkg/oauth/apis/oauth/v1/conversion.go +++ b/pkg/oauth/apis/oauth/v1/conversion.go @@ -20,12 +20,6 @@ func addConversionFuncs(scheme *runtime.Scheme) error { return err } - if err := scheme.AddFieldLabelConversionFunc("v1", "OAuthClient", - oapi.GetFieldLabelConversionFunc(oauthapi.OAuthClientToSelectableFields(&oauthapi.OAuthClient{}), nil), - ); err != nil { - return err - } - if err := scheme.AddFieldLabelConversionFunc("v1", "OAuthClientAuthorization", oapi.GetFieldLabelConversionFunc(oauthapi.OAuthClientAuthorizationToSelectableFields(&oauthapi.OAuthClientAuthorization{}), nil), ); err != nil { diff --git a/pkg/oauth/apis/oauth/v1/conversion_test.go b/pkg/oauth/apis/oauth/v1/conversion_test.go index cfc867e5439a..c83a8c3004c5 100644 --- a/pkg/oauth/apis/oauth/v1/conversion_test.go +++ b/pkg/oauth/apis/oauth/v1/conversion_test.go @@ -25,11 +25,6 @@ func TestFieldSelectorConversions(t *testing.T) { "clientName", "userName", "userUID", ) - testutil.CheckFieldLabelConversions(t, "v1", "OAuthClient", - // Ensure all currently returned labels are supported - oauthapi.OAuthClientToSelectableFields(&oauthapi.OAuthClient{}), - ) - testutil.CheckFieldLabelConversions(t, "v1", "OAuthClientAuthorization", // Ensure all currently returned labels are supported oauthapi.OAuthClientAuthorizationToSelectableFields(&oauthapi.OAuthClientAuthorization{}), diff --git a/pkg/oauth/registry/oauthclient/etcd/etcd.go b/pkg/oauth/registry/oauthclient/etcd/etcd.go index b7e418ea7322..3f733243368b 100644 --- a/pkg/oauth/registry/oauthclient/etcd/etcd.go +++ b/pkg/oauth/registry/oauthclient/etcd/etcd.go @@ -25,7 +25,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &oauthapi.OAuthClient{} }, NewListFunc: func() runtime.Object { return &oauthapi.OAuthClientList{} }, - PredicateFunc: oauthclient.Matcher, DefaultQualifiedResource: oauthapi.Resource("oauthclients"), CreateStrategy: oauthclient.Strategy, @@ -33,7 +32,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: oauthclient.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: oauthclient.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/oauth/registry/oauthclient/strategy.go b/pkg/oauth/registry/oauthclient/strategy.go index e67d5d76e510..019ba0c11f18 100644 --- a/pkg/oauth/registry/oauthclient/strategy.go +++ b/pkg/oauth/registry/oauthclient/strategy.go @@ -1,17 +1,12 @@ package oauthclient import ( - "fmt" - oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth" "github.com/openshift/origin/pkg/oauth/apis/oauth/validation" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - kstorage "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" ) @@ -67,26 +62,3 @@ func (strategy) AllowCreateOnUpdate() bool { func (strategy) AllowUnconditionalUpdate() bool { return false } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*oauthapi.OAuthClient) - if !ok { - return nil, nil, false, fmt.Errorf("not a OAuthClient") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) kstorage.SelectionPredicate { - return kstorage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *oauthapi.OAuthClient) fields.Set { - return oauthapi.OAuthClientToSelectableFields(obj) -} diff --git a/pkg/quota/apis/quota/fields.go b/pkg/quota/apis/quota/fields.go deleted file mode 100644 index 9613c5a2c14f..000000000000 --- a/pkg/quota/apis/quota/fields.go +++ /dev/null @@ -1,9 +0,0 @@ -package quota - -import "k8s.io/apimachinery/pkg/fields" - -func ClusterResourceQuotaToSelectableFields(quota *ClusterResourceQuota) fields.Set { - return fields.Set{ - "metadata.name": quota.Name, - } -} diff --git a/pkg/quota/registry/appliedclusterresourcequota/filter.go b/pkg/quota/registry/appliedclusterresourcequota/filter.go index 451eb5a0683d..1a641c4a077d 100644 --- a/pkg/quota/registry/appliedclusterresourcequota/filter.go +++ b/pkg/quota/registry/appliedclusterresourcequota/filter.go @@ -4,17 +4,19 @@ import ( kapierrors "k8s.io/apimachinery/pkg/api/errors" metainternal "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" + "k8s.io/apiserver/pkg/storage" kcorelisters "k8s.io/kubernetes/pkg/client/listers/core/internalversion" oapi "github.com/openshift/origin/pkg/api" quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" "github.com/openshift/origin/pkg/quota/controller/clusterquotamapping" quotalister "github.com/openshift/origin/pkg/quota/generated/listers/quota/internalversion" - clusterresourcequotaregistry "github.com/openshift/origin/pkg/quota/registry/clusterresourcequota" ) type AppliedClusterResourceQuotaREST struct { @@ -70,7 +72,7 @@ func (r *AppliedClusterResourceQuotaREST) List(ctx apirequest.Context, options * // TODO max resource version? watch? list := "aapi.AppliedClusterResourceQuotaList{} - matcher := clusterresourcequotaregistry.Matcher(oapi.InternalListOptionsToSelectors(options)) + matcher := matcher(oapi.InternalListOptionsToSelectors(options)) quotaNames, _ := r.quotaMapper.GetClusterQuotasFor(namespace) for _, name := range quotaNames { @@ -86,3 +88,12 @@ func (r *AppliedClusterResourceQuotaREST) List(ctx apirequest.Context, options * return list, nil } + +// Matcher returns a generic matcher for a given label and field selector. +func matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate { + return storage.SelectionPredicate{ + Label: label, + Field: field, + GetAttrs: storage.DefaultClusterScopedAttr, + } +} diff --git a/pkg/quota/registry/clusterresourcequota/etcd/etcd.go b/pkg/quota/registry/clusterresourcequota/etcd/etcd.go index 2cf4fe1662a6..094042a69185 100644 --- a/pkg/quota/registry/clusterresourcequota/etcd/etcd.go +++ b/pkg/quota/registry/clusterresourcequota/etcd/etcd.go @@ -26,7 +26,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return "aapi.ClusterResourceQuota{} }, NewListFunc: func() runtime.Object { return "aapi.ClusterResourceQuotaList{} }, - PredicateFunc: clusterresourcequota.Matcher, DefaultQualifiedResource: quotaapi.Resource("clusterresourcequotas"), CreateStrategy: clusterresourcequota.Strategy, @@ -34,7 +33,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, *StatusREST, error) { DeleteStrategy: clusterresourcequota.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: clusterresourcequota.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, nil, err } diff --git a/pkg/quota/registry/clusterresourcequota/strategy.go b/pkg/quota/registry/clusterresourcequota/strategy.go index e543f564bbaa..a0b4e75202a9 100644 --- a/pkg/quota/registry/clusterresourcequota/strategy.go +++ b/pkg/quota/registry/clusterresourcequota/strategy.go @@ -1,15 +1,10 @@ package clusterresourcequota import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" quotaapi "github.com/openshift/origin/pkg/quota/apis/quota" @@ -67,24 +62,6 @@ func (strategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) return validation.ValidateClusterResourceQuotaUpdate(obj.(*quotaapi.ClusterResourceQuota), old.(*quotaapi.ClusterResourceQuota)) } -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) { - quota, ok := obj.(*quotaapi.ClusterResourceQuota) - if !ok { - return nil, nil, false, fmt.Errorf("not a ClusterResourceQuota") - } - return labels.Set(quota.ObjectMeta.Labels), quotaapi.ClusterResourceQuotaToSelectableFields(quota), quota.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate { - return storage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - type statusStrategy struct { runtime.ObjectTyper } diff --git a/pkg/sdn/apis/network/fields.go b/pkg/sdn/apis/network/fields.go deleted file mode 100644 index ea6284998e9c..000000000000 --- a/pkg/sdn/apis/network/fields.go +++ /dev/null @@ -1,32 +0,0 @@ -package network - -import "k8s.io/apimachinery/pkg/fields" - -// ClusterNetworkToSelectableFields returns a label set that represents the object -func ClusterNetworkToSelectableFields(network *ClusterNetwork) fields.Set { - return fields.Set{ - "metadata.name": network.Name, - } -} - -// HostSubnetToSelectableFields returns a label set that represents the object -func HostSubnetToSelectableFields(obj *HostSubnet) fields.Set { - return fields.Set{ - "metadata.name": obj.Name, - } -} - -// NetNamespaceToSelectableFields returns a label set that represents the object -func NetNamespaceToSelectableFields(obj *NetNamespace) fields.Set { - return fields.Set{ - "metadata.name": obj.Name, - } -} - -// EgressNetworkPolicyToSelectableFields returns a label set that represents the object -func EgressNetworkPolicyToSelectableFields(obj *EgressNetworkPolicy) fields.Set { - return fields.Set{ - "metadata.name": obj.Name, - "metadata.namespace": obj.Namespace, - } -} diff --git a/pkg/sdn/apis/network/v1/conversion.go b/pkg/sdn/apis/network/v1/conversion.go deleted file mode 100644 index 175729999a2c..000000000000 --- a/pkg/sdn/apis/network/v1/conversion.go +++ /dev/null @@ -1,63 +0,0 @@ -package v1 - -import ( - "k8s.io/apimachinery/pkg/runtime" - - oapi "github.com/openshift/origin/pkg/api" - sdnapi "github.com/openshift/origin/pkg/sdn/apis/network" -) - -func addConversionFuncs(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc("network.openshift.io/v1", "ClusterNetwork", - oapi.GetFieldLabelConversionFunc(sdnapi.ClusterNetworkToSelectableFields(&sdnapi.ClusterNetwork{}), nil), - ); err != nil { - return err - } - - if err := scheme.AddFieldLabelConversionFunc("network.openshift.io/v1", "HostSubnet", - oapi.GetFieldLabelConversionFunc(sdnapi.HostSubnetToSelectableFields(&sdnapi.HostSubnet{}), nil), - ); err != nil { - return err - } - - if err := scheme.AddFieldLabelConversionFunc("network.openshift.io/v1", "NetNamespace", - oapi.GetFieldLabelConversionFunc(sdnapi.NetNamespaceToSelectableFields(&sdnapi.NetNamespace{}), nil), - ); err != nil { - return err - } - - if err := scheme.AddFieldLabelConversionFunc("network.openshift.io/v1", "EgressNetworkPolicy", - oapi.GetFieldLabelConversionFunc(sdnapi.EgressNetworkPolicyToSelectableFields(&sdnapi.EgressNetworkPolicy{}), nil), - ); err != nil { - return err - } - - return addLegacyConversionFuncs(scheme) -} - -func addLegacyConversionFuncs(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc("v1", "ClusterNetwork", - oapi.GetFieldLabelConversionFunc(sdnapi.ClusterNetworkToSelectableFields(&sdnapi.ClusterNetwork{}), nil), - ); err != nil { - return err - } - - if err := scheme.AddFieldLabelConversionFunc("v1", "HostSubnet", - oapi.GetFieldLabelConversionFunc(sdnapi.HostSubnetToSelectableFields(&sdnapi.HostSubnet{}), nil), - ); err != nil { - return err - } - - if err := scheme.AddFieldLabelConversionFunc("v1", "NetNamespace", - oapi.GetFieldLabelConversionFunc(sdnapi.NetNamespaceToSelectableFields(&sdnapi.NetNamespace{}), nil), - ); err != nil { - return err - } - - if err := scheme.AddFieldLabelConversionFunc("v1", "EgressNetworkPolicy", - oapi.GetFieldLabelConversionFunc(sdnapi.EgressNetworkPolicyToSelectableFields(&sdnapi.EgressNetworkPolicy{}), nil), - ); err != nil { - return err - } - return nil -} diff --git a/pkg/sdn/apis/network/v1/conversion_test.go b/pkg/sdn/apis/network/v1/conversion_test.go deleted file mode 100644 index f4a8a5a9847a..000000000000 --- a/pkg/sdn/apis/network/v1/conversion_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package v1_test - -import ( - "testing" - - sdnapi "github.com/openshift/origin/pkg/sdn/apis/network" - testutil "github.com/openshift/origin/test/util/api" - - // install all APIs - _ "github.com/openshift/origin/pkg/api/install" -) - -func TestFieldSelectorConversions(t *testing.T) { - testutil.CheckFieldLabelConversions(t, "network.openshift.io/v1", "ClusterNetwork", - // Ensure all currently returned labels are supported - sdnapi.ClusterNetworkToSelectableFields(&sdnapi.ClusterNetwork{}), - ) - - testutil.CheckFieldLabelConversions(t, "network.openshift.io/v1", "HostSubnet", - // Ensure all currently returned labels are supported - sdnapi.HostSubnetToSelectableFields(&sdnapi.HostSubnet{}), - ) - - testutil.CheckFieldLabelConversions(t, "network.openshift.io/v1", "NetNamespace", - // Ensure all currently returned labels are supported - sdnapi.NetNamespaceToSelectableFields(&sdnapi.NetNamespace{}), - ) - - testutil.CheckFieldLabelConversions(t, "network.openshift.io/v1", "EgressNetworkPolicy", - // Ensure all currently returned labels are supported - sdnapi.EgressNetworkPolicyToSelectableFields(&sdnapi.EgressNetworkPolicy{}), - ) -} - -func TestLegacyFieldSelectorConversions(t *testing.T) { - testutil.CheckFieldLabelConversions(t, "v1", "ClusterNetwork", - // Ensure all currently returned labels are supported - sdnapi.ClusterNetworkToSelectableFields(&sdnapi.ClusterNetwork{}), - ) - - testutil.CheckFieldLabelConversions(t, "v1", "HostSubnet", - // Ensure all currently returned labels are supported - sdnapi.HostSubnetToSelectableFields(&sdnapi.HostSubnet{}), - ) - - testutil.CheckFieldLabelConversions(t, "v1", "NetNamespace", - // Ensure all currently returned labels are supported - sdnapi.NetNamespaceToSelectableFields(&sdnapi.NetNamespace{}), - ) - - testutil.CheckFieldLabelConversions(t, "v1", "EgressNetworkPolicy", - // Ensure all currently returned labels are supported - sdnapi.EgressNetworkPolicyToSelectableFields(&sdnapi.EgressNetworkPolicy{}), - ) -} diff --git a/pkg/sdn/apis/network/v1/register.go b/pkg/sdn/apis/network/v1/register.go index e082991ee48c..7351d610463f 100644 --- a/pkg/sdn/apis/network/v1/register.go +++ b/pkg/sdn/apis/network/v1/register.go @@ -16,10 +16,10 @@ var ( SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"} - LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes, addConversionFuncs) + LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes) AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes, addConversionFuncs) + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) AddToScheme = SchemeBuilder.AddToScheme ) diff --git a/pkg/sdn/registry/clusternetwork/etcd/etcd.go b/pkg/sdn/registry/clusternetwork/etcd/etcd.go index 8d244276bf27..379c52ff0dd4 100644 --- a/pkg/sdn/registry/clusternetwork/etcd/etcd.go +++ b/pkg/sdn/registry/clusternetwork/etcd/etcd.go @@ -25,7 +25,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &sdnapi.ClusterNetwork{} }, NewListFunc: func() runtime.Object { return &sdnapi.ClusterNetworkList{} }, - PredicateFunc: clusternetwork.Matcher, DefaultQualifiedResource: sdnapi.Resource("clusternetworks"), CreateStrategy: clusternetwork.Strategy, @@ -33,7 +32,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: clusternetwork.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: clusternetwork.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/sdn/registry/clusternetwork/strategy.go b/pkg/sdn/registry/clusternetwork/strategy.go index 69e168276be0..be51f8be3f51 100644 --- a/pkg/sdn/registry/clusternetwork/strategy.go +++ b/pkg/sdn/registry/clusternetwork/strategy.go @@ -1,15 +1,10 @@ package clusternetwork import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" sdnapi "github.com/openshift/origin/pkg/sdn/apis/network" @@ -65,26 +60,3 @@ func (sdnStrategy) AllowUnconditionalUpdate() bool { func (sdnStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateClusterNetworkUpdate(obj.(*sdnapi.ClusterNetwork), old.(*sdnapi.ClusterNetwork)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*sdnapi.ClusterNetwork) - if !ok { - return nil, nil, false, fmt.Errorf("not a ClusterNetwork") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate { - return storage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *sdnapi.ClusterNetwork) fields.Set { - return sdnapi.ClusterNetworkToSelectableFields(obj) -} diff --git a/pkg/sdn/registry/egressnetworkpolicy/etcd/etcd.go b/pkg/sdn/registry/egressnetworkpolicy/etcd/etcd.go index f3445fb128fe..d44237eb11be 100644 --- a/pkg/sdn/registry/egressnetworkpolicy/etcd/etcd.go +++ b/pkg/sdn/registry/egressnetworkpolicy/etcd/etcd.go @@ -25,7 +25,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &sdnapi.EgressNetworkPolicy{} }, NewListFunc: func() runtime.Object { return &sdnapi.EgressNetworkPolicyList{} }, - PredicateFunc: egressnetworkpolicy.Matcher, DefaultQualifiedResource: sdnapi.Resource("egressnetworkpolicies"), CreateStrategy: egressnetworkpolicy.Strategy, @@ -33,7 +32,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: egressnetworkpolicy.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: egressnetworkpolicy.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/sdn/registry/egressnetworkpolicy/strategy.go b/pkg/sdn/registry/egressnetworkpolicy/strategy.go index 5ae6ba2b2974..3327eb65f803 100644 --- a/pkg/sdn/registry/egressnetworkpolicy/strategy.go +++ b/pkg/sdn/registry/egressnetworkpolicy/strategy.go @@ -1,15 +1,10 @@ package egressnetworkpolicy import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" sdnapi "github.com/openshift/origin/pkg/sdn/apis/network" @@ -65,26 +60,3 @@ func (enpStrategy) AllowUnconditionalUpdate() bool { func (enpStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateEgressNetworkPolicyUpdate(obj.(*sdnapi.EgressNetworkPolicy), old.(*sdnapi.EgressNetworkPolicy)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*sdnapi.EgressNetworkPolicy) - if !ok { - return nil, nil, false, fmt.Errorf("not an EgressNetworkPolicy") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate { - return storage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *sdnapi.EgressNetworkPolicy) fields.Set { - return sdnapi.EgressNetworkPolicyToSelectableFields(obj) -} diff --git a/pkg/sdn/registry/hostsubnet/etcd/etcd.go b/pkg/sdn/registry/hostsubnet/etcd/etcd.go index b7820f0291ef..7a73d2d47473 100644 --- a/pkg/sdn/registry/hostsubnet/etcd/etcd.go +++ b/pkg/sdn/registry/hostsubnet/etcd/etcd.go @@ -25,7 +25,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &sdnapi.HostSubnet{} }, NewListFunc: func() runtime.Object { return &sdnapi.HostSubnetList{} }, - PredicateFunc: hostsubnet.Matcher, DefaultQualifiedResource: sdnapi.Resource("hostsubnets"), CreateStrategy: hostsubnet.Strategy, @@ -33,7 +32,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: hostsubnet.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: hostsubnet.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/sdn/registry/hostsubnet/strategy.go b/pkg/sdn/registry/hostsubnet/strategy.go index 8bb8c65c337e..8d17c4181da9 100644 --- a/pkg/sdn/registry/hostsubnet/strategy.go +++ b/pkg/sdn/registry/hostsubnet/strategy.go @@ -1,15 +1,10 @@ package hostsubnet import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" sdnapi "github.com/openshift/origin/pkg/sdn/apis/network" @@ -65,26 +60,3 @@ func (sdnStrategy) AllowUnconditionalUpdate() bool { func (sdnStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateHostSubnetUpdate(obj.(*sdnapi.HostSubnet), old.(*sdnapi.HostSubnet)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*sdnapi.HostSubnet) - if !ok { - return nil, nil, false, fmt.Errorf("not a HostSubnet") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate { - return storage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *sdnapi.HostSubnet) fields.Set { - return sdnapi.HostSubnetToSelectableFields(obj) -} diff --git a/pkg/sdn/registry/netnamespace/etcd/etcd.go b/pkg/sdn/registry/netnamespace/etcd/etcd.go index ea0d01134ae7..4d8e1cfb847e 100644 --- a/pkg/sdn/registry/netnamespace/etcd/etcd.go +++ b/pkg/sdn/registry/netnamespace/etcd/etcd.go @@ -25,7 +25,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &sdnapi.NetNamespace{} }, NewListFunc: func() runtime.Object { return &sdnapi.NetNamespaceList{} }, - PredicateFunc: netnamespace.Matcher, DefaultQualifiedResource: sdnapi.Resource("netnamespaces"), CreateStrategy: netnamespace.Strategy, @@ -33,7 +32,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: netnamespace.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: netnamespace.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/sdn/registry/netnamespace/strategy.go b/pkg/sdn/registry/netnamespace/strategy.go index 26227193281e..987deeed933d 100644 --- a/pkg/sdn/registry/netnamespace/strategy.go +++ b/pkg/sdn/registry/netnamespace/strategy.go @@ -1,15 +1,10 @@ package netnamespace import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" sdnapi "github.com/openshift/origin/pkg/sdn/apis/network" @@ -65,26 +60,3 @@ func (sdnStrategy) AllowUnconditionalUpdate() bool { func (sdnStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateNetNamespaceUpdate(obj.(*sdnapi.NetNamespace), old.(*sdnapi.NetNamespace)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*sdnapi.NetNamespace) - if !ok { - return nil, nil, false, fmt.Errorf("not a NetNamespace") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate { - return storage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *sdnapi.NetNamespace) fields.Set { - return sdnapi.NetNamespaceToSelectableFields(obj) -} diff --git a/pkg/user/apis/user/fields.go b/pkg/user/apis/user/fields.go index 9e5d0a473bfb..29ee38c5d8a6 100644 --- a/pkg/user/apis/user/fields.go +++ b/pkg/user/apis/user/fields.go @@ -2,14 +2,6 @@ package user import "k8s.io/apimachinery/pkg/fields" -// GroupToSelectableFields returns a label set that represents the object -// changes to the returned keys require registering conversions for existing versions using Scheme.AddFieldLabelConversionFunc -func GroupToSelectableFields(group *Group) fields.Set { - return fields.Set{ - "metadata.name": group.Name, - } -} - // IdentityToSelectableFields returns a label set that represents the object // changes to the returned keys require registering conversions for existing versions using Scheme.AddFieldLabelConversionFunc func IdentityToSelectableFields(identity *Identity) fields.Set { @@ -21,11 +13,3 @@ func IdentityToSelectableFields(identity *Identity) fields.Set { "user.uid": string(identity.User.UID), } } - -// UserToSelectableFields returns a label set that represents the object -// changes to the returned keys require registering conversions for existing versions using Scheme.AddFieldLabelConversionFunc -func UserToSelectableFields(user *User) fields.Set { - return fields.Set{ - "metadata.name": user.Name, - } -} diff --git a/pkg/user/apis/user/v1/conversion.go b/pkg/user/apis/user/v1/conversion.go index 28da9f8ecfdc..cbfae72d0aab 100644 --- a/pkg/user/apis/user/v1/conversion.go +++ b/pkg/user/apis/user/v1/conversion.go @@ -8,22 +8,11 @@ import ( ) func addConversionFuncs(scheme *runtime.Scheme) error { - if err := scheme.AddFieldLabelConversionFunc("v1", "Group", - oapi.GetFieldLabelConversionFunc(userapi.GroupToSelectableFields(&userapi.Group{}), nil), - ); err != nil { - return err - } - if err := scheme.AddFieldLabelConversionFunc("v1", "Identity", oapi.GetFieldLabelConversionFunc(userapi.IdentityToSelectableFields(&userapi.Identity{}), nil), ); err != nil { return err } - if err := scheme.AddFieldLabelConversionFunc("v1", "User", - oapi.GetFieldLabelConversionFunc(userapi.UserToSelectableFields(&userapi.User{}), nil), - ); err != nil { - return err - } return nil } diff --git a/pkg/user/apis/user/v1/conversion_test.go b/pkg/user/apis/user/v1/conversion_test.go index 218aa4b67ff8..340f4854f764 100644 --- a/pkg/user/apis/user/v1/conversion_test.go +++ b/pkg/user/apis/user/v1/conversion_test.go @@ -11,11 +11,6 @@ import ( ) func TestFieldSelectorConversions(t *testing.T) { - testutil.CheckFieldLabelConversions(t, "v1", "Group", - // Ensure all currently returned labels are supported - userapi.GroupToSelectableFields(&userapi.Group{}), - ) - testutil.CheckFieldLabelConversions(t, "v1", "Identity", // Ensure all currently returned labels are supported userapi.IdentityToSelectableFields(&userapi.Identity{}), @@ -23,8 +18,4 @@ func TestFieldSelectorConversions(t *testing.T) { "providerName", "providerUserName", "user.name", "user.uid", ) - testutil.CheckFieldLabelConversions(t, "v1", "User", - // Ensure all currently returned labels are supported - userapi.UserToSelectableFields(&userapi.User{}), - ) } diff --git a/pkg/user/registry/group/etcd/etcd.go b/pkg/user/registry/group/etcd/etcd.go index 95210eadb74d..59601a3dbf4c 100644 --- a/pkg/user/registry/group/etcd/etcd.go +++ b/pkg/user/registry/group/etcd/etcd.go @@ -22,7 +22,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &userapi.Group{} }, NewListFunc: func() runtime.Object { return &userapi.GroupList{} }, - PredicateFunc: group.Matcher, DefaultQualifiedResource: userapi.Resource("groups"), CreateStrategy: group.Strategy, @@ -30,7 +29,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: group.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: group.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/user/registry/group/strategy.go b/pkg/user/registry/group/strategy.go index 5b66342ea464..dfc5d042d8bf 100644 --- a/pkg/user/registry/group/strategy.go +++ b/pkg/user/registry/group/strategy.go @@ -1,15 +1,10 @@ package group import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - kstorage "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" userapi "github.com/openshift/origin/pkg/user/apis/user" @@ -65,26 +60,3 @@ func (groupStrategy) Canonicalize(obj runtime.Object) { func (groupStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateGroupUpdate(obj.(*userapi.Group), old.(*userapi.Group)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*userapi.Group) - if !ok { - return nil, nil, false, fmt.Errorf("not a Group") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) kstorage.SelectionPredicate { - return kstorage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *userapi.Group) fields.Set { - return userapi.GroupToSelectableFields(obj) -} diff --git a/pkg/user/registry/user/etcd/etcd.go b/pkg/user/registry/user/etcd/etcd.go index d7bfe4d0794e..35da24e9a30d 100644 --- a/pkg/user/registry/user/etcd/etcd.go +++ b/pkg/user/registry/user/etcd/etcd.go @@ -35,7 +35,6 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { Copier: kapi.Scheme, NewFunc: func() runtime.Object { return &userapi.User{} }, NewListFunc: func() runtime.Object { return &userapi.UserList{} }, - PredicateFunc: user.Matcher, DefaultQualifiedResource: userapi.Resource("users"), CreateStrategy: user.Strategy, @@ -43,7 +42,7 @@ func NewREST(optsGetter restoptions.Getter) (*REST, error) { DeleteStrategy: user.Strategy, } - options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: user.GetAttrs} + options := &generic.StoreOptions{RESTOptions: optsGetter} if err := store.CompleteWithOptions(options); err != nil { return nil, err } diff --git a/pkg/user/registry/user/strategy.go b/pkg/user/registry/user/strategy.go index e1f550bcd54b..f4ad7323b48e 100644 --- a/pkg/user/registry/user/strategy.go +++ b/pkg/user/registry/user/strategy.go @@ -1,15 +1,10 @@ package user import ( - "fmt" - - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" apirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" - kstorage "k8s.io/apiserver/pkg/storage" kapi "k8s.io/kubernetes/pkg/api" userapi "github.com/openshift/origin/pkg/user/apis/user" @@ -65,26 +60,3 @@ func (userStrategy) Canonicalize(obj runtime.Object) { func (userStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList { return validation.ValidateUserUpdate(obj.(*userapi.User), old.(*userapi.User)) } - -// GetAttrs returns labels and fields of a given object for filtering purposes -func GetAttrs(o runtime.Object) (labels.Set, fields.Set, bool, error) { - obj, ok := o.(*userapi.User) - if !ok { - return nil, nil, false, fmt.Errorf("not a User") - } - return labels.Set(obj.Labels), SelectableFields(obj), obj.Initializers != nil, nil -} - -// Matcher returns a generic matcher for a given label and field selector. -func Matcher(label labels.Selector, field fields.Selector) kstorage.SelectionPredicate { - return kstorage.SelectionPredicate{ - Label: label, - Field: field, - GetAttrs: GetAttrs, - } -} - -// SelectableFields returns a field set that can be used for filter selection -func SelectableFields(obj *userapi.User) fields.Set { - return userapi.UserToSelectableFields(obj) -}