move daemonset to generalized label selector

This commit is contained in:
Mike Danese
2015-10-25 23:11:09 -07:00
parent abbed4f7e8
commit 7a7f31ead1
13 changed files with 91 additions and 64 deletions

View File

@@ -247,7 +247,11 @@ func (s *StoreToDaemonSetLister) GetPodDaemonSets(pod *api.Pod) (daemonSets []ex
if daemonSet.Namespace != pod.Namespace {
continue
}
selector = labels.Set(daemonSet.Spec.Selector).AsSelector()
selector, err = extensions.PodSelectorAsSelector(daemonSet.Spec.Selector)
if err != nil {
// this should not happen if the DaemonSet passed validation
return nil, err
}
// If a daemonSet with a nil or empty selector creeps in, it should match nothing, not everything.
if selector.Empty() || !selector.Matches(labels.Set(pod.Labels)) {

View File

@@ -272,7 +272,7 @@ func TestStoreToDaemonSetLister(t *testing.T) {
{
ObjectMeta: api.ObjectMeta{Name: "basic", Namespace: "ns"},
Spec: extensions.DaemonSetSpec{
Selector: map[string]string{"foo": "baz"},
Selector: &extensions.PodSelector{MatchLabels: map[string]string{"foo": "baz"}},
},
},
},
@@ -311,13 +311,13 @@ func TestStoreToDaemonSetLister(t *testing.T) {
{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Spec: extensions.DaemonSetSpec{
Selector: map[string]string{"foo": "bar"},
Selector: &extensions.PodSelector{MatchLabels: map[string]string{"foo": "bar"}},
},
},
{
ObjectMeta: api.ObjectMeta{Name: "bar", Namespace: "ns"},
Spec: extensions.DaemonSetSpec{
Selector: map[string]string{"foo": "bar"},
Selector: &extensions.PodSelector{MatchLabels: map[string]string{"foo": "bar"}},
},
},
},