Skip to content

Commit

Permalink
Exclude node being removed from nodelist for etcd client. Fix forLeader
Browse files Browse the repository at this point in the history
  • Loading branch information
Gab Satchi committed Jun 5, 2020
1 parent 4a4261f commit 1bb6561
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion controlplane/kubeadm/internal/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func NewEtcdClient(endpoints []string, dialer GRPCDial, tlsConfig *tls.Config) (
if err != nil {
return nil, errors.Wrap(err, "unable to create etcd client")
}
etcdClient.Endpoints()
return etcdClient, nil
}

Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/etcd_client_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *etcdClientGenerator) forLeader(ctx context.Context, nodes []corev1.Node
continue
}
for _, member := range members {
if member.ID == client.LeaderID {
if member.Name == node.Name && member.ID == client.LeaderID {
return c.forNodes(ctx, []corev1.Node{node})
}
}
Expand Down
11 changes: 9 additions & 2 deletions controlplane/kubeadm/internal/workload_cluster_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,22 @@ func (w *Workload) RemoveEtcdMemberForMachine(ctx context.Context, machine *clus
}

func (w *Workload) removeMemberForNode(ctx context.Context, name string) error {
// Pick a different node to talk to etcd
controlPlaneNodes, err := w.getControlPlaneNodes(ctx)
if err != nil {
return err
}
if len(controlPlaneNodes.Items) < 2 {
return ErrControlPlaneMinNodes
}
etcdClient, err := w.etcdClientGenerator.forNodes(ctx, controlPlaneNodes.Items)

// Exclude node being removed from etcd client node list
var remainingNodes []corev1.Node
for _, n := range controlPlaneNodes.Items {
if n.Name != name {
remainingNodes = append(remainingNodes, n)
}
}
etcdClient, err := w.etcdClientGenerator.forNodes(ctx, remainingNodes)
if err != nil {
return errors.Wrap(err, "failed to create etcd client")
}
Expand Down

0 comments on commit 1bb6561

Please sign in to comment.