Skip to content

Commit

Permalink
Merge pull request k0sproject#3803 from k0sproject/backport-3794-to-r…
Browse files Browse the repository at this point in the history
…elease-1.26

[Backport release-1.26] fetch node object from apiserver when (un)cordoning
  • Loading branch information
jnummelin authored Dec 15, 2023
2 parents 72d5541 + 8162c97 commit c6603b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
17 changes: 14 additions & 3 deletions pkg/autopilot/controller/signal/k0s/cordon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
18 changes: 15 additions & 3 deletions pkg/autopilot/controller/signal/k0s/uncordon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit c6603b1

Please sign in to comment.