Skip to content

Commit ade3302

Browse files
committed
refactor: extract K8s logic into ContainerK8s library target
Move all K8s sources from the container-k8s executable into a new ContainerK8s library target. Sources/Plugins/K8s/ becomes a thin entry point (K8sMain.swift) that calls K8sCommand.main(). Also make iptables MSS clamping non-fatal: if xt_TCPMSS is unavailable in the VM kernel the node prep no longer aborts; a warning is logged instead.
1 parent 0d111be commit ade3302

14 files changed

Lines changed: 46 additions & 12 deletions

Package.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ let package = Package(
5252
.library(name: "TerminalProgress", targets: ["TerminalProgress"]),
5353
.library(name: "MachineAPIClient", targets: ["MachineAPIClient"]),
5454
.library(name: "MachineAPIService", targets: ["MachineAPIService"]),
55+
.library(name: "ContainerK8s", targets: ["ContainerK8s"]),
5556
],
5657
dependencies: [
5758
.package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion)),
@@ -167,19 +168,21 @@ let package = Package(
167168
.testTarget(
168169
name: "K8sTests",
169170
dependencies: [
170-
"k8s",
171+
"ContainerK8s",
171172
"ContainerResource",
172173
"Yams",
173174
],
174175
path: "Tests/K8sPluginTests"
175176
),
176-
.executableTarget(
177-
name: "k8s",
177+
.target(
178+
name: "ContainerK8s",
178179
dependencies: [
179180
.product(name: "ArgumentParser", package: "swift-argument-parser"),
180181
.product(name: "Logging", package: "swift-log"),
181182
.product(name: "Containerization", package: "containerization"),
182183
.product(name: "ContainerizationOCI", package: "containerization"),
184+
.product(name: "ContainerizationOS", package: "containerization"),
185+
.product(name: "SystemPackage", package: "swift-system"),
183186
"ContainerAPIClient",
184187
"ContainerLog",
185188
"ContainerPersistence",
@@ -188,10 +191,14 @@ let package = Package(
188191
"TerminalProgress",
189192
"Yams",
190193
],
191-
path: "Sources/Plugins/K8s",
192-
exclude: ["config.toml"],
193194
resources: [.process("Resources/kindnet.yaml")]
194195
),
196+
.executableTarget(
197+
name: "k8s",
198+
dependencies: ["ContainerK8s"],
199+
path: "Sources/Plugins/K8s",
200+
exclude: ["config.toml"]
201+
),
195202
.executableTarget(
196203
name: "container-apiserver",
197204
dependencies: [

Sources/Plugins/K8s/K8sCommand.swift renamed to Sources/ContainerK8s/Commands/K8sCommand.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
import ArgumentParser
1818
import ContainerVersion
1919

20-
@main
21-
struct K8sCommand: AsyncParsableCommand {
22-
static let configuration = CommandConfiguration(
20+
public struct K8sCommand: AsyncParsableCommand {
21+
public static let configuration = CommandConfiguration(
2322
commandName: "k8s",
2423
abstract: "Manage local Kubernetes development clusters (EXPERIMENTAL)",
2524
discussion: """
@@ -56,4 +55,6 @@ struct K8sCommand: AsyncParsableCommand {
5655
K8sWriteConfig.self,
5756
]
5857
)
58+
59+
public init() {}
5960
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ struct K8sHelper {
216216
guard result.code == 0 else {
217217
throw ContainerizationError(.internalError, message: "node prep failed on \(nodeID): \(result.output)")
218218
}
219+
if result.output.contains("mss-clamp-failed") {
220+
log.warning("MSS clamping unavailable — large pod-to-pod transfers may be affected", metadata: ["node": "\(nodeID)"])
221+
}
219222
}
220223

221224
static func bootstrapControlPlane(
@@ -291,8 +294,8 @@ struct K8sHelper {
291294
sysctl -w net.bridge.bridge-nf-call-ip6tables=1 2>/dev/null || true
292295
systemctl restart containerd
293296
ctr -n k8s.io images tag registry.k8s.io/pause:3.10 registry.k8s.io/pause:3.10.1 2>/dev/null || true
294-
iptables -t mangle -A OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1220
295-
iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1220
297+
iptables -t mangle -A OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1220 2>/dev/null || echo "warning: mss-clamp-failed"
298+
iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1220 2>/dev/null || echo "warning: mss-clamp-failed"
296299
"""
297300
}()
298301

0 commit comments

Comments
 (0)