mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Fix broken --cluster-reset
This commit is contained in:
parent
b2439788d7
commit
668fcf7e83
@ -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,
|
||||
})
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user