diff --git a/pkg/autopilot/controller/signal/k0s/cordon.go b/pkg/autopilot/controller/signal/k0s/cordon.go index d339d1254780..de79bd850a83 100644 --- a/pkg/autopilot/controller/signal/k0s/cordon.go +++ b/pkg/autopilot/controller/signal/k0s/cordon.go @@ -147,9 +147,20 @@ func (r *cordoning) moveToNextState(ctx context.Context, signalNode crcli.Object // draining ignores daemonsets func (r *cordoning) drainNode(ctx context.Context, signalNode crcli.Object) error { logger := r.log.WithField("signalnode", signalNode.GetName()).WithField("phase", "drain") - node, ok := signalNode.(*corev1.Node) - if !ok { - return fmt.Errorf("failed to covert signalNode to Node") + + node := &corev1.Node{} + // if signalNode is a Node cast it to *corev1.Node + if signalNode.GetObjectKind().GroupVersionKind().Kind == "Node" { + var ok bool + node, ok = signalNode.(*corev1.Node) + if !ok { + return fmt.Errorf("failed to cast signalNode to *corev1.Node") + } + } else { + //otherwise get node from client + if err := r.client.Get(ctx, crcli.ObjectKey{Name: signalNode.GetName()}, node); err != nil { + return fmt.Errorf("failed to get node: %w", err) + } } drainer := &drain.Helper{ diff --git a/pkg/autopilot/controller/signal/k0s/uncordon.go b/pkg/autopilot/controller/signal/k0s/uncordon.go index f72cdbf35244..f8c39e5cee40 100644 --- a/pkg/autopilot/controller/signal/k0s/uncordon.go +++ b/pkg/autopilot/controller/signal/k0s/uncordon.go @@ -146,9 +146,21 @@ func (r *uncordoning) moveToNextState(ctx context.Context, signalNode crcli.Obje // unCordonNode un-cordons a node func (r *uncordoning) unCordonNode(ctx context.Context, signalNode crcli.Object) error { logger := r.log.WithField("signalnode", signalNode.GetName()).WithField("phase", "uncordon") - node, ok := signalNode.(*corev1.Node) - if !ok { - return fmt.Errorf("failed to covert signalNode to Node") + + node := &corev1.Node{} + + // if signalNode is a Node cast it to *corev1.Node + if signalNode.GetObjectKind().GroupVersionKind().Kind == "Node" { + var ok bool + node, ok = signalNode.(*corev1.Node) + if !ok { + return fmt.Errorf("failed to convert signalNode to Node") + } + } else { + //otherwise get node from client + if err := r.client.Get(ctx, crcli.ObjectKey{Name: signalNode.GetName()}, node); err != nil { + return fmt.Errorf("failed to get node: %w", err) + } } drainer := &drain.Helper{