Skip to content

Commit

Permalink
feat(kuma-cp) autoconfigure xds params (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubdyszkiewicz authored Nov 20, 2019
1 parent d8bbcfd commit aba8583
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3057,10 +3057,6 @@ spec:
value: "5681"
- name: KUMA_BOOTSTRAP_SERVER_PORT
value: "5682"
- name: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST
value: "kuma-control-plane.kuma-system"
- name: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT
value: "5678"
- name: KUMA_SDS_SERVER_TLS_CERT_FILE
value: /var/run/secrets/kuma.io/kuma-sds/tls-cert/tls.crt
- name: KUMA_SDS_SERVER_TLS_KEY_FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3057,10 +3057,6 @@ spec:
value: "5681"
- name: KUMA_BOOTSTRAP_SERVER_PORT
value: "5682"
- name: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST
value: "kuma-ctrl-plane.kuma"
- name: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT
value: "5678"
- name: KUMA_SDS_SERVER_TLS_CERT_FILE
value: /var/run/secrets/kuma.io/kuma-sds/tls-cert/tls.crt
- name: KUMA_SDS_SERVER_TLS_KEY_FILE
Expand Down
4 changes: 0 additions & 4 deletions app/kumactl/data/install/k8s/control-plane/kuma-cp/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ spec:
value: "5681"
- name: KUMA_BOOTSTRAP_SERVER_PORT
value: "5682"
- name: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST
value: {{ .ControlPlaneServiceName }}.{{ .Namespace }}
- name: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT
value: "5678"
- name: KUMA_SDS_SERVER_TLS_CERT_FILE
value: /var/run/secrets/kuma.io/kuma-sds/tls-cert/tls.crt
- name: KUMA_SDS_SERVER_TLS_KEY_FILE
Expand Down
14 changes: 7 additions & 7 deletions app/kumactl/pkg/install/k8s/control-plane/templates_vfsdata.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ bootstrapServer:
adminPort: 0 # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_PORT
# Path to access log file of Envoy Admin
adminAccessLogPath: /dev/null # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_ADMIN_ACCESS_LOG_PATH
# Host of XDS Server
xdsHost: 127.0.0.1 # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST
# Port of XDS Server
xdsPort: 5678 # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT
# Host of XDS Server. By default it is autoconfigured from KUMA_GENERAL_ADVERTISED_HOSTNAME
xdsHost: "" # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST
# Port of XDS Server. By default it is autoconfigured from KUMA_XDS_SERVER_GRPC_PORT
xdsPort: 0 # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_PORT
# Connection timeout to the XDS Server
xdsConnectTimeout: 1s # ENV: KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_CONNECT_TIMEOUT

Expand Down
11 changes: 4 additions & 7 deletions pkg/config/xds/bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type BootstrapParamsConfig struct {
AdminPort uint32 `yaml:"adminPort" envconfig:"kuma_bootstrap_server_params_admin_port"`
// Path to access log file of Envoy Admin
AdminAccessLogPath string `yaml:"adminAccessLogPath" envconfig:"kuma_bootstrap_server_params_admin_access_log_path"`
// Host of XDS Server
// Host of XDS Server. By default it is autoconfigured from KUMA_GENERAL_ADVERTISED_HOSTNAME
XdsHost string `yaml:"xdsHost" envconfig:"kuma_bootstrap_server_params_xds_host"`
// Port of XDS Server
// Port of XDS Server. By default it is autoconfigured from KUMA_XDS_SERVER_GRPC_PORT
XdsPort uint32 `yaml:"xdsPort" envconfig:"kuma_bootstrap_server_params_xds_port"`
// Connection timeout to the XDS Server
XdsConnectTimeout time.Duration `yaml:"xdsConnectTimeout" envconfig:"kuma_bootstrap_server_params_xds_connect_timeout"`
Expand All @@ -65,9 +65,6 @@ func (b *BootstrapParamsConfig) Validate() error {
if b.AdminAccessLogPath == "" {
return errors.New("AdminAccessLogPath cannot be empty")
}
if b.XdsHost == "" {
return errors.New("XdsHost cannot be empty")
}
if b.XdsPort > 65535 {
return errors.New("AdminPort must be in the range [0, 65535]")
}
Expand All @@ -82,8 +79,8 @@ func DefaultBootstrapParamsConfig() *BootstrapParamsConfig {
AdminAddress: "127.0.0.1", // by default, Envoy Admin interface should listen on loopback address
AdminPort: 0, // by default, turn off Admin interface of Envoy
AdminAccessLogPath: "/dev/null",
XdsHost: "127.0.0.1",
XdsPort: 5678,
XdsHost: "", // by default it is autoconfigured from KUMA_GENERAL_ADVERTISED_HOSTNAME
XdsPort: 0, // by default it is autoconfigured from KUMA_XDS_SERVER_GRPC_PORT
XdsConnectTimeout: 1 * time.Second,
}
}
4 changes: 2 additions & 2 deletions pkg/config/xds/bootstrap/testdata/default-config.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ params:
adminAddress: 127.0.0.1
adminPort: 0
xdsConnectTimeout: 1s
xdsHost: 127.0.0.1
xdsPort: 5678
xdsHost: ""
xdsPort: 0
10 changes: 10 additions & 0 deletions pkg/core/bootstrap/autoconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func autoconfigure(cfg *kuma_cp.Config) error {
autoconfigureDataplaneTokenServer(cfg.DataplaneTokenServer)
autoconfigureCatalogue(cfg)
autoconfigureGui(cfg)
autoconfigBootstrapXdsParams(cfg)
return autoconfigureSds(cfg)
}

Expand Down Expand Up @@ -80,6 +81,15 @@ func autoconfigureGui(cfg *kuma_cp.Config) {
}
}

func autoconfigBootstrapXdsParams(cfg *kuma_cp.Config) {
if cfg.BootstrapServer.Params.XdsHost == "" {
cfg.BootstrapServer.Params.XdsHost = cfg.General.AdvertisedHostname
}
if cfg.BootstrapServer.Params.XdsPort == 0 {
cfg.BootstrapServer.Params.XdsPort = uint32(cfg.XdsServer.GrpcPort)
}
}

func saveKeyPair(pair tls.KeyPair) (string, string, error) {
crtFile, err := ioutil.TempFile("", "*.crt")
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions pkg/core/bootstrap/autoconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,21 @@ var _ = Describe("Auto configuration", func() {
Environment: "kubernetes",
}))
})

