From 668fcf7e8338e153f5a8b0b183fdbf33f30f4cc2 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Mon, 11 Nov 2019 22:19:00 +0000 Subject: [PATCH] Fix broken --cluster-reset --- pkg/dqlite/reset.go | 33 ++++----------------------------- pkg/dqlite/server.go | 11 +++++++++-- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/pkg/dqlite/reset.go b/pkg/dqlite/reset.go index 95b263e55d..d9a379897f 100644 --- a/pkg/dqlite/reset.go +++ b/pkg/dqlite/reset.go @@ -2,39 +2,14 @@ package dqlite import ( "context" - "fmt" "github.com/canonical/go-dqlite/client" "github.com/sirupsen/logrus" ) func (d *DQLite) Reset(ctx context.Context) error { - dqClient, err := client.New(ctx, d.getBindAddress(), client.WithLogFunc(log())) - if err != nil { - return err - } - - current, err := dqClient.Cluster(ctx) - if err != nil { - return err - } - - // There's a chance our ID and the ID the server has doesn't match so find the ID - var surviving []client.NodeInfo - for _, testNode := range current { - if testNode.Address == d.NodeInfo.Address && testNode.ID == d.NodeInfo.ID { - surviving = append(surviving, testNode) - continue - } - if err := dqClient.Remove(ctx, testNode.ID); err != nil { - return err - } - } - - if len(surviving) != 1 { - return fmt.Errorf("failed to find %s in the current node, can not reset", d.NodeInfo.Address) - } - - logrus.Infof("Resetting cluster to single master, please rejoin members") - return d.node.Recover(surviving) + logrus.Infof("Resetting cluster to single master") + return d.node.Recover([]client.NodeInfo{ + d.NodeInfo, + }) } diff --git a/pkg/dqlite/server.go b/pkg/dqlite/server.go index b5e6b04a4a..9fab9c8e74 100644 --- a/pkg/dqlite/server.go +++ b/pkg/dqlite/server.go @@ -60,7 +60,7 @@ func New(dataDir, advertiseIP string, advertisePort int, getter NodeControllerGe } } -func (d *DQLite) Start(ctx context.Context, initCluster bool, certs *Certs, next http.Handler) (http.Handler, error) { +func (d *DQLite) Start(ctx context.Context, initCluster, resetCluster bool, certs *Certs, next http.Handler) (http.Handler, error) { bindAddress := d.getBindAddress() clientTLSConfig, err := getClientTLSConfig(certs.ClientCert, certs.ServerTrust) @@ -89,6 +89,7 @@ func (d *DQLite) Start(ctx context.Context, initCluster bool, certs *Certs, next } d.NodeInfo = nodeInfo + d.node = node go func() { <-ctx.Done() @@ -101,7 +102,13 @@ func (d *DQLite) Start(ctx context.Context, initCluster bool, certs *Certs, next go d.startController(ctx) - return router(ctx, next, nodeInfo, certs.ClientTrust, "kube-apiserver", bindAddress), node.Start() + if !resetCluster { + if err := node.Start(); err != nil { + return nil, err + } + } + + return router(ctx, next, nodeInfo, certs.ClientTrust, "kube-apiserver", bindAddress), nil } func (d *DQLite) startController(ctx context.Context) {