From 246b378a2743e659a2343b60123ba51a38dcc0ac Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Tue, 29 Jun 2021 13:08:57 -0700 Subject: [PATCH] Bump kine to resolve race condition and unrevisioned delete Signed-off-by: Brad Davidson --- go.mod | 2 +- go.sum | 4 ++-- pkg/cluster/storage.go | 6 +++--- .../k3s-io/kine/pkg/client/client.go | 18 ++++++++++++++---- .../kine/pkg/logstructured/sqllog/sql.go | 8 ++------ vendor/modules.txt | 2 +- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 82e824a61f..712441249a 100644 --- a/go.mod +++ b/go.mod @@ -86,7 +86,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2 github.com/k3s-io/helm-controller v0.9.1 - github.com/k3s-io/kine v0.6.1 + github.com/k3s-io/kine v0.6.2 github.com/klauspost/compress v1.12.2 github.com/kubernetes-sigs/cri-tools v0.0.0-00010101000000-000000000000 github.com/lib/pq v1.8.0 diff --git a/go.sum b/go.sum index d9491b6830..453c15c2fd 100644 --- a/go.sum +++ b/go.sum @@ -543,8 +543,8 @@ github.com/k3s-io/etcd v0.5.0-alpha.5.0.20201208200253-50621aee4aea h1:7cwby0GoN github.com/k3s-io/etcd v0.5.0-alpha.5.0.20201208200253-50621aee4aea/go.mod h1:yVHk9ub3CSBatqGNg7GRmsnfLWtoW60w4eDYfh7vHDg= github.com/k3s-io/helm-controller v0.9.1 h1:qtHWTNHiuCPRbA2YZ7z7jTgSHo7Yc5He52oMga72yUk= github.com/k3s-io/helm-controller v0.9.1/go.mod h1:nZP8FH3KZrNNUf5r+SwwiMR63HS6lxdHdpHijgPfF74= -github.com/k3s-io/kine v0.6.1 h1:GcxxxtfmXIRiVqImZoGCHgJl6+S4Be3tY9nm2ArY7/U= -github.com/k3s-io/kine v0.6.1/go.mod h1:rzCs93+rQHZGOiewMd84PDrER92QeZ6eeHbWkfEy4+w= +github.com/k3s-io/kine v0.6.2 h1:1aJTPfB8HG4exqMKFVE5H0z4bepF05tJHtYNXotWXa4= +github.com/k3s-io/kine v0.6.2/go.mod h1:rzCs93+rQHZGOiewMd84PDrER92QeZ6eeHbWkfEy4+w= github.com/k3s-io/kubernetes v1.21.1-k3s1 h1:X8nEv12/bI3iR2+ARLuzvosPW8iMOisMlklOAeovISw= github.com/k3s-io/kubernetes v1.21.1-k3s1/go.mod h1:ef++isEL1PW0taH6z7DXrSztPglrZ7jQhyvcMEtm0gQ= github.com/k3s-io/kubernetes/staging/src/k8s.io/api v1.21.1-k3s1 h1:7iwn62FGlOqG9oRHwTY/+AbFlSZffWMqx6WUXjRpQPk= diff --git a/pkg/cluster/storage.go b/pkg/cluster/storage.go index ce04adf202..e16bf6a8b5 100644 --- a/pkg/cluster/storage.go +++ b/pkg/cluster/storage.go @@ -132,15 +132,15 @@ func (c *Cluster) getBootstrapKeyFromStorage(ctx context.Context, storageClient return nil, false, nil } if len(bootstrapList) > 1 { - return nil, false, errors.New("found more than one bootstrap keys in storage") + return nil, false, errors.New("found multiple bootstrap keys in storage") } bootstrapKV := bootstrapList[0] // checking for empty string bootstrap key switch string(bootstrapKV.Key) { case emptyStringKey: - logrus.Warn("bootstrap data already found and encrypted with empty string, deleting empty key") + logrus.Warn("bootstrap data encrypted with empty string, deleting and resaving with token") c.saveBootstrap = true - if err := storageClient.Delete(ctx, emptyStringKey); err != nil { + if err := storageClient.Delete(ctx, emptyStringKey, bootstrapKV.Modified); err != nil { return nil, false, err } return &bootstrapKV, true, nil diff --git a/vendor/github.com/k3s-io/kine/pkg/client/client.go b/vendor/github.com/k3s-io/kine/pkg/client/client.go index bca2fb8685..812aaaa842 100644 --- a/vendor/github.com/k3s-io/kine/pkg/client/client.go +++ b/vendor/github.com/k3s-io/kine/pkg/client/client.go @@ -26,7 +26,7 @@ type Client interface { Put(ctx context.Context, key string, value []byte) error Create(ctx context.Context, key string, value []byte) error Update(ctx context.Context, key string, revision int64, value []byte) error - Delete(ctx context.Context, key string) error + Delete(ctx context.Context, key string, revision int64) error Close() error } @@ -129,9 +129,19 @@ func (c *client) Update(ctx context.Context, key string, revision int64, value [ return nil } -func (c *client) Delete(ctx context.Context, key string) error { - _, err := c.c.Delete(ctx, key) - return err +func (c *client) Delete(ctx context.Context, key string, revision int64) error { + resp, err := c.c.Txn(ctx). + If(clientv3.Compare(clientv3.ModRevision(key), "=", revision)). + Then(clientv3.OpDelete(key)). + Else(clientv3.OpGet(key)). + Commit() + if err != nil { + return err + } + if !resp.Succeeded { + return fmt.Errorf("revision %d doesnt match", revision) + } + return nil } func (c *client) Close() error { diff --git a/vendor/github.com/k3s-io/kine/pkg/logstructured/sqllog/sql.go b/vendor/github.com/k3s-io/kine/pkg/logstructured/sqllog/sql.go index b7aec6d8fa..5aa115ff28 100644 --- a/vendor/github.com/k3s-io/kine/pkg/logstructured/sqllog/sql.go +++ b/vendor/github.com/k3s-io/kine/pkg/logstructured/sqllog/sql.go @@ -53,9 +53,9 @@ type Dialect interface { BeginTx(ctx context.Context, opts *sql.TxOptions) (*generic.Tx, error) } -func (s *SQLLog) Start(ctx context.Context) (err error) { +func (s *SQLLog) Start(ctx context.Context) error { s.ctx = ctx - return + return s.compactStart(s.ctx) } func (s *SQLLog) compactStart(ctx context.Context) error { @@ -365,10 +365,6 @@ func filter(events interface{}, checkPrefix bool, prefix string) ([]*server.Even } func (s *SQLLog) startWatch() (chan interface{}, error) { - if err := s.compactStart(s.ctx); err != nil { - return nil, err - } - pollStart, err := s.d.GetCompactRevision(s.ctx) if err != nil { return nil, err diff --git a/vendor/modules.txt b/vendor/modules.txt index eee7f97127..6478992526 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -709,7 +709,7 @@ github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm. github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/internalinterfaces github.com/k3s-io/helm-controller/pkg/generated/listers/helm.cattle.io/v1 github.com/k3s-io/helm-controller/pkg/helm -# github.com/k3s-io/kine v0.6.1 +# github.com/k3s-io/kine v0.6.2 ## explicit github.com/k3s-io/kine/pkg/broadcaster github.com/k3s-io/kine/pkg/client