7
. "github.com/onsi/ginkgo/v2"
8
. "github.com/onsi/gomega"
10
"github.com/kumahq/kuma/pkg/config"
11
runtime_k8s "github.com/kumahq/kuma/pkg/config/plugins/runtime/k8s"
12
. "github.com/kumahq/kuma/pkg/test/matchers"
15
var _ = Describe("Config", func() {
16
It("should be loadable from configuration file", func() {
18
cfg := runtime_k8s.KubernetesRuntimeConfig{}
20
err := config.Load(filepath.Join("testdata", "valid-config.input.yaml"), &cfg)
23
Expect(err).ToNot(HaveOccurred())
26
Expect(cfg.ControlPlaneServiceName).To(Equal("custom-control-plane"))
28
Expect(cfg.AdmissionServer.Address).To(Equal("127.0.0.2"))
29
Expect(cfg.AdmissionServer.Port).To(Equal(uint32(8442)))
30
Expect(cfg.AdmissionServer.CertDir).To(Equal("/var/secret/kuma-cp"))
32
Expect(cfg.Injector.SidecarContainer.Image).To(Equal("kuma-sidecar:latest"))
33
Expect(cfg.Injector.SidecarContainer.RedirectPortOutbound).To(Equal(uint32(1234)))
34
Expect(cfg.Injector.SidecarContainer.RedirectPortInbound).To(Equal(uint32(1236)))
35
Expect(cfg.Injector.SidecarContainer.RedirectPortInboundV6).To(Equal(uint32(1237)))
36
Expect(cfg.Injector.SidecarContainer.UID).To(Equal(int64(2345)))
37
Expect(cfg.Injector.SidecarContainer.GID).To(Equal(int64(3456)))
38
Expect(cfg.Injector.SidecarContainer.AdminPort).To(Equal(uint32(45678)))
39
Expect(cfg.Injector.SidecarContainer.DrainTime.Duration).To(Equal(15 * time.Second))
41
Expect(cfg.Injector.SidecarContainer.ReadinessProbe.InitialDelaySeconds).To(Equal(int32(11)))
42
Expect(cfg.Injector.SidecarContainer.ReadinessProbe.TimeoutSeconds).To(Equal(int32(13)))
43
Expect(cfg.Injector.SidecarContainer.ReadinessProbe.PeriodSeconds).To(Equal(int32(15)))
44
Expect(cfg.Injector.SidecarContainer.ReadinessProbe.SuccessThreshold).To(Equal(int32(11)))
45
Expect(cfg.Injector.SidecarContainer.ReadinessProbe.FailureThreshold).To(Equal(int32(112)))
47
Expect(cfg.Injector.SidecarContainer.LivenessProbe.InitialDelaySeconds).To(Equal(int32(260)))
48
Expect(cfg.Injector.SidecarContainer.LivenessProbe.TimeoutSeconds).To(Equal(int32(23)))
49
Expect(cfg.Injector.SidecarContainer.LivenessProbe.PeriodSeconds).To(Equal(int32(25)))
50
Expect(cfg.Injector.SidecarContainer.LivenessProbe.FailureThreshold).To(Equal(int32(212)))
52
Expect(cfg.Injector.SidecarContainer.Resources.Requests.CPU).To(Equal("150m"))
53
Expect(cfg.Injector.SidecarContainer.Resources.Requests.Memory).To(Equal("164Mi"))
54
Expect(cfg.Injector.SidecarContainer.Resources.Limits.CPU).To(Equal("1100m"))
55
Expect(cfg.Injector.SidecarContainer.Resources.Limits.Memory).To(Equal("1512Mi"))
57
Expect(cfg.Injector.InitContainer.Image).To(Equal("kuma-init:latest"))
58
Expect(cfg.Injector.CNIEnabled).To(BeTrue())
60
Expect(cfg.Injector.BuiltinDNS.Enabled).To(BeTrue())
61
Expect(cfg.Injector.BuiltinDNS.Port).To(Equal(uint32(1253)))
63
Expect(cfg.MarshalingCacheExpirationTime.Duration).To(Equal(1 * time.Second))
66
It("should have consistent defaults", func() {
68
cfg := runtime_k8s.DefaultKubernetesRuntimeConfig()
71
actual, err := config.ToYAML(cfg)
74
Expect(err).ToNot(HaveOccurred())
75
Expect(actual).To(MatchGoldenYAML(filepath.Join("testdata", "default-config.golden.yaml")))
78
It("should have validators", func() {
80
cfg := runtime_k8s.KubernetesRuntimeConfig{}
83
err := config.Load(filepath.Join("testdata", "invalid-config.input.yaml"), &cfg)
86
Expect(err.Error()).To(Equal(`Invalid configuration: .AdmissionServer is not valid: .Port must be in the range [0, 65535]; .CertDir should not be empty; .Injector is not valid: .SidecarContainer is not valid: .Image must be non-empty; .RedirectPortInbound must be in the range [0, 65535]; .RedirectPortOutbound must be in the range [0, 65535]; .AdminPort must be in the range [0, 65535]; .DrainTime must be positive; .ReadinessProbe is not valid: .InitialDelaySeconds must be >= 1; .TimeoutSeconds must be >= 1; .PeriodSeconds must be >= 1; .SuccessThreshold must be >= 1; .FailureThreshold must be >= 1; .LivenessProbe is not valid: .InitialDelaySeconds must be >= 1; .TimeoutSeconds must be >= 1; .PeriodSeconds must be >= 1; .FailureThreshold must be >= 1; .Resources is not valid: .Requests is not valid: .CPU is not valid: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'; .Memory is not valid: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'; .Limits is not valid: .CPU is not valid: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'; .Memory is not valid: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'; .InitContainer is not valid: .Image must be non-empty; .MarshalingCacheExpirationTime must be positive or equal to 0`))