Skip to content

Commit 7730ecf

Browse files
authored
fixed case where, no ready label is defined, but node is unscheduable (#1162)
* fixed case where, no ready label is defined, but node is unscheduable
1 parent e97235a commit 7730ecf

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

pkg/controller/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (c *Controller) nodeUpdate(prev, cur interface{}) {
7676
}
7777

7878
func (c *Controller) nodeIsReady(node *v1.Node) bool {
79-
return (!node.Spec.Unschedulable || util.MapContains(node.Labels, c.opConfig.NodeReadinessLabel) ||
79+
return (!node.Spec.Unschedulable || (len(c.opConfig.NodeReadinessLabel) > 0 && util.MapContains(node.Labels, c.opConfig.NodeReadinessLabel)) ||
8080
util.MapContains(node.Labels, map[string]string{"master": "true"}))
8181
}
8282

pkg/controller/node_test.go

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const (
1515

1616
func newNodeTestController() *Controller {
1717
var controller = NewController(&spec.ControllerConfig{}, "node-test")
18-
controller.opConfig.NodeReadinessLabel = map[string]string{readyLabel: readyValue}
1918
return controller
2019
}
2120

@@ -36,27 +35,58 @@ var nodeTestController = newNodeTestController()
3635
func TestNodeIsReady(t *testing.T) {
3736
testName := "TestNodeIsReady"
3837
var testTable = []struct {
39-
in *v1.Node
40-
out bool
38+
in *v1.Node
39+
out bool
40+
readinessLabel map[string]string
4141
}{
4242
{
43-
in: makeNode(map[string]string{"foo": "bar"}, true),
44-
out: true,
43+
in: makeNode(map[string]string{"foo": "bar"}, true),
44+
out: true,
45+
readinessLabel: map[string]string{readyLabel: readyValue},
4546
},
4647
{
47-
in: makeNode(map[string]string{"foo": "bar"}, false),
48-
out: false,
48+
in: makeNode(map[string]string{"foo": "bar"}, false),
49+
out: false,
50+
readinessLabel: map[string]string{readyLabel: readyValue},
4951
},
5052
{
51-
in: makeNode(map[string]string{readyLabel: readyValue}, false),
52-
out: true,
53+
in: makeNode(map[string]string{readyLabel: readyValue}, false),
54+
out: true,
55+
readinessLabel: map[string]string{readyLabel: readyValue},
5356
},
5457
{
55-
in: makeNode(map[string]string{"foo": "bar", "master": "true"}, false),
56-
out: true,
58+
in: makeNode(map[string]string{"foo": "bar", "master": "true"}, false),
59+
out: true,
60+
readinessLabel: map[string]string{readyLabel: readyValue},
61+
},
62+
{
63+
in: makeNode(map[string]string{"foo": "bar", "master": "true"}, false),
64+
out: true,
65+
readinessLabel: map[string]string{readyLabel: readyValue},
66+
},
67+
{
68+
in: makeNode(map[string]string{"foo": "bar"}, true),
69+
out: true,
70+
readinessLabel: map[string]string{},
71+
},
72+
{
73+
in: makeNode(map[string]string{"foo": "bar"}, false),
74+
out: false,
75+
readinessLabel: map[string]string{},
76+
},
77+
{
78+
in: makeNode(map[string]string{readyLabel: readyValue}, false),
79+
out: false,
80+
readinessLabel: map[string]string{},
81+
},
82+
{
83+
in: makeNode(map[string]string{"foo": "bar", "master": "true"}, false),
84+
out: true,
85+
readinessLabel: map[string]string{},
5786
},
5887
}
5988
for _, tt := range testTable {
89+
nodeTestController.opConfig.NodeReadinessLabel = tt.readinessLabel
6090
if isReady := nodeTestController.nodeIsReady(tt.in); isReady != tt.out {
6191
t.Errorf("%s: expected response %t doesn't match the actual %t for the node %#v",
6292
testName, tt.out, isReady, tt.in)

0 commit comments

Comments
 (0)