mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 23:29:21 +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 {
|
if container.NetworkSettings != nil {
|
||||||
result = container.NetworkSettings.IPAddress
|
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 {
|
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}
|
args := []string{"-t", fmt.Sprintf("%d", containerPid), "-n", "--", "bash", "-c", extractIPCmd}
|
||||||
command := exec.Command("nsenter", args...)
|
command := exec.Command("nsenter", args...)
|
||||||
out, err := command.CombinedOutput()
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user