Merge pull request #15766 from feihujiang/supportNamespaceSelectorInAllNamespacesEndpoint

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2015-10-24 17:08:34 -07:00
commit 33dabe00a8
15 changed files with 55 additions and 38 deletions

View File

@ -98,12 +98,13 @@ func (rcStrategy) AllowUnconditionalUpdate() bool {
return true return true
} }
// ControllerToSelectableFields returns a label set that represents the object. // ControllerToSelectableFields returns a field set that represents the object.
func ControllerToSelectableFields(controller *api.ReplicationController) fields.Set { func ControllerToSelectableFields(controller *api.ReplicationController) fields.Set {
return fields.Set{ objectMetaFieldsSet := generic.ObjectMetaFieldsSet(controller.ObjectMeta)
"metadata.name": controller.Name, controllerSpecificFieldsSet := fields.Set{
"status.replicas": strconv.Itoa(controller.Status.Replicas), "status.replicas": strconv.Itoa(controller.Status.Replicas),
} }
return generic.MergeFieldsSets(objectMetaFieldsSet, controllerSpecificFieldsSet)
} }
// MatchController is the filter used by the generic etcd backend to route // MatchController is the filter used by the generic etcd backend to route

View File

@ -102,9 +102,7 @@ func (daemonSetStrategy) AllowUnconditionalUpdate() bool {
// DaemonSetToSelectableFields returns a field set that represents the object. // DaemonSetToSelectableFields returns a field set that represents the object.
func DaemonSetToSelectableFields(daemon *extensions.DaemonSet) fields.Set { func DaemonSetToSelectableFields(daemon *extensions.DaemonSet) fields.Set {
return fields.Set{ return generic.ObjectMetaFieldsSet(daemon.ObjectMeta)
"metadata.name": daemon.Name,
}
} }
// MatchSetDaemon is the filter used by the generic etcd backend to route // MatchSetDaemon is the filter used by the generic etcd backend to route

View File

@ -74,9 +74,7 @@ func (deploymentStrategy) AllowUnconditionalUpdate() bool {
// DeploymentToSelectableFields returns a field set that represents the object. // DeploymentToSelectableFields returns a field set that represents the object.
func DeploymentToSelectableFields(deployment *extensions.Deployment) fields.Set { func DeploymentToSelectableFields(deployment *extensions.Deployment) fields.Set {
return fields.Set{ return generic.ObjectMetaFieldsSet(deployment.ObjectMeta)
"metadata.name": deployment.Name,
}
} }
// MatchDeployment is the filter used by the generic etcd backend to route // MatchDeployment is the filter used by the generic etcd backend to route

View File

@ -89,7 +89,5 @@ func EndpointsAttributes(obj runtime.Object) (objLabels labels.Set, objFields fi
if !ok { if !ok {
return nil, nil, fmt.Errorf("invalid object type %#v", obj) return nil, nil, fmt.Errorf("invalid object type %#v", obj)
} }
return endpoints.Labels, fields.Set{ return endpoints.Labels, generic.ObjectMetaFieldsSet(endpoints.ObjectMeta), nil
"metadata.name": endpoints.Name,
}, nil
} }

View File

@ -79,8 +79,9 @@ func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, e
if l == nil { if l == nil {
l = labels.Set{} l = labels.Set{}
} }
return l, fields.Set{
"metadata.name": event.Name, objectMetaFieldsSet := generic.ObjectMetaFieldsSet(event.ObjectMeta)
specificFieldsSet := fields.Set{
"involvedObject.kind": event.InvolvedObject.Kind, "involvedObject.kind": event.InvolvedObject.Kind,
"involvedObject.namespace": event.InvolvedObject.Namespace, "involvedObject.namespace": event.InvolvedObject.Namespace,
"involvedObject.name": event.InvolvedObject.Name, "involvedObject.name": event.InvolvedObject.Name,
@ -90,5 +91,6 @@ func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, e
"involvedObject.fieldPath": event.InvolvedObject.FieldPath, "involvedObject.fieldPath": event.InvolvedObject.FieldPath,
"reason": event.Reason, "reason": event.Reason,
"source": event.Source.Component, "source": event.Source.Component,
}, nil }
return l, generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet), nil
} }

