util

package
v2.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionsKeyGeneric = "com.docker.network.generic"
)

Variables

View Source
var (
	// ErrIPAM is every refusal about address allocation; the wrapping site supplies the specific sentence (#110).
	ErrIPAM = errors.New("this network's address allocation was refused")
	// ErrBridgeRequired indicates a network bridge was not provided for network creation
	ErrBridgeRequired = errors.New("bridge required (mode=bridge)")
	// ErrNotBridge indicates that the provided network interface is not a bridge
	ErrNotBridge = errors.New("network interface is not a bridge")
	// ErrBridgeUsed indicates that a bridge is already in use
	ErrBridgeUsed = errors.New("bridge already in use by Docker")
	// ErrInvalidMode indicates an unsupported value was passed for the `mode` option
	ErrInvalidMode = errors.New("invalid mode (must be 'bridge', 'macvlan' or 'ipvlan')")
	// ErrParentRequired indicates `parent` was not provided when mode=macvlan
	ErrParentRequired = errors.New("parent required (mode=macvlan)")
	// ErrParentInvalid indicates the parent interface cannot host macvlan children
	ErrParentInvalid = errors.New("parent interface is unsuitable for macvlan (bridge or macvlan)")
	// ErrParentDown indicates the parent interface is administratively down
	ErrParentDown = errors.New("parent interface is down")
	// ErrModeMismatch indicates an option that doesn't apply to the chosen mode was set
	ErrModeMismatch = errors.New("option does not apply to selected mode")
	// ErrInvalidServerList indicates dhcp_servers or dhcp_deny_servers could not be parsed, or the two contradict.
	ErrInvalidServerList = errors.New("invalid DHCP server list")
	// ErrMACAddress indicates an invalid MAC address
	ErrMACAddress = errors.New("invalid MAC address")
	// ErrNoLease indicates a DHCP lease was not obtained from dhcpcd
	ErrNoLease = errors.New("no lease was acquired")

	// ErrNoHint indicates missing state from the CreateEndpoint stage in Join
	ErrNoHint = errors.New("missing CreateEndpoint hints")
	// ErrNotVEth indicates a host link was unexpectedly not a veth interface
	ErrNotVEth = errors.New("host link is not a veth interface")
	// ErrNoContainer indicates a container was unexpectedly not found
	ErrNoContainer = errors.New("couldn't find container by endpoint on the network")
	// ErrNoSandbox indicates missing state from the Join stage
	ErrNoSandbox = errors.New("missing joined endpoint state")
)

Functions

func AwaitCondition

func AwaitCondition(ctx context.Context, cond func() (bool, error), interval time.Duration) error

AwaitCondition polls cond in the caller's goroutine every interval until it returns true, an error, or ctx ends.

func AwaitContainerInspect

func AwaitContainerInspect(ctx context.Context, docker ContainerInspector, id string, interval time.Duration) (container.InspectResponse, error)

AwaitContainerInspect polls ContainerInspect in the caller's goroutine until it succeeds or ctx ends.

func AwaitLinkByIndex

func AwaitLinkByIndex(ctx context.Context, handle *netlink.Handle, index int, interval time.Duration) (netlink.Link, error)

AwaitLinkByIndex polls LinkByIndex in the caller's goroutine until the link appears or ctx ends.

func DumpResult

func DumpResult[T any](v []T, err error) ([]T, error)

DumpResult returns a netlink dump call's results with ErrDumpInterrupted dropped and every other error unchanged.

func ErrToStatus

func ErrToStatus(err error) int

ErrToStatus maps a sentinel error to its HTTP status, 500 for anything not listed.

func JSONErrResponse

func JSONErrResponse(w http.ResponseWriter, err error, statusCode int)

JSONErrResponse sends err as a JSON object and logs at Error for 5xx, Warn for 4xx and Info otherwise (#88).

func JSONResponse

func JSONResponse(w http.ResponseWriter, v interface{}, statusCode int)

JSONResponse sends v as JSON with statusCode, encoded first so an encoding failure still sends a clean 500.

func ParseJSONOrErrorResponse

func ParseJSONOrErrorResponse(v interface{}, w http.ResponseWriter, r *http.Request) error

ParseJSONOrErrorResponse decodes the body into v and, on failure, has already written the 400 response to w.

func WriteAccessLog

func WriteAccessLog(w io.Writer, params handlers.LogFormatterParams)

Types

type ContainerInspector

type ContainerInspector interface {
	ContainerInspect(ctx context.Context, id string, options client.ContainerInspectOptions) (client.ContainerInspectResult, error)
}

ContainerInspector is the one Docker-client method AwaitContainerInspect needs, so a test can pass a fake.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL