|
51 | 51 | ) |
52 | 52 |
|
53 | 53 | const ( |
54 | | - waitTime = 30 * time.Minute |
| 54 | + waitTime = 10 * time.Second |
55 | 55 | retryTime = 5 * time.Second |
| 56 | + nodeName = "node1" |
56 | 57 | ) |
57 | 58 |
|
58 | 59 | var _ = Describe("Daemon Controller", Ordered, func() { |
@@ -151,7 +152,7 @@ var _ = Describe("Daemon Controller", Ordered, func() { |
151 | 152 | daemonReconciler = createDaemon(hostHelper, platformHelper, featureGates, []string{}) |
152 | 153 | startDaemon(daemonReconciler) |
153 | 154 |
|
154 | | - _, nodeState = createNode("node1") |
| 155 | + _, nodeState = createNode(nodeName) |
155 | 156 | }) |
156 | 157 |
|
157 | 158 | AfterAll(func() { |
@@ -253,6 +254,11 @@ var _ = Describe("Daemon Controller", Ordered, func() { |
253 | 254 | ToNot(HaveOccurred()) |
254 | 255 |
|
255 | 256 | g.Expect(nodeState.Annotations[constants.NodeStateDrainAnnotation]).To(Equal(constants.DrainRequired)) |
| 257 | + // verify that external drainer annotation doesn't exist |
| 258 | + node := &corev1.Node{} |
| 259 | + g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: nodeName}, node)). |
| 260 | + ToNot(HaveOccurred()) |
| 261 | + g.Expect(node.Annotations).NotTo(ContainElement(constants.NodeExternalDrainerAnnotation)) |
256 | 262 | }, waitTime, retryTime).Should(Succeed()) |
257 | 263 |
|
258 | 264 | patchAnnotation(nodeState, constants.NodeStateDrainAnnotationCurrent, constants.DrainComplete) |
@@ -334,6 +340,73 @@ var _ = Describe("Daemon Controller", Ordered, func() { |
334 | 340 | eventuallySyncStatusEqual(nodeState, constants.SyncStatusSucceeded) |
335 | 341 | assertLastStatusTransitionsContains(nodeState, 2, constants.SyncStatusInProgress) |
336 | 342 | }) |
| 343 | + |
| 344 | + It("Should apply external drainer annotation when useExternalDrainer is true", func(ctx context.Context) { |
| 345 | + DeferCleanup(func(x bool) { vars.UseExternalDrainer = x }, vars.UseExternalDrainer) |
| 346 | + vars.UseExternalDrainer = true |
| 347 | + |
| 348 | + discoverSriovReturn.Store(&[]sriovnetworkv1.InterfaceExt{ |
| 349 | + { |
| 350 | + Name: "eno1", |
| 351 | + Driver: "ice", |
| 352 | + PciAddress: "0000:16:00.0", |
| 353 | + DeviceID: "1593", |
| 354 | + Vendor: "8086", |
| 355 | + EswitchMode: "legacy", |
| 356 | + LinkAdminState: "up", |
| 357 | + LinkSpeed: "10000 Mb/s", |
| 358 | + LinkType: "ETH", |
| 359 | + Mac: "aa:bb:cc:dd:ee:ff", |
| 360 | + Mtu: 1500, |
| 361 | + TotalVfs: 2, |
| 362 | + NumVfs: 0, |
| 363 | + }, |
| 364 | + }) |
| 365 | + |
| 366 | + By("waiting for state to be in progress") |
| 367 | + eventuallySyncStatusEqual(nodeState, constants.SyncStatusInProgress) |
| 368 | + |
| 369 | + err := k8sClient.Get(ctx, types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState) |
| 370 | + Expect(err).ToNot(HaveOccurred()) |
| 371 | + |
| 372 | + By("waiting to require drain") |
| 373 | + err = k8sClient.Get(ctx, types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState) |
| 374 | + Expect(err).ToNot(HaveOccurred()) |
| 375 | + nodeState.Spec.Interfaces = []sriovnetworkv1.Interface{} |
| 376 | + err = k8sClient.Update(ctx, nodeState) |
| 377 | + Expect(err).ToNot(HaveOccurred()) |
| 378 | + |
| 379 | + EventuallyWithOffset(1, func(g Gomega) { |
| 380 | + g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState)). |
| 381 | + ToNot(HaveOccurred()) |
| 382 | + |
| 383 | + g.Expect(nodeState.Annotations[constants.NodeStateDrainAnnotation]).To(Equal(constants.DrainRequired)) |
| 384 | + }, waitTime, retryTime).Should(Succeed()) |
| 385 | + |
| 386 | + // Validate status |
| 387 | + EventuallyWithOffset(1, func(g Gomega) { |
| 388 | + // get node by name |
| 389 | + node := &corev1.Node{} |
| 390 | + g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: nodeName}, node)). |
| 391 | + ToNot(HaveOccurred()) |
| 392 | + g.Expect(node.Annotations[constants.NodeExternalDrainerAnnotation]).To(Equal("true")) |
| 393 | + }, waitTime, retryTime).Should(Succeed()) |
| 394 | + |
| 395 | + patchAnnotation(nodeState, constants.NodeStateDrainAnnotationCurrent, constants.DrainComplete) |
| 396 | + // Validate status |
| 397 | + EventuallyWithOffset(1, func(g Gomega) { |
| 398 | + g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState)). |
| 399 | + ToNot(HaveOccurred()) |
| 400 | + |
| 401 | + g.Expect(nodeState.Status.SyncStatus).To(Equal(constants.SyncStatusInProgress)) |
| 402 | + node := &corev1.Node{} |
| 403 | + g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: nodeName}, node)). |
| 404 | + ToNot(HaveOccurred()) |
| 405 | + // verify that external drainer annotation is removed |
| 406 | + g.Expect(node.Annotations).NotTo(ContainElement(constants.NodeExternalDrainerAnnotation)) |
| 407 | + }, waitTime, retryTime).Should(Succeed()) |
| 408 | + |
| 409 | + }) |
337 | 410 | }) |
338 | 411 | }) |
339 | 412 |
|
|
0 commit comments