Skip to content

Commit 58201a9

Browse files
committed
refactor: extract K8s logic into ContainerK8s library target
1 parent 0d111be commit 58201a9

15 files changed

Lines changed: 49 additions & 17 deletions

File tree

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ struct K8sHelper {
291291
sysctl -w net.bridge.bridge-nf-call-ip6tables=1 2>/dev/null || true
292292
systemctl restart containerd
293293
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
294+
/usr/sbin/iptables-nft -t mangle -A OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1220 2>/dev/null || true
295+
/usr/sbin/iptables-nft -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1220 2>/dev/null || true
296296
"""
297297
}()
298298

@@ -538,7 +538,7 @@ struct K8sHelper {
538538
existing.clusters.append(contentsOf: config.clusters)
539539
existing.contexts.append(contentsOf: config.contexts)
540540
existing.users.append(contentsOf: config.users)
541-
if setCurrentContext && existing.currentContext == nil {
541+
if setCurrentContext {
542542
existing.currentContext = containerId
543543
}
544544

0 commit comments

Comments
 (0)