-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adds container network for macOS 26.
#243
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
Merged
katiewasnothere
merged 4 commits into
apple:main
from
jglogan:users/jglogan/container-network
Jun 27, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Copyright © 2025 Apple Inc. and the container project authors. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import ArgumentParser | ||
|
|
||
| extension Application { | ||
| struct NetworkCommand: AsyncParsableCommand { | ||
| static let configuration = CommandConfiguration( | ||
| commandName: "network", | ||
| abstract: "Manage container networks", | ||
| subcommands: [ | ||
| NetworkCreate.self, | ||
| NetworkDelete.self, | ||
| NetworkList.self, | ||
| NetworkInspect.self, | ||
| ], | ||
| aliases: ["n"] | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Copyright © 2025 Apple Inc. and the container project authors. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import ArgumentParser | ||
| import ContainerClient | ||
| import ContainerNetworkService | ||
| import ContainerizationError | ||
| import Foundation | ||
| import TerminalProgress | ||
|
|
||
| extension Application { | ||
| struct NetworkCreate: AsyncParsableCommand { | ||
| static let configuration = CommandConfiguration( | ||
| commandName: "create", | ||
| abstract: "Create a new network") | ||
|
|
||
| @Argument(help: "Network name") | ||
| var name: String | ||
|
|
||
| @OptionGroup | ||
| var global: Flags.Global | ||
|
|
||
| func run() async throws { | ||
| let config = NetworkConfiguration(id: self.name, mode: .nat) | ||
| let state = try await ClientNetwork.create(configuration: config) | ||
| print(state.id) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Copyright © 2025 Apple Inc. and the container project authors. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import ArgumentParser | ||
| import ContainerClient | ||
| import ContainerNetworkService | ||
| import ContainerizationError | ||
| import Foundation | ||
|
|
||
| extension Application { | ||
| struct NetworkDelete: AsyncParsableCommand { | ||
| static let configuration = CommandConfiguration( | ||
| commandName: "delete", | ||
| abstract: "Delete one or more networks", | ||
| aliases: ["rm"]) | ||
|
|
||
| @Flag(name: .shortAndLong, help: "Remove all networks") | ||
| var all = false | ||
|
|
||
| @OptionGroup | ||
| var global: Flags.Global | ||
|
|
||
| @Argument(help: "Network names") | ||
| var networkNames: [String] = [] | ||
|
|
||
| func validate() throws { | ||
| if networkNames.count == 0 && !all { | ||
| throw ContainerizationError(.invalidArgument, message: "no networks specified and --all not supplied") | ||
| } | ||
| if networkNames.count > 0 && all { | ||
| throw ContainerizationError( | ||
| .invalidArgument, | ||
| message: "explicitly supplied network name(s) conflict with the --all flag" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| mutating func run() async throws { | ||
| let uniqueNetworkNames = Set<String>(networkNames) | ||
| let networks: [NetworkState] | ||
|
|
||
| if all { | ||
| networks = try await ClientNetwork.list() | ||
| } else { | ||
| networks = try await ClientNetwork.list() | ||
| .filter { c in | ||
| uniqueNetworkNames.contains(c.id) | ||
| } | ||
|
|
||
| // If one of the networks requested isn't present lets throw. We don't need to do | ||
| // this for --all as --all should be perfectly usable with no networks to remove, | ||
| // otherwise it'd be quite clunky. | ||
| if networks.count != uniqueNetworkNames.count { | ||
| let missing = uniqueNetworkNames.filter { id in | ||
| !networks.contains { n in | ||
| n.id == id | ||
| } | ||
| } | ||
| throw ContainerizationError( | ||
| .notFound, | ||
| message: "failed to delete one or more networks: \(missing)" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| if uniqueNetworkNames.contains(ClientNetwork.defaultNetworkName) { | ||
| throw ContainerizationError( | ||
| .invalidArgument, | ||
| message: "cannot delete the default network" | ||
| ) | ||
| } | ||
|
|
||
| var failed = [String]() | ||
| try await withThrowingTaskGroup(of: NetworkState?.self) { group in | ||
| for network in networks { | ||
| group.addTask { | ||
| do { | ||
| // delete atomically disables the IP allocator, then deletes | ||
| // the allocator disable fails if any IPs are still in use | ||
| try await ClientNetwork.delete(id: network.id) | ||
| print(network.id) | ||
| return nil | ||
| } catch { | ||
| log.error("failed to delete network \(network.id): \(error)") | ||
| return network | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for try await network in group { | ||
| guard let network else { | ||
| continue | ||
| } | ||
| failed.append(network.id) | ||
| } | ||
| } | ||
|
|
||
| if failed.count > 0 { | ||
| throw ContainerizationError(.internalError, message: "delete failed for one or more networks: \(failed)") | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
NOTE: no changes...just reordered private functions to the end of the compilation unit