Commit 739b16b1 authored by galal-hussein's avatar galal-hussein

Upgrade kine

Fix storing bootstrap data with empty token string (#3422) * Fix storing bootstrap data with empty token string Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * delete node password secret after restoration fixes to bootstrap key vendor update Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * fix comment Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * fix typo Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * more fixes Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * fixes Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * fixes Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * typos Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * Removing dynamic listener file after restoration Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> * go mod tidy Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> update kine add bootstrap save Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com> fix save bootstrap Signed-off-by: 's avatargalal-hussein <hussein.galal.ahmed.11@gmail.com>
parent 89c44337
...@@ -81,6 +81,7 @@ require ( ...@@ -81,6 +81,7 @@ require (
github.com/gorilla/mux v1.7.4 github.com/gorilla/mux v1.7.4
github.com/gorilla/websocket v1.4.1 github.com/gorilla/websocket v1.4.1
github.com/k3s-io/helm-controller v0.8.3 github.com/k3s-io/helm-controller v0.8.3
github.com/k3s-io/kine v0.6.2
github.com/kubernetes-sigs/cri-tools v0.0.0-00010101000000-000000000000 github.com/kubernetes-sigs/cri-tools v0.0.0-00010101000000-000000000000
github.com/lib/pq v1.8.0 github.com/lib/pq v1.8.0
github.com/mattn/go-sqlite3 v1.14.4 github.com/mattn/go-sqlite3 v1.14.4
...@@ -92,7 +93,6 @@ require ( ...@@ -92,7 +93,6 @@ require (
github.com/pierrec/lz4 v2.5.2+incompatible github.com/pierrec/lz4 v2.5.2+incompatible
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/rancher/dynamiclistener v0.2.2 github.com/rancher/dynamiclistener v0.2.2
github.com/rancher/kine v0.5.1
github.com/rancher/remotedialer v0.2.0 github.com/rancher/remotedialer v0.2.0
github.com/rancher/wrangler v0.6.2 github.com/rancher/wrangler v0.6.2
github.com/rancher/wrangler-api v0.6.0 github.com/rancher/wrangler-api v0.6.0
......
...@@ -475,6 +475,8 @@ github.com/k3s-io/etcd v0.5.0-alpha.5.0.20201208200253-50621aee4aea h1:7cwby0GoN ...@@ -475,6 +475,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/etcd v0.5.0-alpha.5.0.20201208200253-50621aee4aea/go.mod h1:yVHk9ub3CSBatqGNg7GRmsnfLWtoW60w4eDYfh7vHDg=
github.com/k3s-io/helm-controller v0.8.3 h1:GWxavyMz7Bw2ClxH5okkeOL8o5U6IBK7uauc44SDCjU= github.com/k3s-io/helm-controller v0.8.3 h1:GWxavyMz7Bw2ClxH5okkeOL8o5U6IBK7uauc44SDCjU=
github.com/k3s-io/helm-controller v0.8.3/go.mod h1:nZP8FH3KZrNNUf5r+SwwiMR63HS6lxdHdpHijgPfF74= github.com/k3s-io/helm-controller v0.8.3/go.mod h1:nZP8FH3KZrNNUf5r+SwwiMR63HS6lxdHdpHijgPfF74=
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.19.13-k3s1 h1:Kl++d1Z1z21THbkAgMrnnPH5xqKNEg5jyNxn+YR1QHw= github.com/k3s-io/kubernetes v1.19.13-k3s1 h1:Kl++d1Z1z21THbkAgMrnnPH5xqKNEg5jyNxn+YR1QHw=
github.com/k3s-io/kubernetes v1.19.13-k3s1/go.mod h1:HD/Q62CbvekHttYG9YffbrTHx54dkZCnF7t3oJCzxOA= github.com/k3s-io/kubernetes v1.19.13-k3s1/go.mod h1:HD/Q62CbvekHttYG9YffbrTHx54dkZCnF7t3oJCzxOA=
github.com/k3s-io/kubernetes/staging/src/k8s.io/api v1.19.13-k3s1 h1:CMaqfM1UbCqqSQbvPFH7Rtn6ytrfNda/0jBPmjA/IzQ= github.com/k3s-io/kubernetes/staging/src/k8s.io/api v1.19.13-k3s1 h1:CMaqfM1UbCqqSQbvPFH7Rtn6ytrfNda/0jBPmjA/IzQ=
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rancher/k3s/pkg/agent" "github.com/rancher/k3s/pkg/agent"
"github.com/rancher/k3s/pkg/cli/cmds" "github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/datadir" "github.com/rancher/k3s/pkg/datadir"
"github.com/rancher/k3s/pkg/etcd" "github.com/rancher/k3s/pkg/etcd"
"github.com/rancher/k3s/pkg/netutil" "github.com/rancher/k3s/pkg/netutil"
...@@ -315,7 +316,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -315,7 +316,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
} }
url := fmt.Sprintf("https://%s:%d", ip, serverConfig.ControlConfig.SupervisorPort) url := fmt.Sprintf("https://%s:%d", ip, serverConfig.ControlConfig.SupervisorPort)
token, err := server.FormatToken(serverConfig.ControlConfig.Runtime.AgentToken, serverConfig.ControlConfig.Runtime.ServerCA) token, err := clientaccess.FormatToken(serverConfig.ControlConfig.Runtime.AgentToken, serverConfig.ControlConfig.Runtime.ServerCA)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -275,3 +275,20 @@ func get(u string, client *http.Client, username, password string) ([]byte, erro ...@@ -275,3 +275,20 @@ func get(u string, client *http.Client, username, password string) ([]byte, erro
return ioutil.ReadAll(resp.Body) return ioutil.ReadAll(resp.Body)
} }
func FormatToken(token string, certFile string) (string, error) {
if len(token) == 0 {
return token, nil
}
certHash := ""
if len(certFile) > 0 {
bytes, err := ioutil.ReadFile(certFile)
if err != nil {
return "", nil
}
digest := sha256.Sum256(bytes)
certHash = tokenPrefix + hex.EncodeToString(digest[:]) + "::"
}
return certHash + token, nil
}
...@@ -132,7 +132,7 @@ func (c *Cluster) httpBootstrap() error { ...@@ -132,7 +132,7 @@ func (c *Cluster) httpBootstrap() error {
func (c *Cluster) bootstrap(ctx context.Context) error { func (c *Cluster) bootstrap(ctx context.Context) error {
c.joining = true c.joining = true
// bootstrap managed database via HTTP // bootstrap managed database via HTTPS
if c.runtime.HTTPBootstrap { if c.runtime.HTTPBootstrap {
return c.httpBootstrap() return c.httpBootstrap()
} }
......
...@@ -3,15 +3,16 @@ package cluster ...@@ -3,15 +3,16 @@ package cluster
import ( import (
"context" "context"
"net/url" "net/url"
"runtime"
"strings" "strings"
"github.com/k3s-io/kine/pkg/client"
"github.com/k3s-io/kine/pkg/endpoint"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rancher/k3s/pkg/clientaccess" "github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/cluster/managed" "github.com/rancher/k3s/pkg/cluster/managed"
"github.com/rancher/k3s/pkg/daemons/config" "github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/etcd" "github.com/rancher/k3s/pkg/etcd"
"github.com/rancher/kine/pkg/client"
"github.com/rancher/kine/pkg/endpoint"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -77,7 +78,6 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { ...@@ -77,7 +78,6 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// if necessary, store bootstrap data to datastore // if necessary, store bootstrap data to datastore
if c.saveBootstrap { if c.saveBootstrap {
if err := c.save(ctx); err != nil { if err := c.save(ctx); err != nil {
...@@ -92,7 +92,31 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { ...@@ -92,7 +92,31 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
} }
} }
return ready, c.startStorage(ctx) if err := c.startStorage(ctx); err != nil {
return nil, err
}
// at this point, if etcd is in use, it's bootstrapping is complete
// so save the bootstrap data. We will need for etcd to be up. If
// the save call returns an error, we panic since subsequent etcd
// snapshots will be empty.
if c.managedDB != nil {
go func() {
for {
select {
case <-ready:
if err := c.save(ctx); err != nil {
panic(err)
}
return
default:
runtime.Gosched()
}
}
}()
}
return ready, nil
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"github.com/rancher/dynamiclistener" "github.com/rancher/dynamiclistener"
...@@ -14,6 +15,7 @@ import ( ...@@ -14,6 +15,7 @@ import (
"github.com/rancher/dynamiclistener/storage/kubernetes" "github.com/rancher/dynamiclistener/storage/kubernetes"
"github.com/rancher/dynamiclistener/storage/memory" "github.com/rancher/dynamiclistener/storage/memory"
"github.com/rancher/k3s/pkg/daemons/config" "github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/etcd"
"github.com/rancher/k3s/pkg/version" "github.com/rancher/k3s/pkg/version"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core" "github.com/rancher/wrangler-api/pkg/generated/controllers/core"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
...@@ -24,16 +26,21 @@ import ( ...@@ -24,16 +26,21 @@ import (
// dynamiclistener will use the cluster's Server CA to sign the dynamically generate certificate, // dynamiclistener will use the cluster's Server CA to sign the dynamically generate certificate,
// and will sync the certs into the Kubernetes datastore, with a local disk cache. // and will sync the certs into the Kubernetes datastore, with a local disk cache.
func (c *Cluster) newListener(ctx context.Context) (net.Listener, http.Handler, error) { func (c *Cluster) newListener(ctx context.Context) (net.Listener, http.Handler, error) {
if c.managedDB != nil {
if _, err := os.Stat(etcd.ResetFile(c.config)); err == nil {
// delete the dynamic listener file if it exists after restoration to fix restoration
// on fresh nodes
os.Remove(filepath.Join(c.config.DataDir, "tls/dynamic-cert.json"))
}
}
tcp, err := dynamiclistener.NewTCPListener(c.config.BindAddress, c.config.SupervisorPort) tcp, err := dynamiclistener.NewTCPListener(c.config.BindAddress, c.config.SupervisorPort)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
cert, key, err := factory.LoadCerts(c.runtime.ServerCA, c.runtime.ServerCAKey) cert, key, err := factory.LoadCerts(c.runtime.ServerCA, c.runtime.ServerCAKey)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
storage := tlsStorage(ctx, c.config.DataDir, c.runtime) storage := tlsStorage(ctx, c.config.DataDir, c.runtime)
return dynamiclistener.NewListener(tcp, storage, cert, key, dynamiclistener.Config{ return dynamiclistener.NewListener(tcp, storage, cert, key, dynamiclistener.Config{
ExpirationDaysCheck: config.CertificateRenewDays, ExpirationDaysCheck: config.CertificateRenewDays,
......
...@@ -11,11 +11,11 @@ import ( ...@@ -11,11 +11,11 @@ import (
"strings" "strings"
"time" "time"
"github.com/rancher/k3s/pkg/cluster/managed"
"github.com/rancher/k3s/pkg/etcd" "github.com/rancher/k3s/pkg/etcd"
"github.com/rancher/k3s/pkg/cluster/managed" "github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/k3s/pkg/version" "github.com/rancher/k3s/pkg/version"
"github.com/rancher/kine/pkg/endpoint"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
......
...@@ -3,9 +3,14 @@ package cluster ...@@ -3,9 +3,14 @@ package cluster
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"io/ioutil"
"os"
"path/filepath"
"github.com/k3s-io/kine/pkg/client"
"github.com/rancher/k3s/pkg/bootstrap" "github.com/rancher/k3s/pkg/bootstrap"
"github.com/rancher/kine/pkg/client" "github.com/rancher/k3s/pkg/clientaccess"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -18,8 +23,20 @@ func (c *Cluster) save(ctx context.Context) error { ...@@ -18,8 +23,20 @@ func (c *Cluster) save(ctx context.Context) error {
if err := bootstrap.Write(buf, &c.runtime.ControlRuntimeBootstrap); err != nil { if err := bootstrap.Write(buf, &c.runtime.ControlRuntimeBootstrap); err != nil {
return err return err
} }
token := c.config.Token
if token == "" {
tokenFromFile, err := readTokenFromFile(c.runtime.ServerToken, c.runtime.ServerCA, c.config.DataDir)
if err != nil {
return err
}
token = tokenFromFile
}
normalizedToken, err := normalizeToken(token)
if err != nil {
return err
}
data, err := encrypt(c.config.Token, buf.Bytes()) data, err := encrypt(normalizedToken, buf.Bytes())
if err != nil { if err != nil {
return err return err
} }
...@@ -28,9 +45,14 @@ func (c *Cluster) save(ctx context.Context) error { ...@@ -28,9 +45,14 @@ func (c *Cluster) save(ctx context.Context) error {
return err return err
} }
if err := storageClient.Create(ctx, storageKey(c.config.Token), data); err != nil { _, _, err = c.getBootstrapKeyFromStorage(ctx, storageClient, normalizedToken)
if err != nil {
return err
}
if err := storageClient.Create(ctx, storageKey(normalizedToken), data); err != nil {
if err.Error() == "key exists" { if err.Error() == "key exists" {
logrus.Warnln("Bootstrap key exists. Please follow documentation updating a node after restore.") logrus.Warnln("bootstrap key exists; please follow documentation on updating a node after snapshot restore")
return nil return nil
} }
return err return err
...@@ -41,6 +63,7 @@ func (c *Cluster) save(ctx context.Context) error { ...@@ -41,6 +63,7 @@ func (c *Cluster) save(ctx context.Context) error {
// storageBootstrap loads data from the datastore into the ControlRuntimeBootstrap struct. // storageBootstrap loads data from the datastore into the ControlRuntimeBootstrap struct.
// The storage key and encryption passphrase are both derived from the join token. // The storage key and encryption passphrase are both derived from the join token.
// token is either passed
func (c *Cluster) storageBootstrap(ctx context.Context) error { func (c *Cluster) storageBootstrap(ctx context.Context) error {
if err := c.startStorage(ctx); err != nil { if err := c.startStorage(ctx); err != nil {
return err return err
...@@ -51,18 +74,104 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error { ...@@ -51,18 +74,104 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error {
return err return err
} }
value, err := storageClient.Get(ctx, storageKey(c.config.Token)) token := c.config.Token
if err == client.ErrNotFound { if token == "" {
tokenFromFile, err := readTokenFromFile(c.runtime.ServerToken, c.runtime.ServerCA, c.config.DataDir)
if err != nil {
return err
}
if tokenFromFile == "" {
// at this point this is a fresh start in a non managed environment
c.saveBootstrap = true c.saveBootstrap = true
return nil return nil
} else if err != nil { }
token = tokenFromFile
}
normalizedToken, err := normalizeToken(token)
if err != nil {
return err return err
} }
data, err := decrypt(c.config.Token, value.Data) value, emptyKey, err := c.getBootstrapKeyFromStorage(ctx, storageClient, normalizedToken)
if err != nil {
return err
}
if value == nil {
return nil
}
if emptyKey {
normalizedToken = ""
}
data, err := decrypt(normalizedToken, value.Data)
if err != nil { if err != nil {
return err return err
} }
return bootstrap.Read(bytes.NewBuffer(data), &c.runtime.ControlRuntimeBootstrap) return bootstrap.Read(bytes.NewBuffer(data), &c.runtime.ControlRuntimeBootstrap)
} }
// getBootstrapKeyFromStorage will list all keys that has prefix /bootstrap and will check for key that is
// hashed with empty string and will check for any key that is hashed by different token than the one
// passed to it, it will return error if it finds a key that is hashed with different token and will return
// value if it finds the key hashed by passed token or empty string
func (c *Cluster) getBootstrapKeyFromStorage(ctx context.Context, storageClient client.Client, token string) (*client.Value, bool, error) {
emptyStringKey := storageKey("")
tokenKey := storageKey(token)
bootstrapList, err := storageClient.List(ctx, "/bootstrap", 0)
if err != nil {
return nil, false, err
}
if len(bootstrapList) == 0 {
c.saveBootstrap = true
return nil, false, nil
}
if len(bootstrapList) > 1 {
return nil, false, errors.New("found more than one 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")
c.saveBootstrap = true
if err := storageClient.Delete(ctx, emptyStringKey, bootstrapKV.Modified); err != nil {
return nil, false, err
}
return &bootstrapKV, true, nil
case tokenKey:
return &bootstrapKV, false, nil
}
return nil, false, errors.New("bootstrap data already found and encrypted with different token")
}
// readTokenFromFile will attempt to get the token from <data-dir>/token if it the file not found
// in case of fresh installation it will try to use the runtime serverToken saved in memory
// after stripping it from any additional information like the username or cahash, if the file
// found then it will still strip the token from any additional info
func readTokenFromFile(serverToken, certs, dataDir string) (string, error) {
tokenFile := filepath.Join(dataDir, "token")
b, err := ioutil.ReadFile(tokenFile)
if err != nil {
if os.IsNotExist(err) {
token, err := clientaccess.FormatToken(serverToken, certs)
if err != nil {
return token, err
}
return token, nil
}
return "", err
}
// strip the token from any new line if its read from file
return string(bytes.TrimRight(b, "\n")), nil
}
// normalizeToken will normalize the token read from file or passed as a cli flag
func normalizeToken(token string) (string, error) {
_, password, ok := clientaccess.ParseUsernamePassword(token)
if !ok {
return password, errors.New("failed to normalize token")
}
return password, nil
}
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/rancher/kine/pkg/endpoint" "github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core" "github.com/rancher/wrangler-api/pkg/generated/controllers/core"
"k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/authenticator"
) )
......
...@@ -2,8 +2,6 @@ package server ...@@ -2,8 +2,6 @@ package server
import ( import (
"context" "context"
"crypto/sha256"
"encoding/hex"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
net2 "net" net2 "net"
...@@ -379,30 +377,12 @@ func printToken(httpsPort int, advertiseIP, prefix, cmd string) { ...@@ -379,30 +377,12 @@ func printToken(httpsPort int, advertiseIP, prefix, cmd string) {
logrus.Infof("%s %s %s -s https://%s:%d -t ${NODE_TOKEN}", prefix, version.Program, cmd, ip, httpsPort) logrus.Infof("%s %s %s -s https://%s:%d -t ${NODE_TOKEN}", prefix, version.Program, cmd, ip, httpsPort)
} }
func FormatToken(token string, certFile string) (string, error) {
if len(token) == 0 {
return token, nil
}
prefix := "K10"
if len(certFile) > 0 {
bytes, err := ioutil.ReadFile(certFile)
if err != nil {
return "", nil
}
digest := sha256.Sum256(bytes)
prefix = "K10" + hex.EncodeToString(digest[:]) + "::"
}
return prefix + token, nil
}
func writeToken(token, file, certs string) error { func writeToken(token, file, certs string) error {
if len(token) == 0 { if len(token) == 0 {
return nil return nil
} }
token, err := FormatToken(token, certs) token, err := clientaccess.FormatToken(token, certs)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/rancher/kine/pkg/endpoint" "github.com/k3s-io/kine/pkg/endpoint"
"go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/clientv3"
) )
...@@ -26,6 +26,7 @@ type Client interface { ...@@ -26,6 +26,7 @@ type Client interface {
Put(ctx context.Context, key string, value []byte) error Put(ctx context.Context, key string, value []byte) error
Create(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 Update(ctx context.Context, key string, revision int64, value []byte) error
Delete(ctx context.Context, key string, revision int64) error
Close() error Close() error
} }
...@@ -128,6 +129,21 @@ func (c *client) Update(ctx context.Context, key string, revision int64, value [ ...@@ -128,6 +129,21 @@ func (c *client) Update(ctx context.Context, key string, revision int64, value [
return nil return nil
} }
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 { func (c *client) Close() error {
return c.c.Close() return c.c.Close()
} }
...@@ -14,10 +14,10 @@ import ( ...@@ -14,10 +14,10 @@ import (
"github.com/canonical/go-dqlite" "github.com/canonical/go-dqlite"
"github.com/canonical/go-dqlite/client" "github.com/canonical/go-dqlite/client"
"github.com/canonical/go-dqlite/driver" "github.com/canonical/go-dqlite/driver"
"github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/k3s-io/kine/pkg/drivers/sqlite"
"github.com/k3s-io/kine/pkg/server"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rancher/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/drivers/sqlite"
"github.com/rancher/kine/pkg/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
......
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
"context" "context"
"errors" "errors"
"github.com/rancher/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/server" "github.com/k3s-io/kine/pkg/server"
) )
func New(ctx context.Context, datasourceName string, connPoolConfig generic.ConnectionPoolConfig) (server.Backend, error) { func New(ctx context.Context, datasourceName string, connPoolConfig generic.ConnectionPoolConfig) (server.Backend, error) {
......
...@@ -6,11 +6,11 @@ import ( ...@@ -6,11 +6,11 @@ import (
"database/sql" "database/sql"
"github.com/go-sql-driver/mysql" "github.com/go-sql-driver/mysql"
"github.com/rancher/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/logstructured" "github.com/k3s-io/kine/pkg/logstructured"
"github.com/rancher/kine/pkg/logstructured/sqllog" "github.com/k3s-io/kine/pkg/logstructured/sqllog"
"github.com/rancher/kine/pkg/server" "github.com/k3s-io/kine/pkg/server"
"github.com/rancher/kine/pkg/tls" "github.com/k3s-io/kine/pkg/tls"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
......
...@@ -8,12 +8,12 @@ import ( ...@@ -8,12 +8,12 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/k3s-io/kine/pkg/logstructured"
"github.com/k3s-io/kine/pkg/logstructured/sqllog"
"github.com/k3s-io/kine/pkg/server"
"github.com/k3s-io/kine/pkg/tls"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/rancher/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/logstructured"
"github.com/rancher/kine/pkg/logstructured/sqllog"
"github.com/rancher/kine/pkg/server"
"github.com/rancher/kine/pkg/tls"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
......
...@@ -8,12 +8,12 @@ import ( ...@@ -8,12 +8,12 @@ import (
"os" "os"
"time" "time"
"github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/k3s-io/kine/pkg/logstructured"
"github.com/k3s-io/kine/pkg/logstructured/sqllog"
"github.com/k3s-io/kine/pkg/server"
"github.com/mattn/go-sqlite3" "github.com/mattn/go-sqlite3"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rancher/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/logstructured"
"github.com/rancher/kine/pkg/logstructured/sqllog"
"github.com/rancher/kine/pkg/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
// sqlite db driver // sqlite db driver
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"database/sql" "database/sql"
"errors" "errors"
"github.com/rancher/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/server" "github.com/k3s-io/kine/pkg/server"
) )
var errNoCgo = errors.New("this binary is built without CGO, sqlite is disabled") var errNoCgo = errors.New("this binary is built without CGO, sqlite is disabled")
......
...@@ -7,14 +7,14 @@ import ( ...@@ -7,14 +7,14 @@ import (
"os" "os"
"strings" "strings"
"github.com/k3s-io/kine/pkg/drivers/dqlite"
"github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/k3s-io/kine/pkg/drivers/mysql"
"github.com/k3s-io/kine/pkg/drivers/pgsql"
"github.com/k3s-io/kine/pkg/drivers/sqlite"
"github.com/k3s-io/kine/pkg/server"
"github.com/k3s-io/kine/pkg/tls"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rancher/kine/pkg/drivers/dqlite"
"github.com/rancher/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/drivers/mysql"
"github.com/rancher/kine/pkg/drivers/pgsql"
"github.com/rancher/kine/pkg/drivers/sqlite"
"github.com/rancher/kine/pkg/server"
"github.com/rancher/kine/pkg/tls"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/rancher/kine/pkg/server" "github.com/k3s-io/kine/pkg/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
......
...@@ -6,10 +6,10 @@ import ( ...@@ -6,10 +6,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/k3s-io/kine/pkg/broadcaster"
"github.com/k3s-io/kine/pkg/drivers/generic"
"github.com/k3s-io/kine/pkg/server"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rancher/kine/pkg/broadcaster"
"github.com/rancher/kine/pkg/drivers/generic"
"github.com/rancher/kine/pkg/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -53,9 +53,9 @@ type Dialect interface { ...@@ -53,9 +53,9 @@ type Dialect interface {
BeginTx(ctx context.Context, opts *sql.TxOptions) (*generic.Tx, error) 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 s.ctx = ctx
return return s.compactStart(s.ctx)
} }
func (s *SQLLog) compactStart(ctx context.Context) error { func (s *SQLLog) compactStart(ctx context.Context) error {
...@@ -365,10 +365,6 @@ func filter(events interface{}, checkPrefix bool, prefix string) ([]*server.Even ...@@ -365,10 +365,6 @@ func filter(events interface{}, checkPrefix bool, prefix string) ([]*server.Even
} }
func (s *SQLLog) startWatch() (chan interface{}, error) { 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) pollStart, err := s.d.GetCompactRevision(s.ctx)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -688,6 +688,20 @@ github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm. ...@@ -688,6 +688,20 @@ 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/informers/externalversions/internalinterfaces
github.com/k3s-io/helm-controller/pkg/generated/listers/helm.cattle.io/v1 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/helm-controller/pkg/helm
# github.com/k3s-io/kine v0.6.2
## explicit
github.com/k3s-io/kine/pkg/broadcaster
github.com/k3s-io/kine/pkg/client
github.com/k3s-io/kine/pkg/drivers/dqlite
github.com/k3s-io/kine/pkg/drivers/generic
github.com/k3s-io/kine/pkg/drivers/mysql
github.com/k3s-io/kine/pkg/drivers/pgsql
github.com/k3s-io/kine/pkg/drivers/sqlite
github.com/k3s-io/kine/pkg/endpoint
github.com/k3s-io/kine/pkg/logstructured
github.com/k3s-io/kine/pkg/logstructured/sqllog
github.com/k3s-io/kine/pkg/server
github.com/k3s-io/kine/pkg/tls
# github.com/karrick/godirwalk v1.7.5 # github.com/karrick/godirwalk v1.7.5
github.com/karrick/godirwalk github.com/karrick/godirwalk
# github.com/klauspost/cpuid v1.3.1 # github.com/klauspost/cpuid v1.3.1
...@@ -852,20 +866,6 @@ github.com/rancher/dynamiclistener/storage/memory ...@@ -852,20 +866,6 @@ github.com/rancher/dynamiclistener/storage/memory
# github.com/rancher/go-powershell v0.0.0-20200701182037-6845e6fcfa79 # github.com/rancher/go-powershell v0.0.0-20200701182037-6845e6fcfa79
github.com/rancher/go-powershell/backend github.com/rancher/go-powershell/backend
github.com/rancher/go-powershell/utils github.com/rancher/go-powershell/utils
# github.com/rancher/kine v0.5.1
## explicit
github.com/rancher/kine/pkg/broadcaster
github.com/rancher/kine/pkg/client
github.com/rancher/kine/pkg/drivers/dqlite
github.com/rancher/kine/pkg/drivers/generic
github.com/rancher/kine/pkg/drivers/mysql
github.com/rancher/kine/pkg/drivers/pgsql
github.com/rancher/kine/pkg/drivers/sqlite
github.com/rancher/kine/pkg/endpoint
github.com/rancher/kine/pkg/logstructured
github.com/rancher/kine/pkg/logstructured/sqllog
github.com/rancher/kine/pkg/server
github.com/rancher/kine/pkg/tls
# github.com/rancher/remotedialer v0.2.0 # github.com/rancher/remotedialer v0.2.0
## explicit ## explicit
github.com/rancher/remotedialer github.com/rancher/remotedialer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment