Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where nodes that weren't schedulable or ready are added to … #16640

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/controller/service/servicecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,12 @@ func stringSlicesEqual(x, y []string) bool {
}

func hostsFromNodeList(list *api.NodeList) []string {
result := make([]string, len(list.Items))
result := []string{}
for ix := range list.Items {
result[ix] = list.Items[ix].Name
if list.Items[ix].Spec.Unschedulable {
continue
}
result = append(result, list.Items[ix].Name)
}
return result
}
Expand All @@ -598,7 +601,7 @@ func (s *ServiceController) nodeSyncLoop(period time.Duration) {
// something to compile, and gofmt1.4 complains about using `_ = range`.
for now := range time.Tick(period) {
_ = now
nodes, err := s.nodeLister.List()
nodes, err := s.nodeLister.NodeCondition(api.NodeReady, api.ConditionTrue).List()
if err != nil {
glog.Errorf("Failed to retrieve current set of nodes from node lister: %v", err)
continue
Expand Down
54 changes: 54 additions & 0 deletions pkg/controller/service/servicecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,58 @@ func TestUpdateNodesInExternalLoadBalancer(t *testing.T) {
}
}

func TestHostsFromNodeList(t *testing.T) {
tests := []struct {
nodes *api.NodeList
expectedHosts []string
}{
{
nodes: &api.NodeList{},
expectedHosts: []string{},
},
{
nodes: &api.NodeList{
Items: []api.Node{
{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Status: api.NodeStatus{Phase: api.NodeRunning},
},
{
ObjectMeta: api.ObjectMeta{Name: "bar"},
Status: api.NodeStatus{Phase: api.NodeRunning},
},
},
},
expectedHosts: []string{"foo", "bar"},
},
{
nodes: &api.NodeList{
Items: []api.Node{
{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Status: api.NodeStatus{Phase: api.NodeRunning},
},
{
ObjectMeta: api.ObjectMeta{Name: "bar"},
Status: api.NodeStatus{Phase: api.NodeRunning},
},
{
ObjectMeta: api.ObjectMeta{Name: "unschedulable"},
Spec: api.NodeSpec{Unschedulable: true},
Status: api.NodeStatus{Phase: api.NodeRunning},
},
},
},
expectedHosts: []string{"foo", "bar"},
},
}

for _, test := range tests {
hosts := hostsFromNodeList(test.nodes)
if !reflect.DeepEqual(hosts, test.expectedHosts) {
t.Errorf("expected: %v, saw: %v", test.expectedHosts, hosts)
}
}
}

// TODO(a-robinson): Add tests for update/sync/delete.