From db057b85120d9f223fae4e586e81de048b8f304c Mon Sep 17 00:00:00 2001 From: Vitor Savian Date: Tue, 16 Jul 2024 23:29:56 -0300 Subject: [PATCH] Fix external etcd connection Signed-off-by: Vitor Savian --- go.mod | 2 +- pkg/rke2/rke2_linux.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cb2a39fc1b..9c76fa336e 100644 --- a/go.mod +++ b/go.mod @@ -80,6 +80,7 @@ require ( github.com/iamacarpet/go-win64api v0.0.0-20210311141720-fe38760bed28 github.com/k3s-io/helm-controller v0.16.1 github.com/k3s-io/k3s v1.30.3-0.20240715171250-37830fe170fa // master + github.com/k3s-io/kine v0.11.11 github.com/libp2p/go-netroute v0.2.1 github.com/natefinch/lumberjack v2.0.0+incompatible github.com/onsi/ginkgo/v2 v2.16.0 @@ -251,7 +252,6 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/josharian/native v1.1.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/k3s-io/kine v0.11.11 // indirect github.com/karrick/godirwalk v1.17.0 // indirect github.com/klauspost/compress v1.17.7 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect diff --git a/pkg/rke2/rke2_linux.go b/pkg/rke2/rke2_linux.go index e21b43f8c0..546150127d 100644 --- a/pkg/rke2/rke2_linux.go +++ b/pkg/rke2/rke2_linux.go @@ -19,6 +19,7 @@ import ( "github.com/k3s-io/k3s/pkg/cli/cmds" "github.com/k3s-io/k3s/pkg/cluster/managed" "github.com/k3s-io/k3s/pkg/etcd" + "github.com/k3s-io/kine/pkg/endpoint" "github.com/pkg/errors" "github.com/rancher/rke2/pkg/cli/defaults" "github.com/rancher/rke2/pkg/images" @@ -63,8 +64,14 @@ func initExecutor(clx *cli.Context, cfg Config, isServer bool) (*podexecutor.Sta if cmds.ServerConfig.DatastoreEndpoint != "" || (clx.Bool("disable-etcd") && !clx.IsSet("server")) { cmds.ServerConfig.DisableETCD = false cmds.ServerConfig.ClusterInit = false - cmds.ServerConfig.KineTLS = true - ExternalDatabase = true + + // When the datastore sets a etcd endpoint, rke2 does not need kine with tls and changes + // in the --etcd-servers inside podexecutor using ExternalDatabase + driver, _ := endpoint.ParseStorageEndpoint(cmds.ServerConfig.DatastoreEndpoint) + if !(driver == endpoint.ETCDBackend) { + cmds.ServerConfig.KineTLS = true + ExternalDatabase = true + } } else { managed.RegisterDriver(&etcd.ETCD{}) }