Fail gracefully if Docker is not configured with ipv6.

PiperOrigin-RevId: 343927315
This commit is contained in:
Adin Scannell
2020-11-23 14:24:27 -08:00
committed by gVisor bot
parent b6c00520d3
commit 2320ce5b7d
2 changed files with 9 additions and 1 deletions
+5 -1
View File
@@ -17,6 +17,7 @@ package dockerutil
import (
"bytes"
"context"
"errors"
"fmt"
"io/ioutil"
"net"
@@ -351,6 +352,9 @@ func (c *Container) SandboxPid(ctx context.Context) (int, error) {
return resp.ContainerJSONBase.State.Pid, nil
}
// ErrNoIP indicates that no IP address is available.
var ErrNoIP = errors.New("no IP available")
// FindIP returns the IP address of the container.
func (c *Container) FindIP(ctx context.Context, ipv6 bool) (net.IP, error) {
resp, err := c.client.ContainerInspect(ctx, c.id)
@@ -365,7 +369,7 @@ func (c *Container) FindIP(ctx context.Context, ipv6 bool) (net.IP, error) {
ip = net.ParseIP(resp.NetworkSettings.DefaultNetworkSettings.IPAddress)
}
if ip == nil {
return net.IP{}, fmt.Errorf("invalid IP: %q", ip)
return net.IP{}, ErrNoIP
}
return ip, nil
}
+4
View File
@@ -89,6 +89,10 @@ func iptablesTest(t *testing.T, test TestCase, ipv6 bool) {
// Get the container IP.
ip, err := d.FindIP(ctx, ipv6)
if err != nil {
// If ipv6 is not configured, don't fail.
if ipv6 && err == dockerutil.ErrNoIP {
t.Skipf("No ipv6 address is available.")
}
t.Fatalf("failed to get container IP: %v", err)
}