From 90623d9b51080ab778c8dcee63f0043be931ee07 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Thu, 17 Mar 2016 01:27:16 +0100 Subject: [PATCH] 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 --- pkg/kubelet/dockertools/manager.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/kubelet/dockertools/manager.go b/pkg/kubelet/dockertools/manager.go index c88b0b6d241..00fc1aff924 100644 --- a/pkg/kubelet/dockertools/manager.go +++ b/pkg/kubelet/dockertools/manager.go @@ -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 }