diff --git a/federation/registry/cluster/strategy.go b/federation/registry/cluster/strategy.go index 9b12d487a4..6e442f7309 100644 --- a/federation/registry/cluster/strategy.go +++ b/federation/registry/cluster/strategy.go @@ -41,7 +41,7 @@ func (clusterStrategy) NamespaceScoped() bool { } func ClusterToSelectableFields(cluster *federation.Cluster) fields.Set { - return generic.ObjectMetaFieldsSet(cluster.ObjectMeta, false) + return generic.ObjectMetaFieldsSet(&cluster.ObjectMeta, false) } func MatchCluster(label labels.Selector, field fields.Selector) *generic.SelectionPredicate { diff --git a/pkg/registry/certificates/strategy.go b/pkg/registry/certificates/strategy.go index e5a630c9b8..da6385451c 100644 --- a/pkg/registry/certificates/strategy.go +++ b/pkg/registry/certificates/strategy.go @@ -184,5 +184,5 @@ func Matcher(label labels.Selector, field fields.Selector) *generic.SelectionPre // SelectableFields returns a field set that can be used for filter selection func SelectableFields(obj *certificates.CertificateSigningRequest) fields.Set { - return generic.ObjectMetaFieldsSet(obj.ObjectMeta, false) + return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false) } diff --git a/pkg/registry/configmap/strategy.go b/pkg/registry/configmap/strategy.go index bbac7e86b1..3a06e1a16c 100644 --- a/pkg/registry/configmap/strategy.go +++ b/pkg/registry/configmap/strategy.go @@ -84,7 +84,7 @@ func (strategy) ValidateUpdate(ctx api.Context, newObj, oldObj runtime.Object) f // ConfigMapToSelectableFields returns a field set that represents the object for matching purposes. func ConfigMapToSelectableFields(cfg *api.ConfigMap) fields.Set { - return generic.ObjectMetaFieldsSet(cfg.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&cfg.ObjectMeta, true) } // MatchConfigMap returns a generic matcher for a given label and field selector. diff --git a/pkg/registry/controller/strategy.go b/pkg/registry/controller/strategy.go index 6b96706b60..fdb12e4e39 100644 --- a/pkg/registry/controller/strategy.go +++ b/pkg/registry/controller/strategy.go @@ -103,7 +103,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, true) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&controller.ObjectMeta, true) controllerSpecificFieldsSet := fields.Set{ "status.replicas": strconv.Itoa(int(controller.Status.Replicas)), } diff --git a/pkg/registry/daemonset/strategy.go b/pkg/registry/daemonset/strategy.go index de5690545a..b19eb890ae 100644 --- a/pkg/registry/daemonset/strategy.go +++ b/pkg/registry/daemonset/strategy.go @@ -106,7 +106,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, true) + 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 e460685b37..e31df2e48f 100644 --- a/pkg/registry/deployment/strategy.go +++ b/pkg/registry/deployment/strategy.go @@ -112,7 +112,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, true) + 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 903c9e13de..ed2d16ec27 100644 --- a/pkg/registry/endpoint/strategy.go +++ b/pkg/registry/endpoint/strategy.go @@ -90,5 +90,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, true), 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 bcf363be12..731c00e422 100644 --- a/pkg/registry/event/strategy.go +++ b/pkg/registry/event/strategy.go @@ -20,7 +20,6 @@ import ( "fmt" "k8s.io/kubernetes/pkg/api" - "k8s.io/kubernetes/pkg/api/errors" "k8s.io/kubernetes/pkg/api/validation" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" @@ -71,20 +70,22 @@ func (eventStrategy) AllowUnconditionalUpdate() bool { } func MatchEvent(label labels.Selector, field fields.Selector) *generic.SelectionPredicate { - return &generic.SelectionPredicate{Label: label, Field: field, GetAttrs: getAttrs} + return &generic.SelectionPredicate{ + Label: label, + Field: field, + GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) { + event, ok := obj.(*api.Event) + if !ok { + return nil, nil, fmt.Errorf("not an event") + } + return labels.Set(event.Labels), EventToSelectableFields(event), nil + }, + } } -func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, err error) { - event, ok := obj.(*api.Event) - if !ok { - return nil, nil, errors.NewInternalError(fmt.Errorf("object is not of type event: %#v", obj)) - } - l := event.Labels - if l == nil { - l = labels.Set{} - } - - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(event.ObjectMeta, true) +// EventToSelectableFields returns a field set that represents the object +func EventToSelectableFields(event *api.Event) fields.Set { + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&event.ObjectMeta, true) specificFieldsSet := fields.Set{ "involvedObject.kind": event.InvolvedObject.Kind, "involvedObject.namespace": event.InvolvedObject.Namespace, @@ -97,5 +98,5 @@ func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, e "source": event.Source.Component, "type": event.Type, } - return l, generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet), nil + return generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet) } diff --git a/pkg/registry/event/strategy_test.go b/pkg/registry/event/strategy_test.go index 45b6c08fa8..c6c323521b 100644 --- a/pkg/registry/event/strategy_test.go +++ b/pkg/registry/event/strategy_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/kubernetes/pkg/api/testapi" apitesting "k8s.io/kubernetes/pkg/api/testing" "k8s.io/kubernetes/pkg/fields" - "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/util/diff" ) @@ -60,13 +59,7 @@ func TestGetAttrs(t *testing.T) { Source: api.EventSource{Component: "test"}, Type: api.EventTypeNormal, } - label, field, err := getAttrs(eventA) - if err != nil { - t.Fatalf("Unexpected error %v", err) - } - if e, a := label, (labels.Set{}); !reflect.DeepEqual(e, a) { - t.Errorf("diff: %s", diff.ObjectDiff(e, a)) - } + field := EventToSelectableFields(eventA) expect := fields.Set{ "metadata.name": "f0118", "metadata.namespace": "default", @@ -87,10 +80,7 @@ func TestGetAttrs(t *testing.T) { } func TestSelectableFieldLabelConversions(t *testing.T) { - _, fset, err := getAttrs(&api.Event{}) - if err != nil { - t.Fatalf("Unexpected error %v", err) - } + fset := EventToSelectableFields(&api.Event{}) apitesting.TestSelectableFieldLabelConversionsOfKind(t, testapi.Default.GroupVersion().String(), "Event", diff --git a/pkg/registry/generic/matcher.go b/pkg/registry/generic/matcher.go index 61431fe1b6..16e5851b8f 100644 --- a/pkg/registry/generic/matcher.go +++ b/pkg/registry/generic/matcher.go @@ -27,8 +27,8 @@ import ( // AttrFunc returns label and field sets for List or Watch to compare against, or an error. 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, hasNamespaceField bool) fields.Set { +// ObjectMetaFieldsSet returns a fields that represents the ObjectMeta. +func ObjectMetaFieldsSet(objectMeta *api.ObjectMeta, hasNamespaceField bool) fields.Set { if !hasNamespaceField { return fields.Set{ "metadata.name": objectMeta.Name, diff --git a/pkg/registry/generic/registry/store_test.go b/pkg/registry/generic/registry/store_test.go index 17c4e4491b..ae77752e03 100644 --- a/pkg/registry/generic/registry/store_test.go +++ b/pkg/registry/generic/registry/store_test.go @@ -1046,7 +1046,7 @@ func newTestGenericStoreRegistry(t *testing.T, hasCacheEnabled bool) (*etcdtesti if !ok { return nil, nil, fmt.Errorf("not a pod") } - return labels.Set(pod.ObjectMeta.Labels), generic.ObjectMetaFieldsSet(pod.ObjectMeta, true), nil + return labels.Set(pod.ObjectMeta.Labels), generic.ObjectMetaFieldsSet(&pod.ObjectMeta, true), nil }, } }, diff --git a/pkg/registry/ingress/strategy.go b/pkg/registry/ingress/strategy.go index 5238ebe925..f9ec9a3a3a 100644 --- a/pkg/registry/ingress/strategy.go +++ b/pkg/registry/ingress/strategy.go @@ -99,7 +99,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, true) + 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 a976963737..4cc66f575d 100644 --- a/pkg/registry/job/strategy.go +++ b/pkg/registry/job/strategy.go @@ -156,7 +156,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 *batch.Job) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(job.ObjectMeta, true) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&job.ObjectMeta, true) specificFieldsSet := fields.Set{ "status.successful": strconv.Itoa(int(job.Status.Succeeded)), } diff --git a/pkg/registry/namespace/strategy.go b/pkg/registry/namespace/strategy.go index 5ef0441c18..aa1b572d82 100644 --- a/pkg/registry/namespace/strategy.go +++ b/pkg/registry/namespace/strategy.go @@ -151,7 +151,7 @@ func MatchNamespace(label labels.Selector, field fields.Selector) *generic.Selec // NamespaceToSelectableFields returns a field set that represents the object func NamespaceToSelectableFields(namespace *api.Namespace) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(namespace.ObjectMeta, false) + 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/networkpolicy/strategy.go b/pkg/registry/networkpolicy/strategy.go index 9a2da57c67..a2ddb6c913 100644 --- a/pkg/registry/networkpolicy/strategy.go +++ b/pkg/registry/networkpolicy/strategy.go @@ -92,7 +92,7 @@ func (networkPolicyStrategy) AllowUnconditionalUpdate() bool { // NetworkPolicyToSelectableFields returns a field set that represents the object. func NetworkPolicyToSelectableFields(networkPolicy *extensions.NetworkPolicy) fields.Set { - return generic.ObjectMetaFieldsSet(networkPolicy.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&networkPolicy.ObjectMeta, true) } // MatchNetworkPolicy is the filter used by the generic etcd backend to watch events diff --git a/pkg/registry/node/strategy.go b/pkg/registry/node/strategy.go index 532f5394c4..3f05168ff6 100644 --- a/pkg/registry/node/strategy.go +++ b/pkg/registry/node/strategy.go @@ -139,7 +139,7 @@ type ResourceGetter interface { // NodeToSelectableFields returns a field set that represents the object. func NodeToSelectableFields(node *api.Node) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(node.ObjectMeta, false) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&node.ObjectMeta, false) specificFieldsSet := fields.Set{ "spec.unschedulable": fmt.Sprint(node.Spec.Unschedulable), } diff --git a/pkg/registry/persistentvolume/strategy.go b/pkg/registry/persistentvolume/strategy.go index 4b5e311889..3866dc0f09 100644 --- a/pkg/registry/persistentvolume/strategy.go +++ b/pkg/registry/persistentvolume/strategy.go @@ -111,7 +111,7 @@ func MatchPersistentVolumes(label labels.Selector, field fields.Selector) *gener // PersistentVolumeToSelectableFields returns a field set that represents the object func PersistentVolumeToSelectableFields(persistentvolume *api.PersistentVolume) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolume.ObjectMeta, false) + 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 0b259f04cc..e0058aac95 100644 --- a/pkg/registry/persistentvolumeclaim/strategy.go +++ b/pkg/registry/persistentvolumeclaim/strategy.go @@ -111,7 +111,7 @@ func MatchPersistentVolumeClaim(label labels.Selector, field fields.Selector) *g // PersistentVolumeClaimToSelectableFields returns a field set that represents the object func PersistentVolumeClaimToSelectableFields(persistentvolumeclaim *api.PersistentVolumeClaim) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolumeclaim.ObjectMeta, true) + 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/petset/strategy.go b/pkg/registry/petset/strategy.go index 2ff0ada8e7..e614362c01 100644 --- a/pkg/registry/petset/strategy.go +++ b/pkg/registry/petset/strategy.go @@ -98,7 +98,7 @@ func (petSetStrategy) AllowUnconditionalUpdate() bool { // PetSetToSelectableFields returns a field set that represents the object. func PetSetToSelectableFields(petSet *apps.PetSet) fields.Set { - return generic.ObjectMetaFieldsSet(petSet.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&petSet.ObjectMeta, true) } // MatchPetSet is the filter used by the generic etcd backend to watch events diff --git a/pkg/registry/pod/strategy.go b/pkg/registry/pod/strategy.go index 35199f0c44..7ac59d7d43 100644 --- a/pkg/registry/pod/strategy.go +++ b/pkg/registry/pod/strategy.go @@ -191,7 +191,7 @@ func NodeNameTriggerFunc(obj runtime.Object) []storage.MatchValue { // 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, true) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&pod.ObjectMeta, true) podSpecificFieldsSet := fields.Set{ "spec.nodeName": pod.Spec.NodeName, "spec.restartPolicy": string(pod.Spec.RestartPolicy), diff --git a/pkg/registry/poddisruptionbudget/strategy.go b/pkg/registry/poddisruptionbudget/strategy.go index 450fb302a8..04c143bcd6 100644 --- a/pkg/registry/poddisruptionbudget/strategy.go +++ b/pkg/registry/poddisruptionbudget/strategy.go @@ -97,7 +97,7 @@ func (podDisruptionBudgetStrategy) AllowUnconditionalUpdate() bool { // PodDisruptionBudgetToSelectableFields returns a field set that represents the object. func PodDisruptionBudgetToSelectableFields(podDisruptionBudget *policy.PodDisruptionBudget) fields.Set { - return generic.ObjectMetaFieldsSet(podDisruptionBudget.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&podDisruptionBudget.ObjectMeta, true) } // MatchPodDisruptionBudget is the filter used by the generic etcd backend to watch events diff --git a/pkg/registry/podsecuritypolicy/strategy.go b/pkg/registry/podsecuritypolicy/strategy.go index 4bc4bba8c2..aa6cd8c343 100644 --- a/pkg/registry/podsecuritypolicy/strategy.go +++ b/pkg/registry/podsecuritypolicy/strategy.go @@ -90,5 +90,5 @@ func MatchPodSecurityPolicy(label labels.Selector, field fields.Selector) *gener // PodSecurityPolicyToSelectableFields returns a label set that represents the object func PodSecurityPolicyToSelectableFields(obj *extensions.PodSecurityPolicy) fields.Set { - return generic.ObjectMetaFieldsSet(obj.ObjectMeta, false) + return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, false) } diff --git a/pkg/registry/replicaset/strategy.go b/pkg/registry/replicaset/strategy.go index a8adc95cdf..1cd474d330 100644 --- a/pkg/registry/replicaset/strategy.go +++ b/pkg/registry/replicaset/strategy.go @@ -104,7 +104,7 @@ func (rsStrategy) AllowUnconditionalUpdate() bool { // ReplicaSetToSelectableFields returns a field set that represents the object. func ReplicaSetToSelectableFields(rs *extensions.ReplicaSet) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(rs.ObjectMeta, true) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&rs.ObjectMeta, true) rsSpecificFieldsSet := fields.Set{ "status.replicas": strconv.Itoa(int(rs.Status.Replicas)), } diff --git a/pkg/registry/resourcequota/strategy.go b/pkg/registry/resourcequota/strategy.go index 1e6051f875..6b8dc9a89c 100644 --- a/pkg/registry/resourcequota/strategy.go +++ b/pkg/registry/resourcequota/strategy.go @@ -114,5 +114,5 @@ func MatchResourceQuota(label labels.Selector, field fields.Selector) *generic.S // ResourceQuotaToSelectableFields returns a field set that represents the object func ResourceQuotaToSelectableFields(resourcequota *api.ResourceQuota) fields.Set { - return generic.ObjectMetaFieldsSet(resourcequota.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&resourcequota.ObjectMeta, true) } diff --git a/pkg/registry/scheduledjob/strategy.go b/pkg/registry/scheduledjob/strategy.go index d8db976f82..a0523bbb3c 100644 --- a/pkg/registry/scheduledjob/strategy.go +++ b/pkg/registry/scheduledjob/strategy.go @@ -98,7 +98,7 @@ func (scheduledJobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runti // ScheduledJobToSelectableFields returns a field set that represents the object for matching purposes. func ScheduledJobToSelectableFields(scheduledJob *batch.ScheduledJob) fields.Set { - return generic.ObjectMetaFieldsSet(scheduledJob.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&scheduledJob.ObjectMeta, true) } // MatchScheduledJob is the filter used by the generic etcd backend to route diff --git a/pkg/registry/secret/strategy.go b/pkg/registry/secret/strategy.go index 8663f5109e..83c4229fd3 100644 --- a/pkg/registry/secret/strategy.go +++ b/pkg/registry/secret/strategy.go @@ -110,7 +110,7 @@ func Matcher(label labels.Selector, field fields.Selector) *generic.SelectionPre // SelectableFields returns a field set that can be used for filter selection func SelectableFields(obj *api.Secret) fields.Set { - objectMetaFieldsSet := generic.ObjectMetaFieldsSet(obj.ObjectMeta, true) + objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true) secretSpecificFieldsSet := fields.Set{ "type": string(obj.Type), } diff --git a/pkg/registry/service/strategy.go b/pkg/registry/service/strategy.go index 8fe1e3da02..e499c07566 100644 --- a/pkg/registry/service/strategy.go +++ b/pkg/registry/service/strategy.go @@ -115,7 +115,7 @@ func MatchServices(label labels.Selector, field fields.Selector) *generic.Select } func ServiceToSelectableFields(service *api.Service) fields.Set { - return generic.ObjectMetaFieldsSet(service.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&service.ObjectMeta, true) } type serviceStatusStrategy struct { diff --git a/pkg/registry/serviceaccount/strategy.go b/pkg/registry/serviceaccount/strategy.go index dc10c80e84..d1db5ed3d5 100644 --- a/pkg/registry/serviceaccount/strategy.go +++ b/pkg/registry/serviceaccount/strategy.go @@ -93,5 +93,5 @@ func Matcher(label labels.Selector, field fields.Selector) *generic.SelectionPre // SelectableFields returns a field set that represents the object func SelectableFields(obj *api.ServiceAccount) fields.Set { - return generic.ObjectMetaFieldsSet(obj.ObjectMeta, true) + return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true) } diff --git a/pkg/registry/storageclass/strategy.go b/pkg/registry/storageclass/strategy.go index 6ee3ef8b82..4dc18f88cb 100644 --- a/pkg/registry/storageclass/strategy.go +++ b/pkg/registry/storageclass/strategy.go @@ -94,5 +94,5 @@ func MatchStorageClasses(label labels.Selector, field fields.Selector) *generic. // StorageClassToSelectableFields returns a label set that represents the object func StorageClassToSelectableFields(storageClass *extensions.StorageClass) fields.Set { - return generic.ObjectMetaFieldsSet(storageClass.ObjectMeta, false) + return generic.ObjectMetaFieldsSet(&storageClass.ObjectMeta, false) }