Skip to content

Commit 0b64b4a

Browse files
heyvister1nvidia-ci-cd
authored andcommitted
fix: current code was not deleting 'sriovnetwork.openshift.io/use-external-drainer' annotation, it was only setting empty annotation value
Signed-off-by: Ido Heyvi <iheyvi@nvidia.com>
1 parent e3a9850 commit 0b64b4a

File tree

2 files changed

+58
-18
lines changed

2 files changed

+58
-18
lines changed

pkg/daemon/daemon.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,16 @@ func (dn *NodeReconciler) apply(ctx context.Context, desiredNodeState *sriovnetw
424424
return ctrl.Result{}, err
425425
}
426426

427-
// remove external drainer nodestate annotation
428-
err = utils.AnnotateObject(ctx, desiredNodeState,
429-
consts.NodeStateExternalDrainerAnnotation, "", dn.client)
430-
if err != nil {
431-
if !errors.IsNotFound(err) {
432-
reqLogger.Error(err, "failed to remove node external drainer annotation")
427+
// remove external drainer nodestate annotation if exists
428+
annotations := desiredNodeState.GetAnnotations()
429+
if _, ok := annotations[consts.NodeStateExternalDrainerAnnotation]; ok {
430+
reqLogger.Info("remove external drainer nodestate annotation", "annotation", consts.NodeStateExternalDrainerAnnotation)
431+
original := desiredNodeState.DeepCopy()
432+
delete(annotations, consts.NodeStateExternalDrainerAnnotation)
433+
desiredNodeState.SetAnnotations(annotations)
434+
// Patch only the annotations
435+
if err := dn.client.Patch(ctx, desiredNodeState, client.MergeFrom(original)); err != nil {
436+
reqLogger.Error(err, "failed to patch nodestate after removing external drainer annotation")
433437
return ctrl.Result{}, err
434438
}
435439
}
@@ -563,7 +567,7 @@ func (dn *NodeReconciler) handleDrain(ctx context.Context, desiredNodeState *sri
563567
err := utils.AnnotateObject(ctx, desiredNodeState,
564568
consts.NodeStateExternalDrainerAnnotation, "true", dn.client)
565569
if err != nil {
566-
funcLog.Error(err, "failed to add node external drainer annotation")
570+
funcLog.Error(err, "failed to add nodestate external drainer annotation")
567571
return false, err
568572
}
569573
}

pkg/daemon/daemon_test.go

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,18 @@ var _ = Describe("Daemon Controller", Ordered, func() {
347347
err := k8sClient.Update(ctx, nodeState)
348348
Expect(err).ToNot(HaveOccurred())
349349

350+
nodeState = &sriovnetworkv1.SriovNetworkNodeState{ObjectMeta: metav1.ObjectMeta{Name: nodeName, Namespace: testNamespace}}
350351
eventuallySyncStatusEqual(nodeState, constants.SyncStatusSucceeded)
351352

352353
By("Simulate node policy removal")
353-
nodeState.Spec.Interfaces = []sriovnetworkv1.Interface{}
354-
err = k8sClient.Update(ctx, nodeState)
355-
Expect(err).ToNot(HaveOccurred())
354+
EventuallyWithOffset(1, func(g Gomega) {
355+
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState)
356+
g.Expect(err).ToNot(HaveOccurred())
357+
358+
nodeState.Spec.Interfaces = []sriovnetworkv1.Interface{}
359+
err = k8sClient.Update(ctx, nodeState)
360+
g.Expect(err).ToNot(HaveOccurred())
361+
}, waitTime, retryTime).Should(Succeed())
356362

357363
eventuallySyncStatusEqual(nodeState, constants.SyncStatusSucceeded)
358364
assertLastStatusTransitionsContains(nodeState, 2, constants.SyncStatusInProgress)
@@ -361,7 +367,6 @@ var _ = Describe("Daemon Controller", Ordered, func() {
361367
It("Should apply external drainer annotation when useExternalDrainer is true", func(ctx context.Context) {
362368
DeferCleanup(func(x bool) { vars.UseExternalDrainer = x }, vars.UseExternalDrainer)
363369
vars.UseExternalDrainer = true
364-
365370
discoverSriovReturn.Store(&[]sriovnetworkv1.InterfaceExt{
366371
{
367372
Name: "eno1",
@@ -375,16 +380,47 @@ var _ = Describe("Daemon Controller", Ordered, func() {
375380
LinkType: "ETH",
376381
Mac: "aa:bb:cc:dd:ee:ff",
377382
Mtu: 1500,
378-
TotalVfs: 2,
379-
NumVfs: 0,
383+
TotalVfs: 3,
384+
NumVfs: 3,
385+
VFs: []sriovnetworkv1.VirtualFunction{
386+
{
387+
Name: "eno1f0",
388+
PciAddress: "0000:16:00.1",
389+
VfID: 0,
390+
},
391+
{
392+
Name: "eno1f1",
393+
PciAddress: "0000:16:00.2",
394+
VfID: 1,
395+
},
396+
{
397+
Name: "eno1f2",
398+
PciAddress: "0000:16:00.3",
399+
VfID: 2,
400+
},
401+
},
380402
},
381403
})
382404

383-
By("waiting for state to be in progress")
384-
eventuallySyncStatusEqual(nodeState, constants.SyncStatusInProgress)
385-
386-
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState)
387-
Expect(err).ToNot(HaveOccurred())
405+
EventuallyWithOffset(1, func(g Gomega) {
406+
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState)
407+
g.Expect(err).ToNot(HaveOccurred())
408+
409+
nodeState.Spec.Interfaces = []sriovnetworkv1.Interface{
410+
{Name: "eno1",
411+
PciAddress: "0000:16:00.0",
412+
LinkType: "eth",
413+
NumVfs: 3,
414+
VfGroups: []sriovnetworkv1.VfGroup{
415+
{ResourceName: "test",
416+
DeviceType: "netdevice",
417+
PolicyName: "test-policy",
418+
VfRange: "0-2"},
419+
}},
420+
}
421+
err = k8sClient.Update(ctx, nodeState)
422+
g.Expect(err).ToNot(HaveOccurred())
423+
}, waitTime, retryTime).Should(Succeed())
388424

389425
By("waiting to require drain")
390426
EventuallyWithOffset(1, func(g Gomega) {

0 commit comments

Comments
 (0)