@@ -113,9 +113,19 @@ var _ = Describe("Drain Controller", Ordered, func() {
113113 })
114114
115115 Context ("when there is only one node" , func () {
116+ It ("should not drain node on drain require while use-external-drainer annotation is set" ,
117+ func (ctx context.Context ) {
118+ node , nodeState := createNode (ctx , "node1" , true )
119+
120+ simulateDaemonSetAnnotation (node , constants .DrainRequired )
121+
122+ expectNodeStateAnnotation (nodeState , constants .DrainIdle )
123+ expectNodeIsSchedulable (node )
124+
125+ })
116126
117127 It ("should drain single node on drain require" , func (ctx context.Context ) {
118- node , nodeState := createNode (ctx , "node1" )
128+ node , nodeState := createNode (ctx , "node1" , false )
119129
120130 simulateDaemonSetAnnotation (node , constants .DrainRequired )
121131
@@ -129,7 +139,7 @@ var _ = Describe("Drain Controller", Ordered, func() {
129139 })
130140
131141 It ("should not drain on reboot for single node" , func (ctx context.Context ) {
132- node , nodeState := createNode (ctx , "node1" )
142+ node , nodeState := createNode (ctx , "node1" , false )
133143
134144 simulateDaemonSetAnnotation (node , constants .RebootRequired )
135145
@@ -142,8 +152,8 @@ var _ = Describe("Drain Controller", Ordered, func() {
142152 })
143153
144154 It ("should drain on reboot for multiple node" , func (ctx context.Context ) {
145- node , nodeState := createNode (ctx , "node1" )
146- createNode (ctx , "node2" )
155+ node , nodeState := createNode (ctx , "node1" , false )
156+ createNode (ctx , "node2" , false )
147157
148158 simulateDaemonSetAnnotation (node , constants .RebootRequired )
149159
@@ -159,9 +169,9 @@ var _ = Describe("Drain Controller", Ordered, func() {
159169 Context ("when there are multiple nodes" , func () {
160170
161171 It ("should drain nodes serially with default pool selector" , func (ctx context.Context ) {
162- node1 , nodeState1 := createNode (ctx , "node1" )
163- node2 , nodeState2 := createNode (ctx , "node2" )
164- node3 , nodeState3 := createNode (ctx , "node3" )
172+ node1 , nodeState1 := createNode (ctx , "node1" , false )
173+ node2 , nodeState2 := createNode (ctx , "node2" , false )
174+ node3 , nodeState3 := createNode (ctx , "node3" , false )
165175
166176 // Two nodes require to drain at the same time
167177 simulateDaemonSetAnnotation (node1 , constants .DrainRequired )
@@ -199,9 +209,9 @@ var _ = Describe("Drain Controller", Ordered, func() {
199209 })
200210
201211 It ("should drain nodes in parallel with a custom pool selector" , func (ctx context.Context ) {
202- node1 , nodeState1 := createNode (ctx , "node1" )
203- node2 , nodeState2 := createNode (ctx , "node2" )
204- node3 , nodeState3 := createNode (ctx , "node3" )
212+ node1 , nodeState1 := createNode (ctx , "node1" , false )
213+ node2 , nodeState2 := createNode (ctx , "node2" , false )
214+ node3 , nodeState3 := createNode (ctx , "node3" , false )
205215
206216 maxun := intstr .Parse ("2" )
207217 poolConfig := & sriovnetworkv1.SriovNetworkPoolConfig {}
@@ -250,9 +260,9 @@ var _ = Describe("Drain Controller", Ordered, func() {
250260 })
251261
252262 It ("should drain nodes in parallel with a custom pool selector and honor MaxUnavailable" , func (ctx context.Context ) {
253- node1 , nodeState1 := createNode (ctx , "node1" )
254- node2 , nodeState2 := createNode (ctx , "node2" )
255- node3 , nodeState3 := createNode (ctx , "node3" )
263+ node1 , nodeState1 := createNode (ctx , "node1" , false )
264+ node2 , nodeState2 := createNode (ctx , "node2" , false )
265+ node3 , nodeState3 := createNode (ctx , "node3" , false )
256266
257267 maxun := intstr .Parse ("2" )
258268 poolConfig := & sriovnetworkv1.SriovNetworkPoolConfig {}
@@ -275,9 +285,9 @@ var _ = Describe("Drain Controller", Ordered, func() {
275285 })
276286
277287 It ("should drain all nodes in parallel with a custom pool using nil in max unavailable" , func (ctx context.Context ) {
278- node1 , nodeState1 := createNode (ctx , "node1" )
279- node2 , nodeState2 := createNode (ctx , "node2" )
280- node3 , nodeState3 := createNode (ctx , "node3" )
288+ node1 , nodeState1 := createNode (ctx , "node1" , false )
289+ node2 , nodeState2 := createNode (ctx , "node2" , false )
290+ node3 , nodeState3 := createNode (ctx , "node3" , false )
281291
282292 poolConfig := & sriovnetworkv1.SriovNetworkPoolConfig {}
283293 poolConfig .SetNamespace (testNamespace )
@@ -303,7 +313,7 @@ var _ = Describe("Drain Controller", Ordered, func() {
303313 })
304314
305315 It ("should drain in parallel nodes from two different pools, one custom and one default" , func () {
306- node1 , nodeState1 := createNode (ctx , "node1" )
316+ node1 , nodeState1 := createNode (ctx , "node1" , false )
307317 node2 , nodeState2 := createNodeWithLabel (ctx , "node2" , "pool" )
308318 createPodOnNode (ctx , "test-node-2" , "node2" )
309319
@@ -326,7 +336,7 @@ var _ = Describe("Drain Controller", Ordered, func() {
326336 })
327337
328338 It ("should select all the nodes to drain in parallel when the selector is empty" , func () {
329- node1 , nodeState1 := createNode (ctx , "node3" )
339+ node1 , nodeState1 := createNode (ctx , "node3" , false )
330340 node2 , nodeState2 := createNodeWithLabel (ctx , "node4" , "pool" )
331341 createPodOnNode (ctx , "test-empty-1" , "node3" )
332342 createPodOnNode (ctx , "test-empty-2" , "node4" )
@@ -408,7 +418,7 @@ func simulateDaemonSetAnnotation(node *corev1.Node, drainAnnotationValue string)
408418 ToNot (HaveOccurred ())
409419}
410420
411- func createNode (ctx context.Context , nodeName string ) (* corev1.Node , * sriovnetworkv1.SriovNetworkNodeState ) {
421+ func createNode (ctx context.Context , nodeName string , useExternalDrainer bool ) (* corev1.Node , * sriovnetworkv1.SriovNetworkNodeState ) {
412422 node := corev1.Node {
413423 ObjectMeta : metav1.ObjectMeta {
414424 Name : nodeName ,
@@ -426,12 +436,16 @@ func createNode(ctx context.Context, nodeName string) (*corev1.Node, *sriovnetwo
426436 ObjectMeta : metav1.ObjectMeta {
427437 Name : nodeName ,
428438 Namespace : vars .Namespace ,
429- Labels : map [string ]string {
439+ Annotations : map [string ]string {
430440 constants .NodeStateDrainAnnotationCurrent : constants .DrainIdle ,
431441 },
432442 },
433443 }
434444
445+ if useExternalDrainer {
446+ nodeState .Annotations [constants .NodeStateExternalDrainerAnnotation ] = "true"
447+ }
448+
435449 Expect (k8sClient .Create (ctx , & node )).ToNot (HaveOccurred ())
436450 Expect (k8sClient .Create (ctx , & nodeState )).ToNot (HaveOccurred ())
437451
0 commit comments