Skip to content

Commit

Permalink
check if the Node already cordoned when executing Drain (derailed#2275)
Browse files Browse the repository at this point in the history
* check if the Node already cordoned when executing Drain

* ensure node cordoned
  • Loading branch information
wjiec authored and thejoeejoee committed Jan 31, 2024
1 parent 652a4d4 commit 81f3d86
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/dao/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ func (o DrainOptions) toDrainHelper(k kubernetes.Interface, w io.Writer) drain.H

// Drain drains a node.
func (n *Node) Drain(path string, opts DrainOptions, w io.Writer) error {
if err := n.ToggleCordon(path, true); err != nil {
cordoned, err := n.ensureCordoned(path)
if err != nil {
return err
}

if !cordoned {
if err = n.ToggleCordon(path, true); err != nil {
return err
}
}

dial, err := n.GetFactory().Client().Dial()
if err != nil {
return err
Expand Down Expand Up @@ -217,6 +224,16 @@ func (n *Node) GetPods(nodeName string) ([]*v1.Pod, error) {
return pp, nil
}

// ensureCordoned returns whether the given node has been cordoned
func (n *Node) ensureCordoned(path string) (bool, error) {
o, err := FetchNode(context.Background(), n.Factory, path)
if err != nil {
return false, err
}

return o.Spec.Unschedulable, nil
}

// ----------------------------------------------------------------------------
// Helpers...

Expand Down

0 comments on commit 81f3d86

Please sign in to comment.