Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Node name instead of Machine name on removal #46

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pkg/ck8s/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,19 @@ func (w *Workload) requestJoinToken(ctx context.Context, name string, worker boo
}

func (w *Workload) RemoveMachineFromCluster(ctx context.Context, machine *clusterv1.Machine) error {
request := &apiv1.RemoveNodeRequest{Name: machine.Name, Force: true}
if machine == nil {
return fmt.Errorf("machine object is not set")
}
if machine.Status.NodeRef == nil {
return fmt.Errorf("machine %s has no node reference", machine.Name)
}

nodeName := machine.Status.NodeRef.Name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work finding the root cause. I only have one question, otherwise this looks good. Is Status.NodeRef set automatically by CAPI's Machine controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is part of the CAPI contract.

request := &apiv1.RemoveNodeRequest{Name: nodeName, Force: true}

// If we see that ignoring control-planes is causing issues, let's consider removing it.
// It *should* not be necessary as a machine should be able to remove itself from the cluster.
err := w.doK8sdRequest(ctx, http.MethodPost, "1.0/x/capi/remove-node", request, nil, k8sdProxyOptions{IgnoreNodes: map[string]struct{}{machine.Name: {}}})
err := w.doK8sdRequest(ctx, http.MethodPost, "1.0/x/capi/remove-node", request, nil, k8sdProxyOptions{IgnoreNodes: map[string]struct{}{nodeName: {}}})
if err != nil {
return fmt.Errorf("failed to remove %s from cluster: %w", machine.Name, err)
}
Expand Down