mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fail gracefully if Docker is not configured with ipv6.
PiperOrigin-RevId: 343927315
This commit is contained in:
committed by
gVisor bot
parent
b6c00520d3
commit
2320ce5b7d
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user