6
"github.com/asaskevich/govalidator"
7
"github.com/pkg/errors"
10
config_types "github.com/kumahq/kuma/pkg/config/types"
13
func DefaultInterCpConfig() InterCpConfig {
15
Catalog: CatalogConfig{
16
InstanceAddress: "", // autoconfigured
17
HeartbeatInterval: config_types.Duration{Duration: 5 * time.Second},
18
WriterInterval: config_types.Duration{Duration: 15 * time.Second},
20
Server: InterCpServerConfig{
22
TlsMinVersion: "TLSv1_2",
23
TlsCipherSuites: []string{},
28
type InterCpConfig struct {
29
// Catalog configuration. Catalog keeps a record of all live CP instances in the zone.
30
Catalog CatalogConfig `json:"catalog"`
31
// Intercommunication CP server configuration
32
Server InterCpServerConfig `json:"server"`
35
func (i *InterCpConfig) Validate() error {
36
if err := i.Server.Validate(); err != nil {
37
return errors.Wrap(err, ".Server validation failed")
39
if err := i.Catalog.Validate(); err != nil {
40
return errors.Wrap(err, ".Catalog validation failed")
45
type CatalogConfig struct {
46
// InstanceAddress indicates an address on which other control planes can communicate with this CP
47
// If empty then it's autoconfigured by taking the first IP of the nonloopback network interface.
48
InstanceAddress string `json:"instanceAddress" envconfig:"kuma_inter_cp_catalog_instance_address"`
49
// Interval on which CP will send heartbeat to a leader.
50
HeartbeatInterval config_types.Duration `json:"heartbeatInterval" envconfig:"kuma_inter_cp_catalog_heartbeat_interval"`
51
// Interval on which CP will write all instances to a catalog.
52
WriterInterval config_types.Duration `json:"writerInterval" envconfig:"kuma_inter_cp_catalog_writer_interval"`
55
func (i *CatalogConfig) Validate() error {
56
if i.InstanceAddress != "" && !govalidator.IsDNSName(i.InstanceAddress) && !govalidator.IsIP(i.InstanceAddress) {
57
return errors.New(".InstanceAddress has to be valid IP or DNS address")
62
type InterCpServerConfig struct {
63
// Port on which Intercommunication CP server will listen
64
Port uint16 `json:"port" envconfig:"kuma_inter_cp_server_port"`
65
// TlsMinVersion defines the minimum TLS version to be used
66
TlsMinVersion string `json:"tlsMinVersion" envconfig:"kuma_inter_cp_server_tls_min_version"`
67
// TlsMaxVersion defines the maximum TLS version to be used
68
TlsMaxVersion string `json:"tlsMaxVersion" envconfig:"kuma_inter_cp_server_tls_max_version"`
69
// TlsCipherSuites defines the list of ciphers to use
70
TlsCipherSuites []string `json:"tlsCipherSuites" envconfig:"kuma_inter_cp_server_tls_cipher_suites"`
73
func (i *InterCpServerConfig) Validate() error {
76
errs = multierr.Append(errs, errors.New(".Port cannot be zero"))
78
if _, err := config_types.TLSVersion(i.TlsMinVersion); err != nil {
79
errs = multierr.Append(errs, errors.New(".TlsMinVersion "+err.Error()))
81
if _, err := config_types.TLSVersion(i.TlsMaxVersion); err != nil {
82
errs = multierr.Append(errs, errors.New(".TlsMaxVersion "+err.Error()))
84
if _, err := config_types.TLSCiphers(i.TlsCipherSuites); err != nil {
85
errs = multierr.Append(errs, errors.New(".TlsCipherSuites "+err.Error()))