Files
jshi991andJohn Logan b3357fdb2e Split K8sHelper, add WorkerProvisioner protocol, and add LinuxWorker … (#2110)
- Closes #2102.
- LinuxWorkerProvisioner sets up a kind-based node.
- Includes some test cleanups.

Co-authored-by: John Logan <john_logan@apple.com>
2026-08-18 13:12:06 -07:00

55 lines
2.2 KiB
Swift

//===----------------------------------------------------------------------===//
// Copyright © 2026 Apple Inc. and the container project authors.
//
// 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 ContainerAPIClient
import ContainerPersistence
import ContainerizationError
import ContainerizationOCI
import Logging
extension K8sHelper {
// MARK: - Image management
public static func ensureImage(nodeImage: String = K8sHelper.nodeImage, log: Logger, containerSystemConfig: ContainerSystemConfig) async throws {
do {
_ = try await ClientImage.get(reference: nodeImage, containerSystemConfig: containerSystemConfig)
log.debug("k8s node image present", metadata: ["ref": "\(nodeImage)"])
return
} catch let error as ContainerizationError where error.code == .notFound {
log.info("Pulling k8s node image", metadata: ["ref": "\(nodeImage)"])
}
let platform = try Platform(from: "linux/\(Arch.hostArchitecture().rawValue)")
_ = try await ClientImage.fetch(
reference: nodeImage,
platform: platform,
containerSystemConfig: containerSystemConfig,
progressUpdate: nil)
}
// MARK: - Image reference helpers
static func isShortName(_ reference: String) -> Bool {
guard let ref = try? Reference.parse(reference) else { return true }
return ref.domain == nil
}
static func fqReference(_ reference: String) -> String {
guard let ref = try? Reference.parse(reference) else { return reference }
ref.normalize()
return ref.description
}
}