Skip to content

Commit 78611fd

Browse files
authored
Merge pull request #1038 from SchSeba/fix_waiting_for_dp_when_no_policy
daemon: skip device plugin wait when no policies are configured
2 parents 05cfc47 + 57e8efb commit 78611fd

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

pkg/daemon/daemon.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ func (dn *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
216216
}
217217
// periodically ensure device plugin is unblocked,
218218
// this is required to ensure that device plugin can start in case if it is restarted for some reason
219-
if vars.FeatureGate.IsEnabled(consts.BlockDevicePluginUntilConfiguredFeatureGate) {
219+
if vars.FeatureGate.IsEnabled(consts.BlockDevicePluginUntilConfiguredFeatureGate) &&
220+
len(desiredNodeState.Spec.Interfaces) > 0 {
220221
devicePluginPods, err := dn.getDevicePluginPodsForNode(ctx)
221222
if err != nil {
222223
reqLogger.Error(err, "failed to get device plugin pods")
@@ -410,9 +411,13 @@ func (dn *NodeReconciler) apply(ctx context.Context, desiredNodeState *sriovnetw
410411
}
411412

412413
if vars.FeatureGate.IsEnabled(consts.BlockDevicePluginUntilConfiguredFeatureGate) {
413-
if err := dn.waitForDevicePluginPodAndTryUnblock(ctx, desiredNodeState); err != nil {
414-
reqLogger.Error(err, "failed to wait for device plugin pod to start and try to unblock it")
415-
return ctrl.Result{}, err
414+
if len(desiredNodeState.Spec.Interfaces) == 0 {
415+
reqLogger.Info("no interfaces in desired state, skipping device plugin wait as device plugin won't be deployed")
416+
} else {
417+
if err := dn.waitForDevicePluginPodAndTryUnblock(ctx, desiredNodeState); err != nil {
418+
reqLogger.Error(err, "failed to wait for device plugin pod to start and try to unblock it")
419+
return ctrl.Result{}, err
420+
}
416421
}
417422
} else {
418423
// if the feature gate is not enabled we preserver the old behavior

pkg/daemon/daemon_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,39 @@ var _ = Describe("Daemon Controller", Ordered, func() {
590590
}, waitTime, retryTime).Should(Succeed())
591591
})
592592

593+
It("Should not wait for device plugin pod when there are no interfaces and blockDevicePluginUntilConfigured is enabled", func(ctx context.Context) {
594+
DeferCleanup(func(x bool) { vars.DisableDrain = x }, vars.DisableDrain)
595+
vars.DisableDrain = true
596+
597+
By("waiting for drain idle states")
598+
EventuallyWithOffset(1, func(g Gomega) {
599+
g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState)).
600+
ToNot(HaveOccurred())
601+
602+
g.Expect(nodeState.Annotations[constants.NodeStateDrainAnnotation]).To(Equal(constants.DrainIdle))
603+
g.Expect(nodeState.Annotations[constants.NodeStateDrainAnnotationCurrent]).To(Equal(constants.DrainIdle))
604+
}, waitTime, retryTime).Should(Succeed())
605+
606+
By("setting an empty interfaces spec (no policies)")
607+
EventuallyWithOffset(1, func(g Gomega) {
608+
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: nodeState.Namespace, Name: nodeState.Name}, nodeState)
609+
g.Expect(err).ToNot(HaveOccurred())
610+
611+
nodeState.Spec.Interfaces = []sriovnetworkv1.Interface{}
612+
err = k8sClient.Update(ctx, nodeState)
613+
g.Expect(err).ToNot(HaveOccurred())
614+
}, waitTime, retryTime).Should(Succeed())
615+
616+
By("verifying sync status reaches Succeeded without stalling on device plugin wait")
617+
eventuallySyncStatusEqual(nodeState, constants.SyncStatusSucceeded)
618+
619+
By("verifying the device plugin pod still has the wait-for-config annotation (was not unblocked)")
620+
devicePluginPod := &corev1.Pod{}
621+
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: devicePluginPodName, Namespace: testNamespace},
622+
devicePluginPod)).ToNot(HaveOccurred())
623+
Expect(devicePluginPod.Annotations).To(HaveKey(constants.DevicePluginWaitConfigAnnotation))
624+
})
625+
593626
It("Should unblock the device plugin pod when configuration is finished", func(ctx context.Context) {
594627
DeferCleanup(func(x bool) { vars.DisableDrain = x }, vars.DisableDrain)
595628
vars.DisableDrain = true

0 commit comments

Comments
 (0)