Skip to content

fix: issue with etcd watch cancel #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ replace (
require (
github.com/adrg/xdg v0.4.0
github.com/blang/semver v3.5.1+incompatible
github.com/cosi-project/runtime v0.4.1
github.com/cosi-project/runtime v0.4.2
github.com/fatih/color v1.16.0
github.com/google/uuid v1.6.0
github.com/gosuri/uiprogress v0.0.1
Expand Down
4 changes: 2 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/containerd/go-cni v1.1.9 h1:ORi7P1dYzCwVM6XPN4n3CbkuOx/NZ2DOqy+SHRdo9
github.com/containerd/go-cni v1.1.9/go.mod h1:XYrZJ1d5W6E2VOvjffL3IZq0Dz6bsVlERHbekNK90PM=
github.com/containernetworking/cni v1.1.2 h1:wtRGZVv7olUHMOqouPpn3cXJWpJgM6+EUl31EQbXALQ=
github.com/containernetworking/cni v1.1.2/go.mod h1:sDpYKmGVENF3s6uvMvGgldDWeG8dMxakj/u+i9ht9vw=
github.com/cosi-project/runtime v0.4.1 h1:9lJWw5cl3Lz1qP32bl2vxAsJs6LM8KdUGLCc9t/EGqw=
github.com/cosi-project/runtime v0.4.1/go.mod h1:eXVAHf9QzzSVblLUtHHPFOZ7JBuz+GypHbao1vw+SdQ=
github.com/cosi-project/runtime v0.4.2 h1:kJkhorzDWierDDbXn1BDHS6iQ7ai9AdvQOnK5uG/g8g=
github.com/cosi-project/runtime v0.4.2/go.mod h1:eXVAHf9QzzSVblLUtHHPFOZ7JBuz+GypHbao1vw+SdQ=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/cenkalti/backoff/v4 v4.3.0
github.com/containers/image v3.0.2+incompatible
github.com/cosi-project/runtime v0.4.1
github.com/cosi-project/state-etcd v0.2.8
github.com/cosi-project/runtime v0.4.2
github.com/cosi-project/state-etcd v0.2.9
github.com/crewjam/saml v0.4.14
github.com/dustin/go-humanize v1.0.1
github.com/emicklei/dot v1.6.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cosi-project/runtime v0.4.1 h1:9lJWw5cl3Lz1qP32bl2vxAsJs6LM8KdUGLCc9t/EGqw=
github.com/cosi-project/runtime v0.4.1/go.mod h1:eXVAHf9QzzSVblLUtHHPFOZ7JBuz+GypHbao1vw+SdQ=
github.com/cosi-project/state-etcd v0.2.8 h1:77e3VoA+hw/CSoJH4ibKWwrJwY5pSbIdOli7pbgYBNQ=
github.com/cosi-project/state-etcd v0.2.8/go.mod h1:P/QdrlDu1JTptfteGgt6ClR9BHnbpt5EXxPFMvg+RuY=
github.com/cosi-project/runtime v0.4.2 h1:kJkhorzDWierDDbXn1BDHS6iQ7ai9AdvQOnK5uG/g8g=
github.com/cosi-project/runtime v0.4.2/go.mod h1:eXVAHf9QzzSVblLUtHHPFOZ7JBuz+GypHbao1vw+SdQ=
github.com/cosi-project/state-etcd v0.2.9 h1:jPYLHvQEjAksqPxku7gcfX7o+a0cw289dAQfr58lWfE=
github.com/cosi-project/state-etcd v0.2.9/go.mod h1:9PAv45buB5kWEGB+TuAk8FZxyRYxcB3198W/JndzcbA=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
24 changes: 22 additions & 2 deletions internal/backend/runtime/omni/state_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"net"
"net/url"
"os"
"time"
Expand All @@ -22,10 +23,10 @@ import (
"github.com/cosi-project/runtime/pkg/state/impl/store/compression"
"github.com/cosi-project/runtime/pkg/state/impl/store/encryption"
"github.com/cosi-project/state-etcd/pkg/state/impl/etcd"
"github.com/siderolabs/gen/xslices"
"go.etcd.io/etcd/client/pkg/v3/transport"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/embed"
"go.etcd.io/etcd/server/v3/etcdserver/api/v3client"
"go.uber.org/zap"
"google.golang.org/grpc"

Expand Down Expand Up @@ -204,7 +205,22 @@ func getEmbeddedEtcdClient(ctx context.Context, params *config.EtcdParams, logge
return errors.New("etcd failed to start")
}

cli := v3client.New(embeddedServer.Server)
cli, err := clientv3.New(clientv3.Config{
Endpoints: xslices.Map(embeddedServer.Clients, func(l net.Listener) string { return l.Addr().String() }),
DialTimeout: 5 * time.Second,
DialOptions: []grpc.DialOption{
grpc.WithBlock(),
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(constants.GRPCMaxMessageSize)),
grpc.WithSharedWriteBuffer(true),
},
Logger: logger.WithOptions(
// never enable debug logs for etcd client, they are too chatty
zap.IncreaseLevel(zap.InfoLevel),
).With(logging.Component("etcd_client")),
})
if err != nil {
return err
}

closer := func() error {
if err = cli.Close(); err != nil && !errors.Is(err, context.Canceled) {
Expand Down Expand Up @@ -263,6 +279,10 @@ func getExternalEtcdClient(ctx context.Context, params *config.EtcdParams, logge
grpc.WithSharedWriteBuffer(true),
},
TLS: tlsConfig,
Logger: logger.WithOptions(
// never enable debug logs for etcd client, they are too chatty
zap.IncreaseLevel(zap.InfoLevel),
).With(logging.Component("etcd_client")),
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions internal/backend/runtime/omni/state_etcd_election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestEtcdElections(t *testing.T) {
require.NoError(t, omni.GetEmbeddedEtcdClient(ctx, &config.EtcdParams{
Embedded: true,
EmbeddedDBPath: t.TempDir(),
Endpoints: []string{"http://localhost:0"},
}, logger, func(ctx context.Context, client *clientv3.Client) error {
started := make(chan int)
closed := make(chan error)
Expand Down
2 changes: 2 additions & 0 deletions internal/backend/runtime/omni/state_etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func TestEtcdInitialization(t *testing.T) {
EmbeddedDBPath: etcdDir,
PrivateKeySource: step.args.privateKeySource,
PublicKeyFiles: step.args.publicKeyFiles,
Endpoints: []string{"http://localhost:0"},
},
},
}, zaptest.NewLogger(t), func(context.Context, namespaced.StateBuilder) error {
Expand Down Expand Up @@ -196,6 +197,7 @@ func TestEncryptDecrypt(t *testing.T) {
EmbeddedDBPath: etcdDir,
PrivateKeySource: step.args.privateKeySource,
PublicKeyFiles: step.args.publicKeyFiles,
Endpoints: []string{"http://localhost:0"},
},
},
}, zaptest.NewLogger(t),
Expand Down