Skip to content

Commit

Permalink
Merge pull request #4242 from fabriziopandini/fix-kcp-remediation-whe…
Browse files Browse the repository at this point in the history
…n-nodeName!=machineName-0.3b

🐛 Fix KCP remediation when node Name & etcd member Name != machine Name
  • Loading branch information
k8s-ci-robot authored Mar 2, 2021
2 parents a2ead11 + e25ec2c commit 681073d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion controlplane/kubeadm/controllers/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (r *KubeadmControlPlaneReconciler) canSafelyRemoveEtcdMember(ctx context.Co
unhealthyMembers := []string{}
for _, etcdMember := range etcdMembers {
// Skip the machine to be deleted because it won't be part of the target etcd cluster.
if etcdMember == machineToBeRemediated.Name {
if machineToBeRemediated.Status.NodeRef != nil && machineToBeRemediated.Status.NodeRef.Name == etcdMember {
continue
}

Expand Down
37 changes: 24 additions & 13 deletions controlplane/kubeadm/controllers/remediation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"fmt"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -155,7 +156,7 @@ func TestReconcileUnhealthyMachines(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -191,7 +192,7 @@ func TestReconcileUnhealthyMachines(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -230,7 +231,7 @@ func TestReconcileUnhealthyMachines(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -283,7 +284,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -314,7 +315,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -346,7 +347,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -378,7 +379,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -412,7 +413,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -446,7 +447,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -482,7 +483,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand Down Expand Up @@ -518,7 +519,7 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
recorder: record.NewFakeRecorder(32),
managementCluster: &fakeManagementCluster{
Workload: fakeWorkloadCluster{
EtcdMembersResult: controlPlane.Machines.Names(),
EtcdMembersResult: nodes(controlPlane.Machines),
},
},
}
Expand All @@ -532,6 +533,16 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {
g.Expect(testEnv.Cleanup(ctx, ns)).To(Succeed())
}

func nodes(machines internal.FilterableMachineCollection) []string {
nodes := make([]string, 0, machines.Len())
for _, m := range machines {
if m.Status.NodeRef != nil {
nodes = append(nodes, m.Status.NodeRef.Name)
}
}
return nodes
}

type machineOption func(*clusterv1.Machine)

func withMachineHealthCheckFailed() machineOption {
Expand Down Expand Up @@ -580,7 +591,7 @@ func createMachine(ctx context.Context, g *WithT, namespace, name string, option
patchHelper, err := patch.NewHelper(m, testEnv.GetClient())
g.Expect(err).ToNot(HaveOccurred())

for _, opt := range append(options, withNodeRef(m.Name)) {
for _, opt := range append(options, withNodeRef(fmt.Sprintf("node-%s", m.Name))) {
opt(m)
}

Expand All @@ -604,7 +615,7 @@ func getDeletingMachine(namespace, name string, options ...machineOption) *clust
},
}

for _, opt := range append(options, withNodeRef(m.Name)) {
for _, opt := range append(options, withNodeRef(fmt.Sprintf("node-%s", m.Name))) {
opt(m)
}
return m
Expand Down

0 comments on commit 681073d

Please sign in to comment.