From 9551e1db21d56f7d801be5f1bb5bc117281837ab Mon Sep 17 00:00:00 2001 From: Takeaki Matsumoto Date: Mon, 18 Mar 2019 08:21:55 +0000 Subject: [PATCH] Add advertise-address flag In NAT or LB environment, we need not just the certs for local ip, but also additional ips. advertise-address flag enables to add optional ips. --- pkg/cli/cmds/server.go | 7 +++++++ pkg/cli/server/server.go | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/cli/cmds/server.go b/pkg/cli/cmds/server.go index 7e68f0b854..52089a24d4 100644 --- a/pkg/cli/cmds/server.go +++ b/pkg/cli/cmds/server.go @@ -16,6 +16,7 @@ type Server struct { DisableAgent bool KubeConfigOutput string KubeConfigMode string + AdvertiseAddress string } var ServerConfig Server @@ -94,6 +95,12 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { Destination: &ServerConfig.KubeConfigMode, EnvVar: "K3S_KUBECONFIG_MODE", }, + cli.StringFlag{ + Name: "advertise-address", + Usage: "Advertise address for k3s server", + Destination: &ServerConfig.AdvertiseAddress, + Value: "", + }, NodeIPFlag, NodeNameFlag, DockerFlag, diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index 51958a6e55..f12eb3063b 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -77,7 +77,7 @@ func run(app *cli.Context, cfg *cmds.Server) error { serverConfig.ControlConfig.KubeConfigMode = cfg.KubeConfigMode serverConfig.TLSConfig.HTTPSPort = cfg.HTTPSPort serverConfig.TLSConfig.HTTPPort = cfg.HTTPPort - serverConfig.TLSConfig.KnownIPs = knownIPs() + serverConfig.TLSConfig.KnownIPs = knownIPs(cfg.AdvertiseAddress) _, serverConfig.ControlConfig.ClusterIPRange, err = net2.ParseCIDR(cfg.ClusterCIDR) if err != nil { @@ -146,7 +146,7 @@ func run(app *cli.Context, cfg *cmds.Server) error { return agent.Run(ctx, agentConfig) } -func knownIPs() []string { +func knownIPs(hosts string) []string { ips := []string{ "127.0.0.1", } @@ -154,5 +154,10 @@ func knownIPs() []string { if err == nil { ips = append(ips, ip.String()) } + for _, host := range strings.Split(hosts, ",") { + if host != "" { + ips = append(ips, host) + } + } return ips }