mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
DockerManager: Support IPv6 addresses
Falls back to the GlobalIPv6Address or ip -6 addr output in case no IPv4 is configured for the container. Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
parent
44eaf33056
commit
90623d9b51
@ -301,6 +301,11 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont
|
||||
|
||||
if container.NetworkSettings != nil {
|
||||
result = container.NetworkSettings.IPAddress
|
||||
|
||||
// Fall back to IPv6 address if no IPv4 address is present
|
||||
if result == "" {
|
||||
result = container.NetworkSettings.GlobalIPv6Address
|
||||
}
|
||||
}
|
||||
|
||||
if dm.networkPlugin.Name() != network.DefaultPluginName {
|
||||
@ -1214,6 +1219,15 @@ func (dm *DockerManager) GetContainerIP(containerID, interfaceName string) (stri
|
||||
args := []string{"-t", fmt.Sprintf("%d", containerPid), "-n", "--", "bash", "-c", extractIPCmd}
|
||||
command := exec.Command("nsenter", args...)
|
||||
out, err := command.CombinedOutput()
|
||||
|
||||
// Fall back to IPv6 address if no IPv4 address is present
|
||||
if err == nil && string(out) == "" {
|
||||
extractIPCmd = fmt.Sprintf("ip -6 addr show %s scope global | grep inet6 | awk -F\" \" '{print $2}'", interfaceName)
|
||||
args = []string{"-t", fmt.Sprintf("%d", containerPid), "-n", "--", "bash", "-c", extractIPCmd}
|
||||
command = exec.Command("nsenter", args...)
|
||||
out, err = command.CombinedOutput()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user