Skip to content

Commit 267d6a5

Browse files
committed
Defer builtinNetworkId check until we really need it.
1 parent 5d7368d commit 267d6a5

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Sources/Services/ContainerAPIService/Client/Utility.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,14 @@ public struct Utility {
190190
config.virtualization = management.virtualization
191191

192192
// Parse network specifications with properties
193-
guard let builtinNetworkId = try await ClientNetwork.builtin?.id else {
194-
throw ContainerizationError(.invalidState, message: "builtin network is not present")
195-
}
196193
let parsedNetworks = try management.networks.map { try Parser.network($0) }
197194
if management.networks.contains(ClientNetwork.noNetworkName) {
198195
guard management.networks.count == 1 else {
199196
throw ContainerizationError(.unsupported, message: "no other networks may be created along with network \(ClientNetwork.noNetworkName)")
200197
}
201198
config.networks = []
202199
} else {
200+
let builtinNetworkId = try await ClientNetwork.builtin?.id
203201
config.networks = try getAttachmentConfigurations(
204202
containerId: config.id,
205203
builtinNetworkId: builtinNetworkId,
@@ -253,7 +251,7 @@ public struct Utility {
253251

254252
static func getAttachmentConfigurations(
255253
containerId: String,
256-
builtinNetworkId: String,
254+
builtinNetworkId: String?,
257255
networks: [Parser.ParsedNetwork]
258256
) throws -> [AttachmentConfiguration] {
259257
// Validate MAC addresses if provided
@@ -303,7 +301,11 @@ public struct Utility {
303301
)
304302
}
305303
}
304+
306305
// if no networks specified, attach to the default network
306+
guard let builtinNetworkId else {
307+
throw ContainerizationError(.invalidState, message: "builtin network is not present")
308+
}
307309
return [AttachmentConfiguration(network: builtinNetworkId, options: AttachmentOptions(hostname: fqdn ?? containerId, macAddress: nil))]
308310
}
309311

0 commit comments

Comments
 (0)