Commit 3a6b3054 authored by Takeaki Matsumoto's avatar Takeaki Matsumoto

Change flag name and type

parent 9551e1db
...@@ -16,7 +16,7 @@ type Server struct { ...@@ -16,7 +16,7 @@ type Server struct {
DisableAgent bool DisableAgent bool
KubeConfigOutput string KubeConfigOutput string
KubeConfigMode string KubeConfigMode string
AdvertiseAddress string KnownIPs cli.StringSlice
} }
var ServerConfig Server var ServerConfig Server
...@@ -95,11 +95,10 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { ...@@ -95,11 +95,10 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
Destination: &ServerConfig.KubeConfigMode, Destination: &ServerConfig.KubeConfigMode,
EnvVar: "K3S_KUBECONFIG_MODE", EnvVar: "K3S_KUBECONFIG_MODE",
}, },
cli.StringFlag{ cli.StringSliceFlag{
Name: "advertise-address", Name: "tls-san",
Usage: "Advertise address for k3s server", Usage: "Add additional hostname or IP as a Subject Alternative Name in the TLS cert",
Destination: &ServerConfig.AdvertiseAddress, Value: &ServerConfig.KnownIPs,
Value: "",
}, },
NodeIPFlag, NodeIPFlag,
NodeNameFlag, NodeNameFlag,
......
...@@ -77,7 +77,7 @@ func run(app *cli.Context, cfg *cmds.Server) error { ...@@ -77,7 +77,7 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig.ControlConfig.KubeConfigMode = cfg.KubeConfigMode serverConfig.ControlConfig.KubeConfigMode = cfg.KubeConfigMode
serverConfig.TLSConfig.HTTPSPort = cfg.HTTPSPort serverConfig.TLSConfig.HTTPSPort = cfg.HTTPSPort
serverConfig.TLSConfig.HTTPPort = cfg.HTTPPort serverConfig.TLSConfig.HTTPPort = cfg.HTTPPort
serverConfig.TLSConfig.KnownIPs = knownIPs(cfg.AdvertiseAddress) serverConfig.TLSConfig.KnownIPs = knownIPs(cfg.KnownIPs)
_, serverConfig.ControlConfig.ClusterIPRange, err = net2.ParseCIDR(cfg.ClusterCIDR) _, serverConfig.ControlConfig.ClusterIPRange, err = net2.ParseCIDR(cfg.ClusterCIDR)
if err != nil { if err != nil {
...@@ -146,18 +146,11 @@ func run(app *cli.Context, cfg *cmds.Server) error { ...@@ -146,18 +146,11 @@ func run(app *cli.Context, cfg *cmds.Server) error {
return agent.Run(ctx, agentConfig) return agent.Run(ctx, agentConfig)
} }
func knownIPs(hosts string) []string { func knownIPs(ips []string) []string {
ips := []string{ ips = append(ips, "127.0.0.1")
"127.0.0.1",
}
ip, err := net.ChooseHostInterface() ip, err := net.ChooseHostInterface()
if err == nil { if err == nil {
ips = append(ips, ip.String()) ips = append(ips, ip.String())
} }
for _, host := range strings.Split(hosts, ",") {
if host != "" {
ips = append(ips, host)
}
}
return ips return ips
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment