-
Notifications
You must be signed in to change notification settings - Fork 480
Specify ip in --network #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
if let staticIndex { | ||
try allocator.reserve(staticIndex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When trying to reserve gateway ip 192.168.64.1:
Error: internalError: "failed to bootstrap container" (cause: "internalError: "failed to bootstrap container 66336145-44ba-4e26-8954-39eecd7f73fa (cause: "unknown: "cannot create index using address 3232251905"")"")
When trying to reserve already allocated ip 192.168.64.12:
Error: internalError: "failed to bootstrap container" (cause: "internalError: "failed to bootstrap container b7bd2b0f-00db-4cd3-8970-fd55864d6089 (cause: "unknown: "cannot choose already-allocated address 3232251916"")"")
let networkInspectOutput = try inspectNetwork(name) | ||
guard let networkInspectStatus = networkInspectOutput.status else { | ||
throw CLIError.invalidOutput("network inspect output invalid, missing status") | ||
} | ||
let network = try CIDRAddress(networkInspectStatus.address) | ||
var addressBytes = network.address.networkBytes | ||
addressBytes[3] = UInt8.random(in: 10...100) | ||
let staticIp = try IPv4Address(fromNetworkBytes: addressBytes).description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting a static ip for testing is a bit difficult without a static subnet (#737) but should work
Type of Change
Motivation and Context
Adds Flag.NetworkArg, an
ExpressibleByArgument
struct replacing networkId that optionally parses an arbitrary amount of kv arguments in addition to network id:<network_id>[:k1=v1,k2=v2,...]
.ExpressibleByArgument
doesn't support throwing so invalid kv arguments are also parsed into an array and thrown before creating attachment configurations. Here onlyip
will be added to supported keys.AddressAllocator from containerization used by AttachmentAllocator supports reserving addresses and handles skipping over reserved addresses even when dynamic allocation starts behind and gets ahead of a reserved address. Attempting to reserve invalid addresses (already taken or out of range) throws a pretty low level error and should maybe be improved.
Does not currently implement --ip but can be done and merged with --network in getAttachmentConfigurations. However, swift argument parser doesn't seem to retain positional information relative to other flags and that makes supporting multiple --ip for multiple networks challenging. Also other container tools (only tried podman) seem to error when using --ip or --mac-address with multiple --network s.
The implemented format
--network network_id[:ip=<>]
follows Podman syntax: https://docs.podman.io/en/latest/markdown/podman-run.1.html#network-mode-netDocker style would be
--network name=network_id,ip=<>
: https://docs.docker.com/reference/cli/docker/container/run/#network (apparently:
is reserved for--network container:containername
)Both can be supported simultaneously without breaking changes but maybe just one should be chosen to avoid confusing documentation.
Related:
--network
#459.Fixes #282
Testing