mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
Don't validate selector that is already validated
This commit is contained in:
7
pkg/client/cache/listers.go
vendored
7
pkg/client/cache/listers.go
vendored
@@ -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)
|
||||
}
|
||||
|
||||
8
pkg/client/cache/listers_test.go
vendored
8
pkg/client/cache/listers_test.go
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user