Skip to content

Commit ab78d7a

Browse files
committed
[container-run-create]: add support for --network none
1 parent 0d3f20c commit ab78d7a

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Sources/ContainerClient/Core/ClientNetwork.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public struct ClientNetwork {
2424
static let serviceIdentifier = "com.apple.container.apiserver"
2525

2626
public static let defaultNetworkName = "default"
27+
public static let noNetworkName = "none"
2728
}
2829

2930
extension ClientNetwork {

Sources/ContainerClient/Utility.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,18 @@ public struct Utility {
180180

181181
config.virtualization = management.virtualization
182182

183-
config.networks = try getAttachmentConfigurations(containerId: config.id, networkIds: management.networks)
184-
for attachmentConfiguration in config.networks {
185-
let network: NetworkState = try await ClientNetwork.get(id: attachmentConfiguration.network)
186-
guard case .running(_, _) = network else {
187-
throw ContainerizationError(.invalidState, message: "network \(attachmentConfiguration.network) is not running")
183+
if management.networks.contains(ClientNetwork.noNetworkName) {
184+
if management.networks.count != 1 {
185+
throw ContainerizationError(.unsupported, message: "no other networks may be created along with network \(ClientNetwork.noNetworkName)")
186+
}
187+
config.networks = []
188+
} else {
189+
config.networks = try getAttachmentConfigurations(containerId: config.id, networkIds: management.networks)
190+
for attachmentConfiguration in config.networks {
191+
let network: NetworkState = try await ClientNetwork.get(id: attachmentConfiguration.network)
192+
guard case .running(_, _) = network else {
193+
throw ContainerizationError(.invalidState, message: "network \(attachmentConfiguration.network) is not running")
194+
}
188195
}
189196
}
190197

Sources/Services/ContainerAPIService/Networks/NetworksService.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public actor NetworksService {
107107
"id": "\(configuration.id)"
108108
])
109109

110+
//Ensure that the network is not named "none"
111+
if configuration.id == ClientNetwork.noNetworkName {
112+
throw ContainerizationError(.unsupported, message: "network \(configuration.id) is not a valid name")
113+
}
114+
110115
// Ensure nobody is manipulating the network already.
111116
guard !busyNetworks.contains(configuration.id) else {
112117
throw ContainerizationError(.exists, message: "network \(configuration.id) has a pending operation")

0 commit comments

Comments
 (0)