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 race condition in leader election for OCP #455

Merged
merged 1 commit into from
Jun 14, 2023
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
32 changes: 14 additions & 18 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,22 @@ func (dn *Daemon) nodeStateSyncHandler() error {
go dn.getDrainLock(ctx, done)
<-done
}
}

if dn.openshiftContext.IsOpenshiftCluster() && !dn.openshiftContext.IsHypershift() {
glog.Infof("nodeStateSyncHandler(): pause MCP")
if err := dn.pauseMCP(); err != nil {
return err
}
if dn.openshiftContext.IsOpenshiftCluster() && !dn.openshiftContext.IsHypershift() {
glog.Infof("nodeStateSyncHandler(): pause MCP")
if err := dn.pauseMCP(); err != nil {
return err
}
}

glog.Info("nodeStateSyncHandler(): drain node")
if err := dn.drainNode(); err != nil {
return err
if dn.disableDrain {
adrianchiris marked this conversation as resolved.
Show resolved Hide resolved
glog.Info("nodeStateSyncHandler(): disable drain is true skipping drain")
} else {
glog.Info("nodeStateSyncHandler(): drain node")
if err := dn.drainNode(); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -578,17 +582,14 @@ func (dn *Daemon) nodeHasAnnotation(annoKey string, value string) bool {
return false
}

// isNodeDraining: check if the node is draining
// both Draining and MCP paused labels will return true
func (dn *Daemon) isNodeDraining() bool {
anno, ok := dn.node.Annotations[annoKey]
if !ok {
return false
}

if dn.openshiftContext.IsOpenshiftCluster() && !dn.openshiftContext.IsHypershift() {
SchSeba marked this conversation as resolved.
Show resolved Hide resolved
// for openshift cluster draining should be true only if the annotation has MCP paused
return anno == annoMcpPaused
}

return anno == annoDraining || anno == annoMcpPaused
}

Expand Down Expand Up @@ -895,11 +896,6 @@ func (dn *Daemon) pauseMCP() error {
}

func (dn *Daemon) drainNode() error {
if dn.disableDrain {
glog.Info("drainNode(): disable drain is true skipping drain")
return nil
}

glog.Info("drainNode(): Update prepared")
var err error

Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ SUBSYSTEM=="net", ACTION=="add|move", ATTRS{phys_switch_id}!="", ATTR{phys_port_
Expect(sut.isNodeDraining()).To(BeFalse())

sut.node.Annotations["sriovnetwork.openshift.io/state"] = "Draining"
Expect(sut.isNodeDraining()).To(BeFalse())
Expect(sut.isNodeDraining()).To(BeTrue())

sut.node.Annotations["sriovnetwork.openshift.io/state"] = "Draining_MCP_Paused"
Expect(sut.isNodeDraining()).To(BeTrue())
Expand Down