It("should autoconfigure xds params", func() {
// given
cfg := kuma_cp.DefaultConfig()
cfg.General.AdvertisedHostname = "kuma.internal"
cfg.XdsServer.GrpcPort = 1234

// when
err := autoconfigure(&cfg)

// then
Expect(err).ToNot(HaveOccurred())

// and
Expect(cfg.BootstrapServer.Params.XdsHost).To(Equal("kuma.internal"))
Expect(cfg.BootstrapServer.Params.XdsPort).To(Equal(uint32(1234)))
})
})
50 changes: 32 additions & 18 deletions pkg/xds/bootstrap/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ var _ = Describe("bootstrapGenerator", func() {
})

type testCase struct {
config *bootstrap_config.BootstrapParamsConfig
config func() *bootstrap_config.BootstrapParamsConfig
request types.BootstrapRequest
expectedConfigFile string
}
DescribeTable("should generate bootstrap configuration",
func(given testCase) {
// setup
generator := NewDefaultBootstrapGenerator(resManager, given.config)
generator := NewDefaultBootstrapGenerator(resManager, given.config())

// when
bootstrapConfig, err := generator.Generate(context.Background(), given.request)
Expand All @@ -87,15 +87,25 @@ var _ = Describe("bootstrapGenerator", func() {
Expect(actual).To(MatchYAML(expected))
},
Entry("default config with minimal request", testCase{
config: bootstrap_config.DefaultBootstrapParamsConfig(),
config: func() *bootstrap_config.BootstrapParamsConfig {
cfg := bootstrap_config.DefaultBootstrapParamsConfig()
cfg.XdsHost = "127.0.0.1"
cfg.XdsPort = 5678
return cfg
},
request: types.BootstrapRequest{
Mesh: "mesh",
Name: "name.namespace",
},
expectedConfigFile: "generator.default-config-minimal-request.golden.yaml",
}),
Entry("default config", testCase{
config: bootstrap_config.DefaultBootstrapParamsConfig(),
config: func() *bootstrap_config.BootstrapParamsConfig {
cfg := bootstrap_config.DefaultBootstrapParamsConfig()
cfg.XdsHost = "127.0.0.1"
cfg.XdsPort = 5678
return cfg
},
request: types.BootstrapRequest{
Mesh: "mesh",
Name: "name.namespace",
Expand All @@ -105,13 +115,15 @@ var _ = Describe("bootstrapGenerator", func() {
expectedConfigFile: "generator.default-config.golden.yaml",
}),
Entry("custom config with minimal request", testCase{
config: &bootstrap_config.BootstrapParamsConfig{
AdminAddress: "192.168.0.1", // by default, Envoy Admin interface should listen on loopback address
AdminPort: 9902, // by default, turn off Admin interface of Envoy
AdminAccessLogPath: "/var/log",
XdsHost: "kuma-control-plane.internal",
XdsPort: 15678,
XdsConnectTimeout: 2 * time.Second,
config: func() *bootstrap_config.BootstrapParamsConfig {
return &bootstrap_config.BootstrapParamsConfig{
AdminAddress: "192.168.0.1", // by default, Envoy Admin interface should listen on loopback address
AdminPort: 9902, // by default, turn off Admin interface of Envoy
AdminAccessLogPath: "/var/log",
XdsHost: "kuma-control-plane.internal",
XdsPort: 15678,
XdsConnectTimeout: 2 * time.Second,
}
},
request: types.BootstrapRequest{
Mesh: "mesh",
Expand All @@ -120,13 +132,15 @@ var _ = Describe("bootstrapGenerator", func() {
expectedConfigFile: "generator.custom-config-minimal-request.golden.yaml",
}),
Entry("custom config", testCase{
config: &bootstrap_config.BootstrapParamsConfig{
AdminAddress: "192.168.0.1", // by default, Envoy Admin interface should listen on loopback address
AdminPort: 9902, // by default, turn off Admin interface of Envoy
AdminAccessLogPath: "/var/log",
XdsHost: "kuma-control-plane.internal",
XdsPort: 15678,
XdsConnectTimeout: 2 * time.Second,
config: func() *bootstrap_config.BootstrapParamsConfig {
return &bootstrap_config.BootstrapParamsConfig{
AdminAddress: "192.168.0.1", // by default, Envoy Admin interface should listen on loopback address
AdminPort: 9902, // by default, turn off Admin interface of Envoy
AdminAccessLogPath: "/var/log",
XdsHost: "kuma-control-plane.internal",
XdsPort: 15678,
XdsConnectTimeout: 2 * time.Second,
}
},
request: types.BootstrapRequest{
Mesh: "mesh",
Expand Down
2 changes: 2 additions & 0 deletions pkg/xds/bootstrap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var _ = Describe("Bootstrap Server", func() {
BeforeEach(func() {
resManager = manager.NewResourceManager(memory.NewStore())
config = bootstrap_config.DefaultBootstrapParamsConfig()
config.XdsHost = "127.0.0.1"
config.XdsPort = 5678

port, err := test.GetFreePort()
baseUrl = "http://localhost:" + strconv.Itoa(port)
Expand Down
1 change: 0 additions & 1 deletion tools/e2e/examples/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ services:
environment:
# DNS name of the Kuma xDS server
- KUMA_GENERAL_ADVERTISED_HOSTNAME=kuma-control-plane
- KUMA_BOOTSTRAP_SERVER_PARAMS_XDS_HOST=kuma-control-plane
- KUMA_DATAPLANE_TOKEN_SERVER_PUBLIC_ENABLED=true
- KUMA_DATAPLANE_TOKEN_SERVER_PUBLIC_INTERFACE=0.0.0.0
- KUMA_DATAPLANE_TOKEN_SERVER_PUBLIC_PORT=5684 # otherwise there would be conflict with local port
Expand Down

0 comments on commit aba8583

Please sign in to comment.