From 88df9583cad78310867dedb28f784c5d4b5f45ba Mon Sep 17 00:00:00 2001 From: Vitor Savian Date: Thu, 21 Mar 2024 14:20:33 -0300 Subject: [PATCH] Add a new error when kine is with disable apiserver or disable etcd Signed-off-by: Vitor Savian --- pkg/cli/server/server.go | 12 +++- tests/integration/startup/startup_int_test.go | 62 ++++++++++++++++--- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index d371528951..f9b2a98094 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -49,9 +49,7 @@ func RunWithControllers(app *cli.Context, leaderControllers server.CustomControl } func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomControllers, controllers server.CustomControllers) error { - var ( - err error - ) + var err error // Validate build env cmds.MustValidateGolang() @@ -217,6 +215,14 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont return errors.New("invalid flag use; --server is required with --disable-etcd") } + if serverConfig.ControlConfig.Datastore.Endpoint != "" && serverConfig.ControlConfig.DisableAPIServer { + return errors.New("invalid flag use; cannot use --disable-apiserver with --datastore-endpoint") + } + + if serverConfig.ControlConfig.Datastore.Endpoint != "" && serverConfig.ControlConfig.DisableETCD { + return errors.New("invalid flag use; cannot use --disable-etcd with --datastore-endpoint") + } + if serverConfig.ControlConfig.DisableAPIServer { // Servers without a local apiserver need to connect to the apiserver via the proxy load-balancer. serverConfig.ControlConfig.APIServerPort = cmds.AgentConfig.LBServerPort diff --git a/tests/integration/startup/startup_int_test.go b/tests/integration/startup/startup_int_test.go index 13f9c36a34..b09416a825 100644 --- a/tests/integration/startup/startup_int_test.go +++ b/tests/integration/startup/startup_int_test.go @@ -1,21 +1,23 @@ package integration import ( + "errors" "os" "path/filepath" "testing" - v1 "k8s.io/api/core/v1" - testutil "github.com/k3s-io/k3s/tests/integration" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gstruct" + v1 "k8s.io/api/core/v1" ) -var startupServer *testutil.K3sServer -var startupServerArgs = []string{} -var testLock int +var ( + startupServer *testutil.K3sServer + startupServerArgs = []string{} + testLock int +) var _ = BeforeSuite(func() { if testutil.IsExistingServer() { @@ -27,7 +29,6 @@ var _ = BeforeSuite(func() { }) var _ = Describe("startup tests", Ordered, func() { - When("a default server is created", func() { It("is created with no arguments", func() { var err error @@ -263,7 +264,54 @@ var _ = Describe("startup tests", Ordered, func() { Expect(testutil.K3sCleanup(-1, "")).To(Succeed()) }) }) - + When("a server with datastore-endpoint and disable apiserver is created", func() { + It("is created with datastore-endpoint and disable apiserver flags", func() { + var err error + startupServerArgs = []string{"--datastore-endpoint", "test", "--disable-apiserver"} + startupServer, err = testutil.K3sStartServer(startupServerArgs...) + Expect(err).NotTo(HaveOccurred()) + }) + It("search for the error log", func() { + Eventually(func() error { + match, err := testutil.SearchK3sLog(startupServer, "invalid flag use; cannot use --disable-apiserver with --datastore-endpoint") + if err != nil { + return err + } + if match { + return nil + } + return errors.New("nor found error when --datastore-endpoint and --disable-apiserver are used together") + }, "30s", "2s").Should(Succeed()) + }) + It("cleans up", func() { + Expect(testutil.K3sKillServer(startupServer)).To(Succeed()) + Expect(testutil.K3sCleanup(-1, "")).To(Succeed()) + }) + }) + When("a server with datastore-endpoint and disable etcd is created", func() { + It("is created with datastore-endpoint and disable etcd flags", func() { + var err error + startupServerArgs = []string{"--datastore-endpoint", "test", "--disable-etcd", "-s", "https://192.168.1.12:6443"} + startupServer, err = testutil.K3sStartServer(startupServerArgs...) + Expect(err).NotTo(HaveOccurred()) + }) + It("search for the error log", func() { + Eventually(func() error { + match, err := testutil.SearchK3sLog(startupServer, "invalid flag use; cannot use --disable-etcd with --datastore-endpoint") + if err != nil { + return err + } + if match { + return nil + } + return errors.New("not found error when --datastore-endpoint and --disable-etcd are used together") + }, "30s", "2s").Should(Succeed()) + }) + It("cleans up", func() { + Expect(testutil.K3sKillServer(startupServer)).To(Succeed()) + Expect(testutil.K3sCleanup(-1, "")).To(Succeed()) + }) + }) }) var failed bool