Add a new error when kine is with disable apiserver or disable etcd

Signed-off-by: Vitor Savian <vitor.savian@suse.com>
This commit is contained in:
Vitor Savian 2024-03-21 14:20:33 -03:00
parent f099bfa508
commit 3f649e3bcb
2 changed files with 64 additions and 10 deletions

View File

@ -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()
@ -214,6 +212,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

View File

@ -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