kuma

Форк
0
/
config_test.go 
88 строк · 4.8 Кб
1
package k8s_test
2

3
import (
4
	"path/filepath"
5
	"time"
6

7
	. "github.com/onsi/ginkgo/v2"
8
	. "github.com/onsi/gomega"
9

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"
13
)
14

15
var _ = Describe("Config", func() {
16
	It("should be loadable from configuration file", func() {
17
		// given
18
		cfg := runtime_k8s.KubernetesRuntimeConfig{}
19
		// when
20
		err := config.Load(filepath.Join("testdata", "valid-config.input.yaml"), &cfg)
21

22
		// then
23
		Expect(err).ToNot(HaveOccurred())
24

25
		// and
26
		Expect(cfg.ControlPlaneServiceName).To(Equal("custom-control-plane"))
27

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"))
31
		// and
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))
40
		// and
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)))
46
		// and
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)))
51
		// and
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"))
56
		// and
57
		Expect(cfg.Injector.InitContainer.Image).To(Equal("kuma-init:latest"))
58
		Expect(cfg.Injector.CNIEnabled).To(BeTrue())
59
		// and
60
		Expect(cfg.Injector.BuiltinDNS.Enabled).To(BeTrue())
61
		Expect(cfg.Injector.BuiltinDNS.Port).To(Equal(uint32(1253)))
62
		// and
63
		Expect(cfg.MarshalingCacheExpirationTime.Duration).To(Equal(1 * time.Second))
64
	})
65

66
	It("should have consistent defaults", func() {
67
		// given
68
		cfg := runtime_k8s.DefaultKubernetesRuntimeConfig()
69

70
		// when
71
		actual, err := config.ToYAML(cfg)
72

73
		// then
74
		Expect(err).ToNot(HaveOccurred())
75
		Expect(actual).To(MatchGoldenYAML(filepath.Join("testdata", "default-config.golden.yaml")))
76
	})
77

78
	It("should have validators", func() {
79
		// given
80
		cfg := runtime_k8s.KubernetesRuntimeConfig{}
81

82
		// when
83
		err := config.Load(filepath.Join("testdata", "invalid-config.input.yaml"), &cfg)
84

85
		// then
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`))
87
	})
88
})
89

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.