Skip to content

Conversation

siikamiika
Copy link
Contributor

@siikamiika siikamiika commented Oct 11, 2025

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

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 only ip 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-net

Docker 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:

Fixes #282

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

}

if let staticIndex {
try allocator.reserve(staticIndex)
Copy link
Contributor Author

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"")"")

Comment on lines +104 to +111
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
Copy link
Contributor Author

@siikamiika siikamiika Oct 12, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: A direct option to assign or configure the container's IP address

1 participant