Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config-daemon not waiting for drain to complete #682

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,14 @@ func (dn *Daemon) nodeStateSyncHandler() error {
if reqDrain || !utils.ObjectHasAnnotation(dn.desiredNodeState,
consts.NodeStateDrainAnnotationCurrent,
consts.DrainIdle) {
if err := dn.handleDrain(reqReboot); err != nil {
drainInProcess, err := dn.handleDrain(reqReboot)
if err != nil {
log.Log.Error(err, "failed to handle drain")
return err
}
if drainInProcess {
return nil
}
SchSeba marked this conversation as resolved.
Show resolved Hide resolved
}

if !reqReboot && !vars.UsingSystemdMode {
Expand Down Expand Up @@ -560,54 +564,61 @@ func (dn *Daemon) nodeStateSyncHandler() error {
return nil
}

func (dn *Daemon) handleDrain(reqReboot bool) error {
// handleDrain: adds the right annotation to the node and nodeState object
// returns true if we need to finish the reconcile loop and wait for a new object
func (dn *Daemon) handleDrain(reqReboot bool) (bool, error) {
// done with the drain we can continue with the configuration
if utils.ObjectHasAnnotation(dn.desiredNodeState, consts.NodeStateDrainAnnotationCurrent, consts.DrainComplete) {
log.Log.Info("handleDrain(): the node complete the draining")
return nil
return false, nil
}

// the operator is still draining the node so we reconcile
if utils.ObjectHasAnnotation(dn.desiredNodeState, consts.NodeStateDrainAnnotationCurrent, consts.Draining) {
log.Log.Info("handleDrain(): the node is still draining")
return nil
return true, nil
}

// drain is disabled we continue with the configuration
if dn.disableDrain {
log.Log.Info("handleDrain(): drain is disabled in sriovOperatorConfig")
return nil
return false, nil
}

if reqReboot {
log.Log.Info("handleDrain(): apply 'Reboot_Required' annotation for node")
err := utils.AnnotateNode(context.Background(), vars.NodeName, consts.NodeDrainAnnotation, consts.RebootRequired, dn.client)
if err != nil {
log.Log.Error(err, "applyDrainRequired(): Failed to annotate node")
return err
return false, err
}

log.Log.Info("handleDrain(): apply 'Reboot_Required' annotation for nodeState")
if err := utils.AnnotateObject(context.Background(), dn.desiredNodeState,
consts.NodeStateDrainAnnotation,
consts.RebootRequired, dn.client); err != nil {
return err
return false, err
}

return nil
// the node was annotated we need to wait for the operator to finish the drain
return true, nil
}
log.Log.Info("handleDrain(): apply 'Drain_Required' annotation for node")
err := utils.AnnotateNode(context.Background(), vars.NodeName, consts.NodeDrainAnnotation, consts.DrainRequired, dn.client)
if err != nil {
log.Log.Error(err, "handleDrain(): Failed to annotate node")
return err
return false, err
}

log.Log.Info("handleDrain(): apply 'Drain_Required' annotation for nodeState")
if err := utils.AnnotateObject(context.Background(), dn.desiredNodeState,
consts.NodeStateDrainAnnotation,
consts.DrainRequired, dn.client); err != nil {
return err
return false, err
}

return nil
// the node was annotated we need to wait for the operator to finish the drain
return true, nil
}

func (dn *Daemon) restartDevicePluginPod() error {
Expand Down
15 changes: 9 additions & 6 deletions pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ var _ = Describe("Config Daemon", func() {

nodeState := &sriovnetworkv1.SriovNetworkNodeState{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Generation: 123,
Name: "test-node",
Generation: 123,
Annotations: map[string]string{consts.NodeStateDrainAnnotationCurrent: consts.DrainIdle},
},
Spec: sriovnetworkv1.SriovNetworkNodeStateSpec{},
Status: sriovnetworkv1.SriovNetworkNodeStateStatus{
Expand Down Expand Up @@ -253,8 +254,9 @@ var _ = Describe("Config Daemon", func() {

nodeState1 := &sriovnetworkv1.SriovNetworkNodeState{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Generation: 123,
Name: "test-node",
Generation: 123,
Annotations: map[string]string{consts.NodeStateDrainAnnotationCurrent: consts.DrainIdle},
},
}
Expect(
Expand All @@ -263,8 +265,9 @@ var _ = Describe("Config Daemon", func() {

nodeState2 := &sriovnetworkv1.SriovNetworkNodeState{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Generation: 777,
Name: "test-node",
Generation: 777,
Annotations: map[string]string{consts.NodeStateDrainAnnotationCurrent: consts.DrainIdle},
},
}
Expect(
Expand Down
Loading