From c738dc9293f265461d192c0bccc10b47760af28d Mon Sep 17 00:00:00 2001 From: Jussi Nummelin Date: Fri, 26 Apr 2024 11:22:10 +0300 Subject: [PATCH] Fix timing issue in EtcdMember inttest Signed-off-by: Jussi Nummelin --- inttest/etcdmember/etcdmember_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/inttest/etcdmember/etcdmember_test.go b/inttest/etcdmember/etcdmember_test.go index df606223cc57..c40287a59588 100644 --- a/inttest/etcdmember/etcdmember_test.go +++ b/inttest/etcdmember/etcdmember_test.go @@ -27,6 +27,8 @@ import ( "github.com/stretchr/testify/suite" etcdv1beta1 "github.com/k0sproject/k0s/pkg/apis/etcd/v1beta1" + + apierrors "k8s.io/apimachinery/pkg/api/errors" ) type EtcdMemberSuite struct { @@ -79,8 +81,22 @@ func (s *EtcdMemberSuite) TestDeregistration() { // Check each node is present in the etcd cluster and reports joined state expectedObjects := []string{"controller0", "controller1", "controller2"} for i, obj := range expectedObjects { + s.T().Logf("verifying initial status of %s", obj) em := &etcdv1beta1.EtcdMember{} - err = kc.RESTClient().Get().AbsPath(fmt.Sprintf(basePath, obj)).Do(s.Context()).Into(em) + ctx, cancel := context.WithTimeout(s.Context(), 20*time.Second) + defer cancel() + err = common.Poll(ctx, func(ctx context.Context) (done bool, err error) { + // As status is updated separately, we need to wait till we actually see conditions + err = kc.RESTClient().Get().AbsPath(fmt.Sprintf(basePath, obj)).Do(s.Context()).Into(em) + if apierrors.IsNotFound(err) { + return false, nil + } else if err != nil { + return false, err + } + c := em.Status.GetCondition(etcdv1beta1.ConditionTypeJoined) + return c != nil, nil + }) + // We've got the condition, verify status details s.Require().NoError(err) s.Require().Equal(em.PeerAddress, s.GetControllerIPAddress(i)) c := em.Status.GetCondition(etcdv1beta1.ConditionTypeJoined)