Fix incorrect reference to name in v1beta3 API.

This commit is contained in:
Daniel Smith
2015-04-03 14:10:47 -07:00
parent 0c2d3ffe68
commit 34b399ca02
11 changed files with 51 additions and 46 deletions

View File

@@ -291,7 +291,7 @@ func TestListPodListSelection(t *testing.T) {
{
expectedIDs: util.NewStringSet("foo", "bar", "baz", "qux", "zot"),
}, {
field: "name=zot",
field: "metadata.name=zot",
expectedIDs: util.NewStringSet("zot"),
}, {
label: "label=qux",

View File

@@ -105,23 +105,26 @@ func (podStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object
// MatchPod returns a generic matcher for a given label and field selector.
func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
podObj, ok := obj.(*api.Pod)
if !ok {
return false, fmt.Errorf("not a pod")
}
fields := PodToSelectableFields(podObj)
return label.Matches(labels.Set(podObj.Labels)) && field.Matches(fields), nil
})
return &generic.SelectionPredicate{
Label: label,
Field: field,
GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
pod, ok := obj.(*api.Pod)
if !ok {
return nil, nil, fmt.Errorf("not a pod")
}
return labels.Set(pod.ObjectMeta.Labels), PodToSelectableFields(pod), nil
},
}
}
// PodToSelectableFields returns a label set that represents the object
// TODO: fields are not labels, and the validation rules for them do not apply.
func PodToSelectableFields(pod *api.Pod) labels.Set {
return labels.Set{
"name": pod.Name,
"spec.host": pod.Spec.Host,
"status.phase": string(pod.Status.Phase),
func PodToSelectableFields(pod *api.Pod) fields.Set {
return fields.Set{
"metadata.name": pod.Name,
"spec.host": pod.Spec.Host,
"status.phase": string(pod.Status.Phase),
}
}