diff --git a/internal/dao/node.go b/internal/dao/node.go index b878d0ea81..8f9cb0b5bd 100644 --- a/internal/dao/node.go +++ b/internal/dao/node.go @@ -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 @@ -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...