Skip to content

Commit

Permalink
DockerManager: Support IPv6 addresses
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tgraf committed Mar 17, 2016
1 parent 44eaf33 commit 90623d9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/kubelet/dockertools/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

1 comment on commit 90623d9

@k8s-teamcity-mesosphere

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity OSS :: Kubernetes Mesos :: 4 - Smoke Tests Build 19308 outcome was SUCCESS
Summary: Tests passed: 1, ignored: 265 Build time: 00:05:09

Please sign in to comment.