Merge pull request #30976 from wojtek-t/validated_selector

Automatic merge from submit-queue

	Don't validate selector that is already validated

Ref #30875

@timothysc
This commit is contained in:
Kubernetes Submit Queue
2016-08-22 03:34:44 -07:00
committed by GitHub
9 changed files with 42 additions and 19 deletions

View File

@@ -269,11 +269,10 @@ func (s *StoreToReplicationControllerLister) GetPodControllers(pod *api.Pod) (co
for _, m := range items {
rc = *m.(*api.ReplicationController)
labelSet := labels.Set(rc.Spec.Selector)
selector = labels.Set(rc.Spec.Selector).AsSelector()
selector = labels.Set(rc.Spec.Selector).AsSelectorPreValidated()
// If an rc with a nil or empty selector creeps in, it should match nothing, not everything.
if labelSet.AsSelector().Empty() || !selector.Matches(labels.Set(pod.Labels)) {
if selector.Empty() || !selector.Matches(labels.Set(pod.Labels)) {
continue
}
controllers = append(controllers, rc)
@@ -513,7 +512,7 @@ func (s *StoreToServiceLister) GetPodServices(pod *api.Pod) (services []api.Serv
// services with nil selectors match nothing, not everything.
continue
}
selector = labels.Set(service.Spec.Selector).AsSelector()
selector = labels.Set(service.Spec.Selector).AsSelectorPreValidated()
if selector.Matches(labels.Set(pod.Labels)) {
services = append(services, service)
}

View File

@@ -143,7 +143,7 @@ func TestStoreToReplicationControllerLister(t *testing.T) {
},
},
list: func(lister StoreToReplicationControllerLister) ([]api.ReplicationController, error) {
return lister.ReplicationControllers(api.NamespaceAll).List(labels.Set{}.AsSelector())
return lister.ReplicationControllers(api.NamespaceAll).List(labels.Set{}.AsSelectorPreValidated())
},
outRCNames: sets.NewString("hmm", "foo"),
},
@@ -158,7 +158,7 @@ func TestStoreToReplicationControllerLister(t *testing.T) {
},
},
list: func(lister StoreToReplicationControllerLister) ([]api.ReplicationController, error) {
return lister.ReplicationControllers("hmm").List(labels.Set{}.AsSelector())
return lister.ReplicationControllers("hmm").List(labels.Set{}.AsSelectorPreValidated())
},
outRCNames: sets.NewString("hmm"),
},
@@ -715,7 +715,7 @@ func TestStoreToPodLister(t *testing.T) {
spl := StoreToPodLister{store}
// Verify that we can always look up by Namespace.
defaultPods, err := spl.Pods(api.NamespaceDefault).List(labels.Set{}.AsSelector())
defaultPods, err := spl.Pods(api.NamespaceDefault).List(labels.Set{}.AsSelectorPreValidated())
if err != nil {
t.Errorf("Unexpected error: %v", err)
} else if e, a := 1, len(defaultPods); e != a {
@@ -725,7 +725,7 @@ func TestStoreToPodLister(t *testing.T) {
}
for _, id := range ids {
got, err := spl.List(labels.Set{"name": id}.AsSelector())
got, err := spl.List(labels.Set{"name": id}.AsSelectorPreValidated())
if err != nil {
t.Errorf("Unexpected error: %v", err)
continue