From 726def04d5f647ffccf8afe8035f8f8f6fc3b0f5 Mon Sep 17 00:00:00 2001 From: feihujiang Date: Sat, 31 Oct 2015 10:48:24 +0800 Subject: [PATCH] Make rootscoped resource no namespace selectable field --- pkg/registry/controller/strategy.go | 2 +- pkg/registry/daemonset/strategy.go | 2 +- pkg/registry/deployment/strategy.go | 2 +- pkg/registry/endpoint/strategy.go | 2 +- pkg/registry/event/strategy.go | 2 +- pkg/registry/generic/matcher.go | 7 ++++++- pkg/registry/ingress/strategy.go | 2 +- pkg/registry/job/strategy.go | 2 +- pkg/registry/namespace/strategy.go | 2 +- pkg/registry/node/strategy.go | 5 +++-- pkg/registry/persistentvolume/strategy.go | 2 +- pkg/registry/persistentvolumeclaim/strategy.go | 2 +- pkg/registry/pod/strategy.go | 2 +- pkg/registry/resourcequota/strategy.go | 2 +- pkg/registry/serviceaccount/strategy.go | 2 +- 15 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pkg/registry/controller/strategy.go b/pkg/registry/controller/strategy.go index d06c32212ad..9abb6ec5822 100644 --- a/pkg/registry/controller/strategy.go +++ b/pkg/registry/controller/strategy.go @@ -100,7 +100,7 @@ func (rcStrategy) AllowUnconditionalUpdate() bool { // ControllerToSelectableFields returns a field set that represents the object. func ControllerToSelectableFields(controller *api.ReplicationController) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(controller.ObjectMeta) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(controller.ObjectMeta, true) controllerSpecificFieldsSet := fields.Set{ "status.replicas": strconv.Itoa(controller.Status.Replicas), } diff --git a/pkg/registry/daemonset/strategy.go b/pkg/registry/daemonset/strategy.go index 98152db1b60..53a3eda0749 100644 --- a/pkg/registry/daemonset/strategy.go +++ b/pkg/registry/daemonset/strategy.go @@ -102,7 +102,7 @@ func (daemonSetStrategy) AllowUnconditionalUpdate() bool { // DaemonSetToSelectableFields returns a field set that represents the object. func DaemonSetToSelectableFields(daemon *extensions.DaemonSet) fields.Set { - return generic.ObjectMetaFieldsSet(daemon.ObjectMeta) + return generic.ObjectMetaFieldsSet(daemon.ObjectMeta, true) } // MatchSetDaemon is the filter used by the generic etcd backend to route diff --git a/pkg/registry/deployment/strategy.go b/pkg/registry/deployment/strategy.go index 19fd5693215..4d50d47dc07 100644 --- a/pkg/registry/deployment/strategy.go +++ b/pkg/registry/deployment/strategy.go @@ -97,7 +97,7 @@ func (deploymentStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime // DeploymentToSelectableFields returns a field set that represents the object. func DeploymentToSelectableFields(deployment *extensions.Deployment) fields.Set { - return generic.ObjectMetaFieldsSet(deployment.ObjectMeta) + return generic.ObjectMetaFieldsSet(deployment.ObjectMeta, true) } // MatchDeployment is the filter used by the generic etcd backend to route diff --git a/pkg/registry/endpoint/strategy.go b/pkg/registry/endpoint/strategy.go index 0366d87a557..67eab3b4155 100644 --- a/pkg/registry/endpoint/strategy.go +++ b/pkg/registry/endpoint/strategy.go @@ -89,5 +89,5 @@ func EndpointsAttributes(obj runtime.Object) (objLabels labels.Set, objFields fi if !ok { return nil, nil, fmt.Errorf("invalid object type %#v", obj) } - return endpoints.Labels, generic.ObjectMetaFieldsSet(endpoints.ObjectMeta), nil + return endpoints.Labels, generic.ObjectMetaFieldsSet(endpoints.ObjectMeta, true), nil } diff --git a/pkg/registry/event/strategy.go b/pkg/registry/event/strategy.go index 9c8f0dc7735..9d033f56624 100644 --- a/pkg/registry/event/strategy.go +++ b/pkg/registry/event/strategy.go @@ -80,7 +80,7 @@ func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, e l = labels.Set{} } - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(event.ObjectMeta) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(event.ObjectMeta, true) specificFieldsSet := fields.Set{ "involvedObject.kind": event.InvolvedObject.Kind, "involvedObject.namespace": event.InvolvedObject.Namespace, diff --git a/pkg/registry/generic/matcher.go b/pkg/registry/generic/matcher.go index 16282ea7eb4..08e2df7b456 100644 --- a/pkg/registry/generic/matcher.go +++ b/pkg/registry/generic/matcher.go @@ -27,7 +27,12 @@ import ( type AttrFunc func(obj runtime.Object) (label labels.Set, field fields.Set, err error) // ObjectMetaFieldsSet returns a fields set that represents the ObjectMeta. -func ObjectMetaFieldsSet(objectMeta api.ObjectMeta) fields.Set { +func ObjectMetaFieldsSet(objectMeta api.ObjectMeta, hasNamespaceField bool) fields.Set { + if !hasNamespaceField { + return fields.Set{ + "metadata.name": objectMeta.Name, + } + } return fields.Set{ "metadata.name": objectMeta.Name, "metadata.namespace": objectMeta.Namespace, diff --git a/pkg/registry/ingress/strategy.go b/pkg/registry/ingress/strategy.go index 95ab183a3e9..05b4f0fef9f 100644 --- a/pkg/registry/ingress/strategy.go +++ b/pkg/registry/ingress/strategy.go @@ -95,7 +95,7 @@ func (ingressStrategy) AllowUnconditionalUpdate() bool { // IngressToSelectableFields returns a field set that represents the object. func IngressToSelectableFields(ingress *extensions.Ingress) fields.Set { - return generic.ObjectMetaFieldsSet(ingress.ObjectMeta) + return generic.ObjectMetaFieldsSet(ingress.ObjectMeta, true) } // MatchIngress is the filter used by the generic etcd backend to ingress diff --git a/pkg/registry/job/strategy.go b/pkg/registry/job/strategy.go index 0b489332e8f..66aece643c5 100644 --- a/pkg/registry/job/strategy.go +++ b/pkg/registry/job/strategy.go @@ -97,7 +97,7 @@ func (jobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object // JobSelectableFields returns a field set that represents the object for matching purposes. func JobToSelectableFields(job *extensions.Job) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(job.ObjectMeta) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(job.ObjectMeta, true) specificFieldsSet := fields.Set{ "status.successful": strconv.Itoa(job.Status.Succeeded), } diff --git a/pkg/registry/namespace/strategy.go b/pkg/registry/namespace/strategy.go index f0acec3b1ea..bfe95d5df17 100644 --- a/pkg/registry/namespace/strategy.go +++ b/pkg/registry/namespace/strategy.go @@ -144,7 +144,7 @@ func MatchNamespace(label labels.Selector, field fields.Selector) generic.Matche // NamespaceToSelectableFields returns a label set that represents the object func NamespaceToSelectableFields(namespace *api.Namespace) labels.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(namespace.ObjectMeta) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(namespace.ObjectMeta, false) specificFieldsSet := fields.Set{ "status.phase": string(namespace.Status.Phase), // This is a bug, but we need to support it for backward compatibility. diff --git a/pkg/registry/node/strategy.go b/pkg/registry/node/strategy.go index 679a53b8fa9..7a903984cc3 100644 --- a/pkg/registry/node/strategy.go +++ b/pkg/registry/node/strategy.go @@ -114,10 +114,11 @@ type ResourceGetter interface { // NodeToSelectableFields returns a label set that represents the object. func NodeToSelectableFields(node *api.Node) fields.Set { - return fields.Set{ - "metadata.name": node.Name, + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(node.ObjectMeta, false) + specificFieldsSet := fields.Set{ "spec.unschedulable": fmt.Sprint(node.Spec.Unschedulable), } + return generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet) } // MatchNode returns a generic matcher for a given label and field selector. diff --git a/pkg/registry/persistentvolume/strategy.go b/pkg/registry/persistentvolume/strategy.go index 9ebb0837a63..35ff51aa70e 100644 --- a/pkg/registry/persistentvolume/strategy.go +++ b/pkg/registry/persistentvolume/strategy.go @@ -104,7 +104,7 @@ func MatchPersistentVolumes(label labels.Selector, field fields.Selector) generi // PersistentVolumeToSelectableFields returns a label set that represents the object func PersistentVolumeToSelectableFields(persistentvolume *api.PersistentVolume) labels.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolume.ObjectMeta) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolume.ObjectMeta, false) specificFieldsSet := fields.Set{ // This is a bug, but we need to support it for backward compatibility. "name": persistentvolume.Name, diff --git a/pkg/registry/persistentvolumeclaim/strategy.go b/pkg/registry/persistentvolumeclaim/strategy.go index 57fc3666e20..26b99a2f4fe 100644 --- a/pkg/registry/persistentvolumeclaim/strategy.go +++ b/pkg/registry/persistentvolumeclaim/strategy.go @@ -104,7 +104,7 @@ func MatchPersistentVolumeClaim(label labels.Selector, field fields.Selector) ge // PersistentVolumeClaimToSelectableFields returns a label set that represents the object func PersistentVolumeClaimToSelectableFields(persistentvolumeclaim *api.PersistentVolumeClaim) labels.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolumeclaim.ObjectMeta) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolumeclaim.ObjectMeta, true) specificFieldsSet := fields.Set{ // This is a bug, but we need to support it for backward compatibility. "name": persistentvolumeclaim.Name, diff --git a/pkg/registry/pod/strategy.go b/pkg/registry/pod/strategy.go index 4aa57d03d62..a753f7ece6f 100644 --- a/pkg/registry/pod/strategy.go +++ b/pkg/registry/pod/strategy.go @@ -166,7 +166,7 @@ func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher { // PodToSelectableFields returns a field set that represents the object // TODO: fields are not labels, and the validation rules for them do not apply. func PodToSelectableFields(pod *api.Pod) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(pod.ObjectMeta) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(pod.ObjectMeta, true) podSpecificFieldsSet := fields.Set{ "spec.nodeName": pod.Spec.NodeName, "status.phase": string(pod.Status.Phase), diff --git a/pkg/registry/resourcequota/strategy.go b/pkg/registry/resourcequota/strategy.go index e6735031040..4780e7d9bc0 100644 --- a/pkg/registry/resourcequota/strategy.go +++ b/pkg/registry/resourcequota/strategy.go @@ -107,5 +107,5 @@ func MatchResourceQuota(label labels.Selector, field fields.Selector) generic.Ma // ResourceQuotaToSelectableFields returns a label set that represents the object func ResourceQuotaToSelectableFields(resourcequota *api.ResourceQuota) labels.Set { - return labels.Set(generic.ObjectMetaFieldsSet(resourcequota.ObjectMeta)) + return labels.Set(generic.ObjectMetaFieldsSet(resourcequota.ObjectMeta, true)) } diff --git a/pkg/registry/serviceaccount/strategy.go b/pkg/registry/serviceaccount/strategy.go index 91778aa3efa..d4b97a2b752 100644 --- a/pkg/registry/serviceaccount/strategy.go +++ b/pkg/registry/serviceaccount/strategy.go @@ -86,5 +86,5 @@ func Matcher(label labels.Selector, field fields.Selector) generic.Matcher { // SelectableFields returns a label set that represents the object func SelectableFields(obj *api.ServiceAccount) labels.Set { - return labels.Set(generic.ObjectMetaFieldsSet(obj.ObjectMeta)) + return labels.Set(generic.ObjectMetaFieldsSet(obj.ObjectMeta, true)) }