Skip to content

Commit

Permalink
Fix timing issue in EtcdMember inttest
Browse files Browse the repository at this point in the history
Signed-off-by: Jussi Nummelin <[email protected]>
  • Loading branch information
jnummelin committed Apr 26, 2024
1 parent 6b68e18 commit c738dc9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion inttest/etcdmember/etcdmember_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c738dc9

Please sign in to comment.