mirror of https://github.com/k3s-io/k3s
Use default address family when adding kubernetes service address to SAN list
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>pull/6938/head
parent
566975533d
commit
208486323b
|
@ -208,18 +208,17 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
|
|||
}
|
||||
|
||||
if serverConfig.ControlConfig.PrivateIP == "" && len(cmds.AgentConfig.NodeIP) != 0 {
|
||||
// ignoring the error here is fine since etcd will fall back to the interface's IPv4 address
|
||||
serverConfig.ControlConfig.PrivateIP, _, _ = util.GetFirstString(cmds.AgentConfig.NodeIP)
|
||||
serverConfig.ControlConfig.PrivateIP = util.GetFirstValidIPString(cmds.AgentConfig.NodeIP)
|
||||
}
|
||||
|
||||
// if not set, try setting advertise-ip from agent node-external-ip
|
||||
if serverConfig.ControlConfig.AdvertiseIP == "" && len(cmds.AgentConfig.NodeExternalIP) != 0 {
|
||||
serverConfig.ControlConfig.AdvertiseIP, _, _ = util.GetFirstString(cmds.AgentConfig.NodeExternalIP)
|
||||
serverConfig.ControlConfig.AdvertiseIP = util.GetFirstValidIPString(cmds.AgentConfig.NodeExternalIP)
|
||||
}
|
||||
|
||||
// if not set, try setting advertise-ip from agent node-ip
|
||||
if serverConfig.ControlConfig.AdvertiseIP == "" && len(cmds.AgentConfig.NodeIP) != 0 {
|
||||
serverConfig.ControlConfig.AdvertiseIP, _, _ = util.GetFirstString(cmds.AgentConfig.NodeIP)
|
||||
serverConfig.ControlConfig.AdvertiseIP = util.GetFirstValidIPString(cmds.AgentConfig.NodeIP)
|
||||
}
|
||||
|
||||
// if we ended up with any advertise-ips, ensure they're added to the SAN list;
|
||||
|
@ -301,7 +300,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
|
|||
}
|
||||
|
||||
// the apiserver service does not yet support dual-stack operation
|
||||
_, apiServerServiceIP, err := controlplane.ServiceIPRange(*serverConfig.ControlConfig.ServiceIPRange)
|
||||
_, apiServerServiceIP, err := controlplane.ServiceIPRange(*serverConfig.ControlConfig.ServiceIPRanges[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -189,6 +189,19 @@ func ParseStringSliceToIPs(s cli.StringSlice) ([]net.IP, error) {
|
|||
return ips, nil
|
||||
}
|
||||
|
||||
// GetFirstValidIPString returns the first valid address from a list of IP address strings,
|
||||
// without preference for IP family. If no address are found, an empty string is returned.
|
||||
func GetFirstValidIPString(s cli.StringSlice) string {
|
||||
for _, unparsedIP := range s {
|
||||
for _, v := range strings.Split(unparsedIP, ",") {
|
||||
if ip := net.ParseIP(v); ip != nil {
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetFirstIP returns the first IPv4 address from the list of IP addresses.
|
||||
// If no IPv4 addresses are found, returns the first IPv6 address
|
||||
// if neither of IPv4 or IPv6 are found an error is raised.
|
||||
|
|
Loading…
Reference in New Issue