Skip to content

Commit 86378a7

Browse files
committed
Source code documentation updates
This change adds documentation to quite a few existing public types that didn't have a blurb before. Additionally, this fixes a couple things that I think either didn't make sense when going to document them: - Rename ConnectionStream to VsockConnectionStream. This type only functions for vsock connections. - Deletes NsLock+Closure. This was not used anywhere. - Rename ContainerizationOCI/Config.swift to ImageConfig.swift. Signed-off-by: Danny Canter <[email protected]>
1 parent 49276e8 commit 86378a7

32 files changed

+71
-49
lines changed

Sources/Containerization/DNSConfiguration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
/// DNS configuration for a container. The values will be used to
18+
/// construct /etc/resolv.conf for a given container.
1719
public struct DNS: Sendable {
1820
public static let defaultNameservers = ["1.1.1.1"]
1921

Sources/Containerization/Image/Image.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import SystemPackage
2626
import ContainerizationExtras
2727
#endif
2828

29+
/// Type representing an OCI container image.
2930
public struct Image: Sendable {
3031

3132
private let contentStore: ContentStore

Sources/Containerization/Image/InitImage.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import ContainerizationError
1818
import ContainerizationOCI
1919
import Foundation
2020

21+
/// Data representing the image to use as the root filesystem for a virtual machine.
22+
/// Typically this image would contain the guest agent used to facilitate container
23+
/// workloads, as well as any extras that may be useful to have in the guest.
2124
public struct InitImage: Sendable {
2225
public var name: String { image.reference }
2326

Sources/Containerization/Kernel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
import Foundation
1818

19-
/// A kernel used to boot a sandbox.
19+
/// An object representing a Linux kernel used to boot a virtual machine.
20+
/// In addition to a path to the kernel itself, this type stores relevant
21+
/// data such as the commandline to pass to the kernel, and init arguments.
2022
public struct Kernel: Sendable, Codable {
2123
/// The command line arguments passed to the kernel on boot.
2224
public struct CommandLine: Sendable, Codable {

Sources/Containerization/LinuxProcess.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public final class LinuxProcess: Sendable {
163163
}
164164

165165
extension LinuxProcess {
166-
func setupIO(streams: [ConnectionStream?]) async throws -> [FileHandle?] {
166+
func setupIO(streams: [VsockConnectionStream?]) async throws -> [FileHandle?] {
167167
let handles = try await Timeout.run(seconds: 3) {
168168
await withTaskGroup(of: (Int, FileHandle?).self) { group in
169169
var results = [FileHandle?](repeating: nil, count: 3)
@@ -231,7 +231,7 @@ extension LinuxProcess {
231231
public func start() async throws {
232232
let spec = self.state.withLock { $0.spec }
233233

234-
var streams = [ConnectionStream?](repeating: nil, count: 3)
234+
var streams = [VsockConnectionStream?](repeating: nil, count: 3)
235235
if let stdin = self.ioSetup.stdin {
236236
streams[0] = try self.vm.listen(stdin.port)
237237
}

Sources/Containerization/NATNetworkInterface.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import ContainerizationError
2222
import Foundation
2323
import Synchronization
2424

25+
/// An interface that uses NAT to provide an IP address for a given
26+
/// container/virtual machine.
2527
@available(macOS 16, *)
2628
public final class NATNetworkInterface: Interface, Sendable {
2729
public var address: String {

Sources/Containerization/SystemPlatform.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
import ContainerizationOCI
1818

19+
/// `SystemPlatform` describes an operating system and architecture pair.
20+
/// This is primarily used to choose what kind of OCI image to pull from a
21+
/// registry.
1922
public struct SystemPlatform: Sendable, Codable {
2023
public enum OS: String, CaseIterable, Sendable, Codable {
2124
case linux

Sources/Containerization/VZVirtualMachineInstance.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ extension VZVirtualMachineInstance {
184184
).dupHandle()
185185
}
186186

187-
func listen(_ port: UInt32) throws -> ConnectionStream {
188-
let stream = ConnectionStream(port: port)
187+
func listen(_ port: UInt32) throws -> VsockConnectionStream {
188+
let stream = VsockConnectionStream(port: port)
189189
let listener = VZVirtioSocketListener()
190190
listener.delegate = stream
191191

Sources/Containerization/VirtualMachineInstance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public protocol VirtualMachineInstance: Sendable {
3939
/// Dial a vsock port in the guest.
4040
func dial(_ port: UInt32) async throws -> FileHandle
4141
/// Listen on a host vsock port.
42-
func listen(_ port: UInt32) throws -> ConnectionStream
42+
func listen(_ port: UInt32) throws -> VsockConnectionStream
4343
/// Stop listening on a vsock port.
4444
func stopListen(_ port: UInt32) throws
4545
/// Start the virtual machine.

Sources/Containerization/ConnectionStream.swift renamed to Sources/Containerization/VsockConnectionStream.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import Foundation
2020
import Virtualization
2121
#endif
2222

23-
public final class ConnectionStream: NSObject, Sendable {
23+
/// A stream of vsock connections.
24+
public final class VsockConnectionStream: NSObject, Sendable {
2425
/// A stream of connections dialed from the remote.
2526
public let connections: AsyncStream<FileHandle>
27+
/// The port the connections are for.
28+
public let port: UInt32
2629

2730
private let cont: AsyncStream<FileHandle>.Continuation
28-
private let port: UInt32
2931

3032
public init(port: UInt32) {
3133
self.port = port
@@ -41,7 +43,7 @@ public final class ConnectionStream: NSObject, Sendable {
4143

4244
#if os(macOS)
4345

44-
extension ConnectionStream: VZVirtioSocketListenerDelegate {
46+
extension VsockConnectionStream: VZVirtioSocketListenerDelegate {
4547
public func listener(
4648
_: VZVirtioSocketListener, shouldAcceptNewConnection conn: VZVirtioSocketConnection,
4749
from _: VZVirtioSocketDevice

0 commit comments

Comments
 (0)