8
"github.com/pkg/errors"
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"
16
var _ config.Config = &BootstrapServerConfig{}
18
type BootstrapServerConfig struct {
20
Params *BootstrapParamsConfig `json:"params"`
23
func (b *BootstrapServerConfig) Sanitize() {
27
func (b *BootstrapServerConfig) PostProcess() error {
28
return multierr.Combine(b.Params.PostProcess())
31
func (b *BootstrapServerConfig) Validate() error {
32
if err := b.Params.Validate(); err != nil {
33
return errors.Wrap(err, "Params validation failed")
38
func DefaultBootstrapServerConfig() *BootstrapServerConfig {
39
return &BootstrapServerConfig{
40
Params: DefaultBootstrapParamsConfig(),
44
var _ config.Config = &BootstrapParamsConfig{}
46
type BootstrapParamsConfig struct {
50
AdminAddress string `json:"adminAddress" envconfig:"kuma_bootstrap_server_params_admin_address"`
52
AdminPort uint32 `json:"adminPort" envconfig:"kuma_bootstrap_server_params_admin_port"`
54
AdminAccessLogPath string `json:"adminAccessLogPath" envconfig:"kuma_bootstrap_server_params_admin_access_log_path"`
56
XdsHost string `json:"xdsHost" envconfig:"kuma_bootstrap_server_params_xds_host"`
58
XdsPort uint32 `json:"xdsPort" envconfig:"kuma_bootstrap_server_params_xds_port"`
60
XdsConnectTimeout config_types.Duration `json:"xdsConnectTimeout" envconfig:"kuma_bootstrap_server_params_xds_connect_timeout"`
62
CorefileTemplatePath string `json:"corefileTemplatePath" envconfig:"kuma_bootstrap_server_params_corefile_template_path"`
65
func (b *BootstrapParamsConfig) Validate() error {
66
if b.AdminAddress == "" {
67
return errors.New("AdminAddress cannot be empty")
69
if net.ParseIP(b.AdminAddress) == nil {
70
return errors.New("AdminAddress should be a valid IP address")
72
if b.AdminPort > 65535 {
73
return errors.New("AdminPort must be in the range [0, 65535]")
75
if b.AdminAccessLogPath == "" {
76
return errors.New("AdminAccessLogPath cannot be empty")
78
if b.XdsPort > 65535 {
79
return errors.New("AdminPort must be in the range [0, 65535]")
81
if b.XdsConnectTimeout.Duration < 0 {
82
return errors.New("XdsConnectTimeout cannot be negative")
84
if b.CorefileTemplatePath != "" && !files.FileExists(b.CorefileTemplatePath) {
85
return errors.New("CorefileTemplatePath must point to an existing file")
90
func DefaultBootstrapParamsConfig() *BootstrapParamsConfig {
91
return &BootstrapParamsConfig{
92
AdminAddress: "127.0.0.1",
94
AdminAccessLogPath: os.DevNull,
97
XdsConnectTimeout: config_types.Duration{Duration: 1 * time.Second},
98
CorefileTemplatePath: "",