Skip to content

Commit b662053

Browse files
t089Tobias Haeberleclaude
authored
Adopt FoundationEssentials when available (#14)
* Use FoundationEssentials where available Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix Quantity parsing for FoundationEssentials compatibility Use explicit String(unit) conversion from Substring since FoundationEssentials doesn't implicitly convert Substring to String. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update to Kubernetes v1.34.6 Regenerated model files from K8s v1.34.6 OpenAPI spec. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update copyright to 2020-2026 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * update gitignore * remove unused file * revert changes to generated files * bump swift tools version to 5.7 and bump platform requirements * use #/.../# syntax for regex * add workaround for missing pow(Decimal, Int) in FoundationEssentials on 6.0 * formatting --------- Co-authored-by: Tobias Haeberle <tobias@fedora.fritz.box> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 42d5d87 commit b662053

30 files changed

Lines changed: 215 additions & 63 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.DS_Store
2+
/.claude/settings.local.json
3+
/.vscode
24
/.build
35
/Packages
46
/*.xcodeproj

CLAUDE.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
SwiftkubeModel is a zero-dependency Swift package providing Codable, Hashable, Sendable model structs for all Kubernetes API objects. Currently tracks Kubernetes v1.33.3.
8+
9+
## Build & Test Commands
10+
11+
```bash
12+
swift build # Build the package
13+
swift test # Run all tests
14+
swift test --filter SwiftkubeModelTests.GroupVersionKindTests # Run a single test class
15+
swift format -i Sources/ Tests/ # Format code
16+
```
17+
18+
## Architecture
19+
20+
### Code Generation
21+
22+
Most files under `Sources/Model/` are **generated** by an external tool called `Swiftkube:ModelGen` (not in this repo). Generated files have this header comment:
23+
```
24+
// Generated by Swiftkube:ModelGen
25+
// Kubernetes v1.33.3
26+
```
27+
Do not manually edit generated files unless you understand they will be overwritten on the next generation run.
28+
29+
### Source Layout
30+
31+
- **`Sources/Model/<group>/<version>/`** — Generated Kubernetes API structs, one file per type. Files follow the naming convention `TypeName+group.version.swift` (e.g., `Pod+core.v1.swift`). Each API group is a Swift namespace enum (e.g., `core.v1`, `apps.v1`, `networking.v1beta1`).
32+
33+
- **`Sources/Model/`** (top-level files) — Core infrastructure:
34+
- `KubernetesResource.swift` — Protocol hierarchy: `KubernetesResource``MetadataHavingResource``KubernetesAPIResource`, plus capability marker protocols (`NamespacedResource`, `ClusterScopedResource`, `ReadableResource`, `ListableResource`, `CreatableResource`, `DeletableResource`, etc.)
35+
- `GroupVersionKind.swift` / `GroupVersionResource.swift` — GVK/GVR types and their lookup tables (`+DefaultResources`, `+KubernetesAPIResource`, `+Meta`, `+ResourceName`)
36+
- `UnstructuredResource.swift` — Type-erased resource for unknown/CRD types
37+
- `IntOrString.swift`, `Quantity.swift`, `JSONObject.swift` — Special Kubernetes types
38+
39+
- **`Sources/Builders/`** — Closure-based builder functions under the `sk` namespace enum. Only covers common types (core/v1, apps/v1, meta/v1).
40+
41+
- **`Sources/Codable/`** — Custom encoding/decoding support (`Any+Codable.swift`, `NullWrapper.swift`).
42+
43+
- **`Sources/Extensions/`** — Convenience extensions on model types and `Hashes.swift` for Hashable conformance.
44+
45+
### Key Patterns
46+
47+
- All resources are `Codable`, `Hashable`, and `Sendable` structs.
48+
- API resources use `var` properties (not `let`) for mutability.
49+
- `apiVersion` and `kind` are `let` constants with default values on each API resource struct.
50+
- Resources with `JSONObject` fields (dictionary-backed) store values as `Dictionary<String, any Sendable>`.
51+
- The `sk` enum provides builder functions that use `inout` closure patterns via the internal `build(_:with:)` helper.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.7
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "SwiftkubeModel",
88
platforms: [
9-
.macOS(.v10_13), .iOS(.v12), .tvOS(.v12), .watchOS(.v5)
9+
.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9)
1010
],
1111
products: [
1212
.library(

Sources/Builders/Builders.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
import Foundation
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
20+
import Foundation
21+
#endif
1822

1923
// MARK: - sk
2024

Sources/Builders/apps/v1/appsV1+Deployment.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
import Foundation
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
20+
import Foundation
21+
#endif
1822

1923
public extension sk {
2024

Sources/Builders/core/v1/coreV1+ConfigMap.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
import Foundation
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
20+
import Foundation
21+
#endif
1822

1923
public extension sk {
2024

Sources/Builders/core/v1/coreV1+Container.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
import Foundation
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
20+
import Foundation
21+
#endif
1822

1923
public extension sk {
2024

Sources/Builders/core/v1/coreV1+Namespace.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
import Foundation
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
20+
import Foundation
21+
#endif
1822

1923
public extension sk {
2024

Sources/Builders/core/v1/coreV1+Node.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
import Foundation
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
20+
import Foundation
21+
#endif
1822

1923
public extension sk {
2024

Sources/Builders/core/v1/coreV1+ObjectReference.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
import Foundation
17+
#if canImport(FoundationEssentials)
18+
import FoundationEssentials
19+
#else
20+
import Foundation
21+
#endif
1822

1923
public extension sk {
2024

0 commit comments

Comments
 (0)