Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.4"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
.package(url: "https://github.com/grpc/grpc-swift-2.git", from: "2.3.0"),
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "2.4.4"),
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", from: "2.9.0"),
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", from: "2.2.0"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.36.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.80.0"),
Expand Down
90 changes: 0 additions & 90 deletions Sources/Containerization/HTTP2ConnectBufferingHandler.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/Containerization/VZVirtualMachineInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension VZVirtualMachineInstance: VirtualMachineInstance {

try await self.vm.start(queue: self.queue)

let agent = try Vminitd(
let agent = try await Vminitd(
connection: try await self.vm.waitForAgent(queue: self.queue),
group: self.group
)
Expand Down Expand Up @@ -260,7 +260,7 @@ extension VZVirtualMachineInstance: VirtualMachineInstance {
port: Vminitd.port
)
let handle = try conn.dupHandle()
return try Vminitd(connection: handle, group: self.group)
return try await Vminitd(connection: handle, group: self.group)
} catch {
if let err = error as? ContainerizationError {
throw err
Expand Down
33 changes: 19 additions & 14 deletions Sources/Containerization/Vminitd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import ContainerizationOCI
import ContainerizationOS
import Foundation
import GRPCCore
import GRPCNIOTransportCore
import NIOCore
import NIOPosix
import GRPCNIOTransportHTTP2
import NIO

/// A remote connection into the vminitd Linux guest agent via a port (vsock).
/// Used to modify the runtime environment of the Linux sandbox.
Expand All @@ -34,18 +33,24 @@ public struct Vminitd: Sendable {
public let grpcClient: GRPCClient<HTTP2ClientTransport.WrappedChannel>
private let connectionTask: Task<Void, Error>

public init(connection: FileHandle, group: any EventLoopGroup) throws {
let channel = try ClientBootstrap(group: group)
.channelInitializer { channel in
channel.eventLoop.makeCompletedFuture(withResultOf: {
try channel.pipeline.syncOperations.addHandler(HTTP2ConnectBufferingHandler())
})
public init(connection: FileHandle, group: any EventLoopGroup) async throws {
let transport = try await HTTP2ClientTransport.WrappedChannel.wrapping(
config: .defaults { $0.connection.maxIdleTime = nil },
serviceConfig: .init()
) { configure in
try await withCheckedThrowingContinuation { continuation in
ClientBootstrap(group: group)
.channelInitializer { channel in
configure(channel).map { configured in
continuation.resume(returning: configured)
}
}
.withConnectedSocket(connection.fileDescriptor)
.whenFailure { error in
continuation.resume(throwing: error)
}
}
.withConnectedSocket(connection.fileDescriptor).wait()
let transport = HTTP2ClientTransport.WrappedChannel.wrapping(
channel: channel,
config: .defaults { $0.connection.maxIdleTime = nil }
)
}
let grpcClient = GRPCClient(transport: transport)
self.grpcClient = grpcClient
self.client = Com_Apple_Containerization_Sandbox_V3_SandboxContext.Client(wrapping: self.grpcClient)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Integration/ContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ extension IntegrationSuite {
try await assertExec(container, id: "create-fifo", cmd: "mkfifo /tmp/test-fifo")

let vsock = try await container.dialVsock(port: 1024)
let vminitd = try Vminitd(connection: vsock, group: Self.eventLoop)
let vminitd = try await Vminitd(connection: vsock, group: Self.eventLoop)

let root = URL(filePath: container.root)

Expand Down
14 changes: 7 additions & 7 deletions vminitd/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading