Skip to content

feat(builtin): make Go structs the source of truth for sample Karta definitions #118

Description

@yuval-gr

Sub-issue of #86.

Background

Karta ships a dozen sample definitions under docs/samples/ as hand-written YAML (jobset.yaml, pytorch.yaml, raycluster.yaml, etc.). Hand-written YAML has no compile-time checking: a typo in a field path, a wrong GVK, or drift from the Karta API type is only caught at runtime, if at all. In addition, we plan to provide the our kartas that are verified as part of karta library (see #86) - having them as go struct would make it much cleaner

Proposal

Make typed Go definitions the single source of truth for the built-in samples, and generate the YAML from them.

  1. New pkg/builtin/ package holding each sample as a typed *v1alpha1.Karta value, one file per workload (e.g. pkg/builtin/jobset.go, pkg/builtin/pytorch.go). The jq-expression notes currently embedded in the YAML move into Go comments. The same package indexes the definitions by workload identity and exposes the resolver API (Get / Add / List), with no go:embed.
  2. A generator (make generate-builtins) that marshals every definition in pkg/builtin/ to YAML and writes it to docs/builtin/, preserving the existing filename convention {group-slug}-{kind-lowercase}-{version}.yaml.
  3. A CI check that runs the generator and fails on any diff, so docs/builtin/ can never drift from pkg/builtin/. This mirrors the existing make validate pattern (git diff --exit-code).
  4. Suggested name in code: "catalog", in description: "Built-in catalog"

Scope

  • Add pkg/builtin/ with typed definitions equivalent to the current 13 YAML files.
  • Add the resolver API (Get / Add / List) in the same package.
  • Add a generator (cmd/gen-samples or under hack/) invoked by a new generate-samples Make target.
  • Wire generate-samples into the validate target so git diff --exit-code covers it. CI already runs make checkvalidate; add an explicit CI step only if clearer.
  • Convert all existing samples; the hand-written YAML becomes generated output.
  • Tests verify each definition is structurally valid and round-trips to the committed YAML.

Acceptance criteria

  • make generate-samples regenerates docs/builtin/ from pkg/builtin/.
  • CI fails when pkg/builtin/ and docs/samples/ are out of sync.
  • All 13 existing samples are represented as Go structs with passing tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions