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

@ -1534,7 +1534,7 @@ func init() {
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
return "metadata.name", value, nil
case "DesiredState.Host":
return "spec.host", value, nil
case "DesiredState.Status":
@ -1554,7 +1554,7 @@ func init() {
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
return "metadata.name", value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
@ -1567,7 +1567,7 @@ func init() {
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
return "metadata.name", value, nil
case "currentState.replicas":
return "status.replicas", value, nil
default:

View File

@ -1459,7 +1459,7 @@ func init() {
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
return "metadata.name", value, nil
case "DesiredState.Host":
return "spec.host", value, nil
case "DesiredState.Status":
@ -1479,7 +1479,7 @@ func init() {
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
return "metadata.name", value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
@ -1492,7 +1492,7 @@ func init() {
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
return "metadata.name", value, nil
case "currentState.replicas":
return "status.replicas", value, nil
default:

View File

@ -27,7 +27,7 @@ func init() {
err := newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod",
func(label, value string) (string, string, error) {
switch label {
case "name",
case "metadata.name",
"status.phase",
"spec.host":
return label, value, nil
@ -42,7 +42,7 @@ func init() {
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node",
func(label, value string) (string, string, error) {
switch label {
case "name":
case "metadata.name":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
@ -55,10 +55,9 @@ func init() {
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController",
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
case "status.replicas":
return "status.replicas", value, nil
case "metadata.name",
"status.replicas":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}

View File

@ -544,14 +544,15 @@ func TestEtcdWatchControllersFields(t *testing.T) {
testFieldMap := map[int][]fields.Set{
PASS: {
{"status.replicas": "0"},
{"name": "foo"},
{"status.replicas": "0", "name": "foo"},
{"metadata.name": "foo"},
{"status.replicas": "0", "metadata.name": "foo"},
},
FAIL: {
{"status.replicas": "10"},
{"name": "bar"},
{"status.replicas": "10", "name": "foo"},
{"status.replicas": "0", "name": "bar"},
{"metadata.name": "bar"},
{"name": "foo"},
{"status.replicas": "10", "metadata.name": "foo"},
{"status.replicas": "0", "metadata.name": "bar"},
},
}
testEtcdActions := []string{

View File

@ -75,9 +75,9 @@ func (rcStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field
}
// ControllerToSelectableFields returns a label set that represents the object.
func ControllerToSelectableFields(controller *api.ReplicationController) labels.Set {
return labels.Set{
"name": controller.Name,
func ControllerToSelectableFields(controller *api.ReplicationController) fields.Set {
return fields.Set{
"metadata.name": controller.Name,
"status.replicas": strconv.Itoa(controller.Status.Replicas),
}
}
@ -86,13 +86,15 @@ func ControllerToSelectableFields(controller *api.ReplicationController) labels.
// watch events from etcd to clients of the apiserver only interested in specific
// labels/fields.
func MatchController(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(
func(obj runtime.Object) (bool, error) {
controllerObj, ok := obj.(*api.ReplicationController)
return &generic.SelectionPredicate{
Label: label,
Field: field,
GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
rc, ok := obj.(*api.ReplicationController)
if !ok {
return false, fmt.Errorf("Given object is not a replication controller.")
return nil, nil, fmt.Errorf("Given object is not a replication controller.")
}
fields := ControllerToSelectableFields(controllerObj)
return label.Matches(labels.Set(controllerObj.Labels)) && field.Matches(fields), nil
})
return labels.Set(rc.ObjectMeta.Labels), ControllerToSelectableFields(rc), nil
},
}
}

View File

@ -53,7 +53,7 @@ func (s *SelectionPredicate) Matches(obj runtime.Object) (bool, error) {
// name.
func (s *SelectionPredicate) MatchesSingle() (string, bool) {
// TODO: should be namespace.name
if name, ok := s.Field.RequiresExactMatch("name"); ok {
if name, ok := s.Field.RequiresExactMatch("metadata.name"); ok {
return name, true
}
return "", false

View File

@ -68,9 +68,9 @@ func TestSelectionPredicate(t *testing.T) {
shouldMatch: false,
},
"D": {
fieldSelector: "name=12345",
fieldSelector: "metadata.name=12345",
labels: labels.Set{},
fields: fields.Set{"name": "12345"},
fields: fields.Set{"metadata.name": "12345"},
shouldMatch: true,
matchSingleKey: "12345",
},

View File

@ -85,7 +85,7 @@ type ResourceGetter interface {
// NodeToSelectableFields returns a label set that represents the object.
func NodeToSelectableFields(node *api.Node) fields.Set {
return fields.Set{
"name": node.Name,
"metadata.name": node.Name,
}
}

View File

@ -26,7 +26,7 @@ import (
func TestMatchNode(t *testing.T) {
testFieldMap := map[bool][]fields.Set{
true: {
{"name": "foo"},
{"metadata.name": "foo"},
},
false: {
{"foo": "bar"},

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),
}
}