From 88b1ebc0c496030a075f716b376f4522c6959050 Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Wed, 4 Dec 2024 19:37:02 +0200 Subject: [PATCH] Remove etcdmember that left the cluster Signed-off-by: Alexey Makhov --- internal/controller/controlplane/helper.go | 9 +++++++++ .../capi_docker_machine_change_template_test.go | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/internal/controller/controlplane/helper.go b/internal/controller/controlplane/helper.go index e2ac879bd..5532d9115 100644 --- a/internal/controller/controlplane/helper.go +++ b/internal/controller/controlplane/helper.go @@ -286,6 +286,15 @@ func (c *K0sController) checkMachineLeft(ctx context.Context, name string, clien for _, condition := range conditions { conditionMap := condition.(map[string]interface{}) if conditionMap["type"] == etcdMemberConditionTypeJoined && conditionMap["status"] == "False" { + err = clientset.RESTClient(). + Delete(). + AbsPath("/apis/etcd.k0sproject.io/v1beta1/etcdmembers/" + name). + Do(ctx). + Into(&etcdMember) + if err != nil && !apierrors.IsNotFound(err) { + return false, fmt.Errorf("error deleting etcd member %s: %w", name, err) + } + return true, nil } } diff --git a/inttest/capi-docker-machine-change-template/capi_docker_machine_change_template_test.go b/inttest/capi-docker-machine-change-template/capi_docker_machine_change_template_test.go index 48ddb9981..fdb7f4d4e 100644 --- a/inttest/capi-docker-machine-change-template/capi_docker_machine_change_template_test.go +++ b/inttest/capi-docker-machine-change-template/capi_docker_machine_change_template_test.go @@ -210,6 +210,16 @@ func (s *CAPIDockerMachineChangeTemplate) TestCAPIControlPlaneDockerDownScaling( Into(&obj) s.Require().NoError(err) s.Require().Equal("docker-test-cp-template-new-2", obj.GetAnnotations()[clusterv1.TemplateClonedFromNameAnnotation]) + + err = wait.PollUntilContextCancel(s.ctx, 1*time.Second, true, func(ctx context.Context) (bool, error) { + b, _ := s.client.RESTClient(). + Get(). + AbsPath("/healthz"). + DoRaw(context.Background()) + + return string(b) == "ok", nil + }) + s.Require().NoError(err) } func (s *CAPIDockerMachineChangeTemplate) applyClusterObjects() {