Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/ContainerClient/Core/ClientNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public struct ClientNetwork {
static let serviceIdentifier = "com.apple.container.apiserver"

public static let defaultNetworkName = "default"
public static let noNetworkName = "none"
}

extension ClientNetwork {
Expand Down
17 changes: 12 additions & 5 deletions Sources/ContainerClient/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,18 @@ public struct Utility {

config.virtualization = management.virtualization

config.networks = try getAttachmentConfigurations(containerId: config.id, networkIds: management.networks)
for attachmentConfiguration in config.networks {
let network: NetworkState = try await ClientNetwork.get(id: attachmentConfiguration.network)
guard case .running(_, _) = network else {
throw ContainerizationError(.invalidState, message: "network \(attachmentConfiguration.network) is not running")
if management.networks.contains(ClientNetwork.noNetworkName) {
if management.networks.count != 1 {
throw ContainerizationError(.unsupported, message: "no other networks may be created along with network \(ClientNetwork.noNetworkName)")
}
config.networks = []
} else {
config.networks = try getAttachmentConfigurations(containerId: config.id, networkIds: management.networks)
for attachmentConfiguration in config.networks {
let network: NetworkState = try await ClientNetwork.get(id: attachmentConfiguration.network)
guard case .running(_, _) = network else {
throw ContainerizationError(.invalidState, message: "network \(attachmentConfiguration.network) is not running")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public actor NetworksService {
"id": "\(configuration.id)"
])

//Ensure that the network is not named "none"
if configuration.id == ClientNetwork.noNetworkName {
throw ContainerizationError(.unsupported, message: "network \(configuration.id) is not a valid name")
}

// Ensure nobody is manipulating the network already.
guard !busyNetworks.contains(configuration.id) else {
throw ContainerizationError(.exists, message: "network \(configuration.id) has a pending operation")
Expand Down