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

View File

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

View File

@ -27,7 +27,7 @@ func init() {
err := newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod", err := newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "name", case "metadata.name",
"status.phase", "status.phase",
"spec.host": "spec.host":
return label, value, nil return label, value, nil
@ -42,7 +42,7 @@ func init() {
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node", err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "name": case "metadata.name":
return label, value, nil return label, value, nil
default: default:
return "", "", fmt.Errorf("field label not supported: %s", label) return "", "", fmt.Errorf("field label not supported: %s", label)
@ -55,10 +55,9 @@ func init() {
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController", err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController",
func(label, value string) (string, string, error) { func(label, value string) (string, string, error) {
switch label { switch label {
case "name": case "metadata.name",
return "name", value, nil "status.replicas":
case "status.replicas": return label, value, nil
return "status.replicas", value, nil
default: default:
return "", "", fmt.Errorf("field label not supported: %s", label) 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{ testFieldMap := map[int][]fields.Set{
PASS: { PASS: {
{"status.replicas": "0"}, {"status.replicas": "0"},
{"name": "foo"}, {"metadata.name": "foo"},
{"status.replicas": "0", "name": "foo"}, {"status.replicas": "0", "metadata.name": "foo"},
}, },
FAIL: { FAIL: {
{"status.replicas": "10"}, {"status.replicas": "10"},
{"name": "bar"}, {"metadata.name": "bar"},
{"status.replicas": "10", "name": "foo"}, {"name": "foo"},
{"status.replicas": "0", "name": "bar"}, {"status.replicas": "10", "metadata.name": "foo"},
{"status.replicas": "0", "metadata.name": "bar"},
}, },
} }
testEtcdActions := []string{ 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. // ControllerToSelectableFields returns a label set that represents the object.
func ControllerToSelectableFields(controller *api.ReplicationController) labels.Set { func ControllerToSelectableFields(controller *api.ReplicationController) fields.Set {
return labels.Set{ return fields.Set{
"name": controller.Name, "metadata.name": controller.Name,
"status.replicas": strconv.Itoa(controller.Status.Replicas), "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 // watch events from etcd to clients of the apiserver only interested in specific
// labels/fields. // labels/fields.
func MatchController(label labels.Selector, field fields.Selector) generic.Matcher { func MatchController(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc( return &generic.SelectionPredicate{
func(obj runtime.Object) (bool, error) { Label: label,
controllerObj, ok := obj.(*api.ReplicationController) Field: field,
GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
rc, ok := obj.(*api.ReplicationController)
if !ok { 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 labels.Set(rc.ObjectMeta.Labels), ControllerToSelectableFields(rc), nil
return label.Matches(labels.Set(controllerObj.Labels)) && field.Matches(fields), nil },
}) }
} }

View File

@ -53,7 +53,7 @@ func (s *SelectionPredicate) Matches(obj runtime.Object) (bool, error) {
// name. // name.
func (s *SelectionPredicate) MatchesSingle() (string, bool) { func (s *SelectionPredicate) MatchesSingle() (string, bool) {
// TODO: should be namespace.name // 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 name, true
} }
return "", false return "", false

View File

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

View File

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

View File

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

View File

@ -291,7 +291,7 @@ func TestListPodListSelection(t *testing.T) {
{ {
expectedIDs: util.NewStringSet("foo", "bar", "baz", "qux", "zot"), expectedIDs: util.NewStringSet("foo", "bar", "baz", "qux", "zot"),
}, { }, {
field: "name=zot", field: "metadata.name=zot",
expectedIDs: util.NewStringSet("zot"), expectedIDs: util.NewStringSet("zot"),
}, { }, {
label: "label=qux", 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. // MatchPod returns a generic matcher for a given label and field selector.
func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher { func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) { return &generic.SelectionPredicate{
podObj, ok := obj.(*api.Pod) Label: label,
if !ok { Field: field,
return false, fmt.Errorf("not a pod") GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
} pod, ok := obj.(*api.Pod)
fields := PodToSelectableFields(podObj) if !ok {
return label.Matches(labels.Set(podObj.Labels)) && field.Matches(fields), nil 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 // PodToSelectableFields returns a label 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) labels.Set { func PodToSelectableFields(pod *api.Pod) fields.Set {
return labels.Set{ return fields.Set{
"name": pod.Name, "metadata.name": pod.Name,
"spec.host": pod.Spec.Host, "spec.host": pod.Spec.Host,
"status.phase": string(pod.Status.Phase), "status.phase": string(pod.Status.Phase),
} }
} }