9
. "github.com/onsi/ginkgo/v2"
10
. "github.com/onsi/gomega"
12
"github.com/kumahq/kuma/pkg/config"
13
. "github.com/kumahq/kuma/pkg/config/xds/bootstrap"
16
var _ = Describe("BootstrappServerConfig", func() {
17
It("should be loadable from configuration file", func() {
19
cfg := BootstrapServerConfig{}
21
fileError := os.WriteFile("/tmp/corefile", []byte("abc"), 0o600)
22
Expect(fileError).ToNot(HaveOccurred())
25
err := config.Load(filepath.Join("testdata", "valid-config.input.yaml"), &cfg)
28
Expect(err).ToNot(HaveOccurred())
31
Expect(cfg.Params.AdminAddress).To(Equal("192.168.0.1"))
32
Expect(cfg.Params.AdminPort).To(Equal(uint32(4321)))
33
Expect(cfg.Params.AdminAccessLogPath).To(Equal("/var/log"))
34
Expect(cfg.Params.XdsHost).To(Equal("kuma-control-plane.internal"))
35
Expect(cfg.Params.XdsPort).To(Equal(uint32(10101)))
36
Expect(cfg.Params.XdsConnectTimeout.Duration).To(Equal(2 * time.Second))
37
Expect(cfg.Params.CorefileTemplatePath).To(Equal("/tmp/corefile"))
40
Context("with modified environment variables", func() {
41
var backupEnvVars []string
44
backupEnvVars = os.Environ()
49
for _, envVar := range backupEnvVars {
50
parts := strings.SplitN(envVar, "=", 2)
51
os.Setenv(parts[0], parts[1])
55
It("should be loadable from environment variables", func() {
57
env := map[string]string{
58
"KUMA_BOOTSTRAP_SERVER_API_VERSION": "v3",
59
"KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_ADDRESS": "192.168.0.1",
60
"KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_PORT": "4321",
61
"KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_ACCESS_LOG_PATH": "/var/log",
62
"KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST": "kuma-control-plane.internal",
63
"KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT": "10101",
64
"KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_CONNECT_TIMEOUT": "2s",
66
for key, value := range env {
71
cfg := BootstrapServerConfig{}
74
err := config.Load("", &cfg)
77
Expect(err).ToNot(HaveOccurred())
80
Expect(cfg.Params.AdminAddress).To(Equal("192.168.0.1"))
81
Expect(cfg.Params.AdminPort).To(Equal(uint32(4321)))
82
Expect(cfg.Params.AdminAccessLogPath).To(Equal("/var/log"))
83
Expect(cfg.Params.XdsHost).To(Equal("kuma-control-plane.internal"))
84
Expect(cfg.Params.XdsPort).To(Equal(uint32(10101)))
85
Expect(cfg.Params.XdsConnectTimeout.Duration).To(Equal(2 * time.Second))
89
It("should have consistent defaults", func() {
91
cfg := DefaultBootstrapServerConfig()
94
actual, err := config.ToYAML(cfg)
96
Expect(err).ToNot(HaveOccurred())
99
expected, err := os.ReadFile(filepath.Join("testdata", "default-config.golden.yaml"))
101
Expect(err).ToNot(HaveOccurred())
103
Expect(actual).To(MatchYAML(expected))