From 6021b7d7c11746f55a400b4f88431150e04cffb4 Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Mon, 23 Dec 2024 15:16:45 +0200 Subject: [PATCH] Backport etcd join workflow fix from #5151 Signed-off-by: Alexey Makhov --- cmd/controller/controller.go | 12 ++++++++---- pkg/component/controller/etcd.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/controller/controller.go b/cmd/controller/controller.go index a1999bc3a4ce..c7edb380087b 100644 --- a/cmd/controller/controller.go +++ b/cmd/controller/controller.go @@ -655,15 +655,19 @@ func (c *command) startWorker(ctx context.Context, profile string, nodeConfig *v return wc.Start(ctx) } -// If we've got CA in place we assume the node has already joined previously +// If we've got an etcd data directory in place for embedded etcd, or a ca for +// external or other storage types, we assume the node has already joined +// previously. func (c *command) needToJoin(nodeConfig *v1beta1.ClusterConfig) bool { + if nodeConfig.Spec.Storage.Type == v1beta1.EtcdStorageType && !nodeConfig.Spec.Storage.Etcd.IsExternalClusterUsed() { + // Use the main etcd data directory as the source of truth to determine if this node has already joined + // See https://etcd.io/docs/v3.5/learning/persistent-storage-files/#bbolt-btree-membersnapdb + return !file.Exists(filepath.Join(c.K0sVars.EtcdDataDir, "member", "snap", "db")) + } if file.Exists(filepath.Join(c.K0sVars.CertRootDir, "ca.key")) && file.Exists(filepath.Join(c.K0sVars.CertRootDir, "ca.crt")) { return false } - if nodeConfig.Spec.Storage.Type == v1beta1.EtcdStorageType && !nodeConfig.Spec.Storage.Etcd.IsExternalClusterUsed() { - return !file.Exists(filepath.Join(c.K0sVars.EtcdDataDir, "member", "snap", "db")) - } return true } diff --git a/pkg/component/controller/etcd.go b/pkg/component/controller/etcd.go index b7ed956e1ffa..20b141b68def 100644 --- a/pkg/component/controller/etcd.go +++ b/pkg/component/controller/etcd.go @@ -107,7 +107,7 @@ func (e *Etcd) syncEtcdConfig(peerURL, etcdCaCert, etcdCaCertKey string) ([]stri if err != nil { return nil, err } - + logrus.Debugf("got cluster info: %v", etcdResponse.InitialCluster) // Write etcd ca cert&key if file.Exists(etcdCaCert) && file.Exists(etcdCaCertKey) {