Skip to content

Commit

Permalink
Use Node name instead of Machine name on removal (#46)
Browse files Browse the repository at this point in the history
Use Node name instead of Machine name on removal
  • Loading branch information
HomayoonAlimohammadi authored Aug 28, 2024
1 parent 952459b commit f9d6a96
Showing 1 changed file with 10 additions and 2 deletions.
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
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

0 comments on commit f9d6a96

Please sign in to comment.