kuma

Форк
0
100 строк · 3.5 Кб
1
package bootstrap
2

3
import (
4
	"net"
5
	"os"
6
	"time"
7

8
	"github.com/pkg/errors"
9
	"go.uber.org/multierr"
10

11
	"github.com/kumahq/kuma/pkg/config"
12
	config_types "github.com/kumahq/kuma/pkg/config/types"
13
	"github.com/kumahq/kuma/pkg/util/files"
14
)
15

16
var _ config.Config = &BootstrapServerConfig{}
17

18
type BootstrapServerConfig struct {
19
	// Parameters of bootstrap configuration
20
	Params *BootstrapParamsConfig `json:"params"`
21
}
22

23
func (b *BootstrapServerConfig) Sanitize() {
24
	b.Params.Sanitize()
25
}
26

27
func (b *BootstrapServerConfig) PostProcess() error {
28
	return multierr.Combine(b.Params.PostProcess())
29
}
30

31
func (b *BootstrapServerConfig) Validate() error {
32
	if err := b.Params.Validate(); err != nil {
33
		return errors.Wrap(err, "Params validation failed")
34
	}
35
	return nil
36
}
37

38
func DefaultBootstrapServerConfig() *BootstrapServerConfig {
39
	return &BootstrapServerConfig{
40
		Params: DefaultBootstrapParamsConfig(),
41
	}
42
}
43

44
var _ config.Config = &BootstrapParamsConfig{}
45

46
type BootstrapParamsConfig struct {
47
	config.BaseConfig
48

49
	// Address of Envoy Admin
50
	AdminAddress string `json:"adminAddress" envconfig:"kuma_bootstrap_server_params_admin_address"`
51
	// Port of Envoy Admin
52
	AdminPort uint32 `json:"adminPort" envconfig:"kuma_bootstrap_server_params_admin_port"`
53
	// Path to access log file of Envoy Admin
54
	AdminAccessLogPath string `json:"adminAccessLogPath" envconfig:"kuma_bootstrap_server_params_admin_access_log_path"`
55
	// Host of XDS Server. By default it is the same host as the one used by kuma-dp to connect to the control plane
56
	XdsHost string `json:"xdsHost" envconfig:"kuma_bootstrap_server_params_xds_host"`
57
	// Port of XDS Server. By default it is autoconfigured from KUMA_XDS_SERVER_GRPC_PORT
58
	XdsPort uint32 `json:"xdsPort" envconfig:"kuma_bootstrap_server_params_xds_port"`
59
	// Connection timeout to the XDS Server
60
	XdsConnectTimeout config_types.Duration `json:"xdsConnectTimeout" envconfig:"kuma_bootstrap_server_params_xds_connect_timeout"`
61
	// Path to the template of Corefile for data planes to use
62
	CorefileTemplatePath string `json:"corefileTemplatePath" envconfig:"kuma_bootstrap_server_params_corefile_template_path"`
63
}
64

65
func (b *BootstrapParamsConfig) Validate() error {
66
	if b.AdminAddress == "" {
67
		return errors.New("AdminAddress cannot be empty")
68
	}
69
	if net.ParseIP(b.AdminAddress) == nil {
70
		return errors.New("AdminAddress should be a valid IP address")
71
	}
72
	if b.AdminPort > 65535 {
73
		return errors.New("AdminPort must be in the range [0, 65535]")
74
	}
75
	if b.AdminAccessLogPath == "" {
76
		return errors.New("AdminAccessLogPath cannot be empty")
77
	}
78
	if b.XdsPort > 65535 {
79
		return errors.New("AdminPort must be in the range [0, 65535]")
80
	}
81
	if b.XdsConnectTimeout.Duration < 0 {
82
		return errors.New("XdsConnectTimeout cannot be negative")
83
	}
84
	if b.CorefileTemplatePath != "" && !files.FileExists(b.CorefileTemplatePath) {
85
		return errors.New("CorefileTemplatePath must point to an existing file")
86
	}
87
	return nil
88
}
89

90
func DefaultBootstrapParamsConfig() *BootstrapParamsConfig {
91
	return &BootstrapParamsConfig{
92
		AdminAddress:         "127.0.0.1", // by default, Envoy Admin interface should listen on loopback address
93
		AdminPort:            9901,
94
		AdminAccessLogPath:   os.DevNull,
95
		XdsHost:              "", // by default, it is the same host as the one used by kuma-dp to connect to the control plane
96
		XdsPort:              0,  // by default, it is autoconfigured from KUMA_XDS_SERVER_GRPC_PORT
97
		XdsConnectTimeout:    config_types.Duration{Duration: 1 * time.Second},
98
		CorefileTemplatePath: "", // by default, data plane will use the embedded Corefile to be the template
99
	}
100
}
101

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

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

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

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