Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 2.75 KB

File metadata and controls

51 lines (35 loc) · 2.75 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

SwiftkubeModel is a zero-dependency Swift package providing Codable, Hashable, Sendable model structs for all Kubernetes API objects. Currently tracks Kubernetes v1.33.3.

Build & Test Commands

swift build              # Build the package
swift test               # Run all tests
swift test --filter SwiftkubeModelTests.GroupVersionKindTests  # Run a single test class
swift format -i Sources/ Tests/  # Format code

Architecture

Code Generation

Most files under Sources/Model/ are generated by an external tool called Swiftkube:ModelGen (not in this repo). Generated files have this header comment:

// Generated by Swiftkube:ModelGen
// Kubernetes v1.33.3

Do not manually edit generated files unless you understand they will be overwritten on the next generation run.

Source Layout

  • 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).

  • Sources/Model/ (top-level files) — Core infrastructure:

    • KubernetesResource.swift — Protocol hierarchy: KubernetesResourceMetadataHavingResourceKubernetesAPIResource, plus capability marker protocols (NamespacedResource, ClusterScopedResource, ReadableResource, ListableResource, CreatableResource, DeletableResource, etc.)
    • GroupVersionKind.swift / GroupVersionResource.swift — GVK/GVR types and their lookup tables (+DefaultResources, +KubernetesAPIResource, +Meta, +ResourceName)
    • UnstructuredResource.swift — Type-erased resource for unknown/CRD types
    • IntOrString.swift, Quantity.swift, JSONObject.swift — Special Kubernetes types
  • Sources/Builders/ — Closure-based builder functions under the sk namespace enum. Only covers common types (core/v1, apps/v1, meta/v1).

  • Sources/Codable/ — Custom encoding/decoding support (Any+Codable.swift, NullWrapper.swift).

  • Sources/Extensions/ — Convenience extensions on model types and Hashes.swift for Hashable conformance.

Key Patterns

  • All resources are Codable, Hashable, and Sendable structs.
  • API resources use var properties (not let) for mutability.
  • apiVersion and kind are let constants with default values on each API resource struct.
  • Resources with JSONObject fields (dictionary-backed) store values as Dictionary<String, any Sendable>.
  • The sk enum provides builder functions that use inout closure patterns via the internal build(_:with:) helper.