View File

@ -42,7 +42,10 @@ func testEvent(name string) *api.Event {
func TestGetAttrs(t *testing.T) { func TestGetAttrs(t *testing.T) {
eventA := &api.Event{ eventA := &api.Event{
ObjectMeta: api.ObjectMeta{Name: "f0118"}, ObjectMeta: api.ObjectMeta{
Name: "f0118",
Namespace: "default",
},
InvolvedObject: api.ObjectReference{ InvolvedObject: api.ObjectReference{
Kind: "Pod", Kind: "Pod",
Name: "foo", Name: "foo",
@ -64,6 +67,7 @@ func TestGetAttrs(t *testing.T) {
} }
expect := fields.Set{ expect := fields.Set{
"metadata.name": "f0118", "metadata.name": "f0118",
"metadata.namespace": "default",
"involvedObject.kind": "Pod", "involvedObject.kind": "Pod",
"involvedObject.name": "foo", "involvedObject.name": "foo",
"involvedObject.namespace": "baz", "involvedObject.namespace": "baz",

View File

@ -17,6 +17,7 @@ limitations under the License.
package generic package generic
import ( import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
@ -25,6 +26,22 @@ import (
// AttrFunc returns label and field sets for List or Watch to compare against, or an error. // 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) 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 {
return fields.Set{
"metadata.name": objectMeta.Name,
"metadata.namespace": objectMeta.Namespace,
}
}
// MergeFieldsSets merges a fields'set from fragment into the source.
func MergeFieldsSets(source fields.Set, fragment fields.Set) fields.Set {
for k, value := range fragment {
source[k] = value
}
return source
}
// SelectionPredicate implements a generic predicate that can be passed to // SelectionPredicate implements a generic predicate that can be passed to
// GenericRegistry's List or Watch methods. Implements the Matcher interface. // GenericRegistry's List or Watch methods. Implements the Matcher interface.
type SelectionPredicate struct { type SelectionPredicate struct {

View File

@ -93,11 +93,9 @@ func (ingressStrategy) AllowUnconditionalUpdate() bool {
return true return true
} }
// IngressToSelectableFields returns a label set that represents the object. // IngressToSelectableFields returns a field set that represents the object.
func IngressToSelectableFields(ingress *extensions.Ingress) fields.Set { func IngressToSelectableFields(ingress *extensions.Ingress) fields.Set {
return fields.Set{ return generic.ObjectMetaFieldsSet(ingress.ObjectMeta)
"metadata.name": ingress.Name,
}
} }
// MatchIngress is the filter used by the generic etcd backend to ingress // MatchIngress is the filter used by the generic etcd backend to ingress

View File

@ -97,10 +97,11 @@ func (jobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object
// JobSelectableFields returns a field set that represents the object for matching purposes. // JobSelectableFields returns a field set that represents the object for matching purposes.
func JobToSelectableFields(job *extensions.Job) fields.Set { func JobToSelectableFields(job *extensions.Job) fields.Set {
return fields.Set{ objectMetaFieldsSet := generic.ObjectMetaFieldsSet(job.ObjectMeta)
"metadata.name": job.Name, specificFieldsSet := fields.Set{
"status.successful": strconv.Itoa(job.Status.Succeeded), "status.successful": strconv.Itoa(job.Status.Succeeded),
} }
return generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet)
} }
// MatchJob is the filter used by the generic etcd backend to route // MatchJob is the filter used by the generic etcd backend to route

View File

@ -144,10 +144,11 @@ func MatchNamespace(label labels.Selector, field fields.Selector) generic.Matche
// NamespaceToSelectableFields returns a label set that represents the object // NamespaceToSelectableFields returns a label set that represents the object
func NamespaceToSelectableFields(namespace *api.Namespace) labels.Set { func NamespaceToSelectableFields(namespace *api.Namespace) labels.Set {
return labels.Set{ objectMetaFieldsSet := generic.ObjectMetaFieldsSet(namespace.ObjectMeta)
"metadata.name": namespace.Name, specificFieldsSet := fields.Set{
"status.phase": string(namespace.Status.Phase), "status.phase": string(namespace.Status.Phase),
// This is a bug, but we need to support it for backward compatibility. // This is a bug, but we need to support it for backward compatibility.
"name": namespace.Name, "name": namespace.Name,
} }
return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet))
} }

View File

@ -104,9 +104,10 @@ func MatchPersistentVolumes(label labels.Selector, field fields.Selector) generi
// PersistentVolumeToSelectableFields returns a label set that represents the object // PersistentVolumeToSelectableFields returns a label set that represents the object
func PersistentVolumeToSelectableFields(persistentvolume *api.PersistentVolume) labels.Set { func PersistentVolumeToSelectableFields(persistentvolume *api.PersistentVolume) labels.Set {
return labels.Set{ objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolume.ObjectMeta)
"metadata.name": persistentvolume.Name, specificFieldsSet := fields.Set{
// This is a bug, but we need to support it for backward compatibility. // This is a bug, but we need to support it for backward compatibility.
"name": persistentvolume.Name, "name": persistentvolume.Name,
} }
return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet))
} }

View File

@ -104,9 +104,10 @@ func MatchPersistentVolumeClaim(label labels.Selector, field fields.Selector) ge
// PersistentVolumeClaimToSelectableFields returns a label set that represents the object // PersistentVolumeClaimToSelectableFields returns a label set that represents the object
func PersistentVolumeClaimToSelectableFields(persistentvolumeclaim *api.PersistentVolumeClaim) labels.Set { func PersistentVolumeClaimToSelectableFields(persistentvolumeclaim *api.PersistentVolumeClaim) labels.Set {
return labels.Set{ objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolumeclaim.ObjectMeta)
"metadata.name": persistentvolumeclaim.Name, specificFieldsSet := fields.Set{
// This is a bug, but we need to support it for backward compatibility. // This is a bug, but we need to support it for backward compatibility.
"name": persistentvolumeclaim.Name, "name": persistentvolumeclaim.Name,
} }
return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet))
} }

View File

@ -163,14 +163,15 @@ func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
} }
} }
// PodToSelectableFields returns a label set that represents the object // PodToSelectableFields returns a field set that represents the object
// TODO: fields are not labels, and the validation rules for them do not apply. // TODO: fields are not labels, and the validation rules for them do not apply.
func PodToSelectableFields(pod *api.Pod) fields.Set { func PodToSelectableFields(pod *api.Pod) fields.Set {
return fields.Set{ objectMetaFieldsSet := generic.ObjectMetaFieldsSet(pod.ObjectMeta)
"metadata.name": pod.Name, podSpecificFieldsSet := fields.Set{
"spec.nodeName": pod.Spec.NodeName, "spec.nodeName": pod.Spec.NodeName,
"status.phase": string(pod.Status.Phase), "status.phase": string(pod.Status.Phase),
} }
return generic.MergeFieldsSets(objectMetaFieldsSet, podSpecificFieldsSet)
} }
// ResourceGetter is an interface for retrieving resources by ResourceLocation. // ResourceGetter is an interface for retrieving resources by ResourceLocation.

View File

@ -107,7 +107,5 @@ func MatchResourceQuota(label labels.Selector, field fields.Selector) generic.Ma
// ResourceQuotaToSelectableFields returns a label set that represents the object // ResourceQuotaToSelectableFields returns a label set that represents the object
func ResourceQuotaToSelectableFields(resourcequota *api.ResourceQuota) labels.Set { func ResourceQuotaToSelectableFields(resourcequota *api.ResourceQuota) labels.Set {
return labels.Set{ return labels.Set(generic.ObjectMetaFieldsSet(resourcequota.ObjectMeta))
"metadata.name": resourcequota.Name,
}
} }

View File

@ -86,7 +86,5 @@ func Matcher(label labels.Selector, field fields.Selector) generic.Matcher {
// SelectableFields returns a label set that represents the object // SelectableFields returns a label set that represents the object
func SelectableFields(obj *api.ServiceAccount) labels.Set { func SelectableFields(obj *api.ServiceAccount) labels.Set {
return labels.Set{ return labels.Set(generic.ObjectMetaFieldsSet(obj.ObjectMeta))
"metadata.name": obj.Name,
}
} }