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
This commit is contained in:
		
							parent
							
								
									e97235aa39
								
							
						
					
					
						commit
						7730ecfdec
					
				|  | @ -76,7 +76,7 @@ func (c *Controller) nodeUpdate(prev, cur interface{}) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Controller) nodeIsReady(node *v1.Node) bool { | func (c *Controller) nodeIsReady(node *v1.Node) bool { | ||||||
| 	return (!node.Spec.Unschedulable || util.MapContains(node.Labels, c.opConfig.NodeReadinessLabel) || | 	return (!node.Spec.Unschedulable || (len(c.opConfig.NodeReadinessLabel) > 0 && util.MapContains(node.Labels, c.opConfig.NodeReadinessLabel)) || | ||||||
| 		util.MapContains(node.Labels, map[string]string{"master": "true"})) | 		util.MapContains(node.Labels, map[string]string{"master": "true"})) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -15,7 +15,6 @@ const ( | ||||||
| 
 | 
 | ||||||
| func newNodeTestController() *Controller { | func newNodeTestController() *Controller { | ||||||
| 	var controller = NewController(&spec.ControllerConfig{}, "node-test") | 	var controller = NewController(&spec.ControllerConfig{}, "node-test") | ||||||
| 	controller.opConfig.NodeReadinessLabel = map[string]string{readyLabel: readyValue} |  | ||||||
| 	return controller | 	return controller | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -36,27 +35,58 @@ var nodeTestController = newNodeTestController() | ||||||
| func TestNodeIsReady(t *testing.T) { | func TestNodeIsReady(t *testing.T) { | ||||||
| 	testName := "TestNodeIsReady" | 	testName := "TestNodeIsReady" | ||||||
| 	var testTable = []struct { | 	var testTable = []struct { | ||||||
| 		in  *v1.Node | 		in             *v1.Node | ||||||
| 		out bool | 		out            bool | ||||||
|  | 		readinessLabel map[string]string | ||||||
| 	}{ | 	}{ | ||||||
| 		{ | 		{ | ||||||
| 			in:  makeNode(map[string]string{"foo": "bar"}, true), | 			in:             makeNode(map[string]string{"foo": "bar"}, true), | ||||||
| 			out: true, | 			out:            true, | ||||||
|  | 			readinessLabel: map[string]string{readyLabel: readyValue}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			in:  makeNode(map[string]string{"foo": "bar"}, false), | 			in:             makeNode(map[string]string{"foo": "bar"}, false), | ||||||
| 			out: false, | 			out:            false, | ||||||
|  | 			readinessLabel: map[string]string{readyLabel: readyValue}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			in:  makeNode(map[string]string{readyLabel: readyValue}, false), | 			in:             makeNode(map[string]string{readyLabel: readyValue}, false), | ||||||
| 			out: true, | 			out:            true, | ||||||
|  | 			readinessLabel: map[string]string{readyLabel: readyValue}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			in:  makeNode(map[string]string{"foo": "bar", "master": "true"}, false), | 			in:             makeNode(map[string]string{"foo": "bar", "master": "true"}, false), | ||||||
| 			out: true, | 			out:            true, | ||||||
|  | 			readinessLabel: map[string]string{readyLabel: readyValue}, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			in:             makeNode(map[string]string{"foo": "bar", "master": "true"}, false), | ||||||
|  | 			out:            true, | ||||||
|  | 			readinessLabel: map[string]string{readyLabel: readyValue}, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			in:             makeNode(map[string]string{"foo": "bar"}, true), | ||||||
|  | 			out:            true, | ||||||
|  | 			readinessLabel: map[string]string{}, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			in:             makeNode(map[string]string{"foo": "bar"}, false), | ||||||
|  | 			out:            false, | ||||||
|  | 			readinessLabel: map[string]string{}, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			in:             makeNode(map[string]string{readyLabel: readyValue}, false), | ||||||
|  | 			out:            false, | ||||||
|  | 			readinessLabel: map[string]string{}, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			in:             makeNode(map[string]string{"foo": "bar", "master": "true"}, false), | ||||||
|  | 			out:            true, | ||||||
|  | 			readinessLabel: map[string]string{}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	for _, tt := range testTable { | 	for _, tt := range testTable { | ||||||
|  | 		nodeTestController.opConfig.NodeReadinessLabel = tt.readinessLabel | ||||||
| 		if isReady := nodeTestController.nodeIsReady(tt.in); isReady != tt.out { | 		if isReady := nodeTestController.nodeIsReady(tt.in); isReady != tt.out { | ||||||
| 			t.Errorf("%s: expected response %t doesn't match the actual %t for the node %#v", | 			t.Errorf("%s: expected response %t doesn't match the actual %t for the node %#v", | ||||||
| 				testName, tt.out, isReady, tt.in) | 				testName, tt.out, isReady, tt.in) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue