Skip to content

Commit

Permalink
Merge pull request #421 from zeeke/check_MCP_after_pod_restart
Browse files Browse the repository at this point in the history
improve the isdraning check for openshift
  • Loading branch information
SchSeba authored Mar 23, 2023
2 parents 1e0d8ab + 69cedcf commit 708059d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,17 @@ func (dn *Daemon) nodeHasAnnotation(annoKey string, value string) bool {
}

func (dn *Daemon) isNodeDraining() bool {
if anno, ok := dn.node.Annotations[annoKey]; ok && (anno == annoDraining || anno == annoMcpPaused) {
return true
anno, ok := dn.node.Annotations[annoKey]
if !ok {
return false
}
return false

if dn.openshiftContext.IsOpenshiftCluster() && !dn.openshiftContext.IsHypershift() {
// for openshift cluster draining should be true only if the annotation has MCP paused
return anno == annoMcpPaused
}

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

func (dn *Daemon) completeDrain() error {
Expand Down
60 changes: 60 additions & 0 deletions pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,66 @@ SUBSYSTEM=="net", ACTION=="add|move", ATTRS{phys_switch_id}!="", ATTR{phys_port_
assertFileContents(networkManagerUdevRulePath, expectedContents)
})
})

Context("isNodeDraining", func() {

It("for a non-Openshift cluster", func() {
sut.openshiftContext = &utils.OpenshiftContext{IsOpenShiftCluster: false}

sut.node = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Annotations: map[string]string{}}}

Expect(sut.isNodeDraining()).To(BeFalse())

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

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

It("for an Openshift cluster", func() {
sut.openshiftContext = &utils.OpenshiftContext{
IsOpenShiftCluster: true,
OpenshiftFlavor: utils.OpenshiftFlavorDefault,
}

sut.node = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Annotations: map[string]string{}}}

Expect(sut.isNodeDraining()).To(BeFalse())

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

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

It("for an Openshift Hypershift cluster", func() {
sut.openshiftContext = &utils.OpenshiftContext{
IsOpenShiftCluster: true,
OpenshiftFlavor: utils.OpenshiftFlavorHypershift,
}

sut.node = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Annotations: map[string]string{}}}

Expect(sut.isNodeDraining()).To(BeFalse())

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

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

func createSriovNetworkNodeState(c snclientset.Interface, nodeState *sriovnetworkv1.SriovNetworkNodeState) error {
Expand Down

0 comments on commit 708059d

Please sign in to comment.