Skip to content

feat(catalog): catalog, generator, and seed definitions - #158

Merged
rogirun merged 7 commits into
mainfrom
catalog/pr1-foundation
Jul 22, 2026
Merged

rogirun merged 7 commits into
mainfrom
catalog/pr1-foundation

Conversation

@rogirun

@rogirun rogirun commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Introduces the pkg/catalog package: an immutable, in-process catalog of built-in
Karta definitions indexed by their root-component GVK, with Get/List resolvers and
no runtime registration. Typed Go is the single source of truth (pkg/catalog/kartas/),
and a generator (hack/gen-samples) renders the definitions to YAML under docs/catalog/.
A generate-samples target is folded into make validate so drift between the Go source
and the generated YAML fails CI.

This is the foundation PR of the built-in catalog effort (first of a stacked series). It
seeds the catalog with the five basic Kubernetes workloads (Job, CronJob, Deployment,
StatefulSet, Pod) and removes their hand-written copies from docs/samples. Later PRs port
the remaining workloads.

Tests cover structural validity, catalog semantics (Get hit/miss, List determinism,
duplicate-GVK panic), round-trip YAML equality against docs/catalog/, and a go/ast
completeness check that every constructor is wired into the catalog.

Related issue(s)

Part of #86. Relates to #118.

Checklist

  • All commits are signed off with DCO (git commit -s)
  • New/modified files have SPDX license and copyright headers
  • Documentation updated (if applicable)
  • Tests pass (make check)
  • No proprietary or internal information included

Summary by CodeRabbit

  • New Features
    • Added built-in Karta catalog entries for Pods, Deployments, StatefulSets, Jobs, and CronJobs.
    • Introduced a deterministic catalog that generates stable, SPDX header–prefixed YAML manifests.
  • Documentation
    • Updated the built-in catalog documentation to reflect deep-copy behavior for returned entries.
    • Regenerated catalog manifests with consistent formatting, optimization instructions, and an explicit top-level status.
    • Removed outdated standalone sample YAMLs in favor of the regenerated catalog.
  • Validation
    • Added automated checks for catalog completeness, determinism, YAML stability, and schema validity.
  • Chores
    • Added a generation step that runs during validation to keep generated manifests in sync.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Typed Go constructors now define built-in Karta resources for Kubernetes workloads. A catalog indexes and serializes them into docs/catalog, with generation integrated into make validate. Tests verify wiring, lookup, copying, ordering, YAML stability, and schema validity.

Changes

Typed Karta catalog

Layer / File(s) Summary
Workload definitions
pkg/catalog/kartas/*
Adds typed Karta definitions for Pods, Deployments, StatefulSets, CronJobs, and Jobs, including scaling, status, ownership, suspension, and gang-scheduling configuration.
Catalog indexing and serialization
pkg/catalog/catalog.go, docs/design/builtin-catalog/detailed-design.md
Adds GVK-based lookup, deterministic listing, defensive copies, slug generation, YAML marshaling, and duplicate-definition checks; documents the deep-copy contract.
YAML generation and manifests
hack/gen-samples/main.go, Makefile, docs/catalog/*
Generates catalog YAML from typed definitions, removes stale manifests, and includes generation in validation.
Catalog validation
pkg/catalog/catalog_test.go, pkg/catalog/catalog_completeness_test.go
Tests constructor completeness, lookup and copy behavior, deterministic listing, duplicate detection, YAML round trips, and Karta validity.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • run-ai/karta issue 118 — Adds typed Go Karta definitions as the source for generated catalog YAML and validation.
  • run-ai/karta issue 86 — Implements the built-in typed catalog, YAML generation, and validation integration.

Possibly related PRs

  • run-ai/karta#143 — Updates the catalog design documentation and deep-copy contract touched by this implementation.

Suggested reviewers: ronlv10, aviadhayumi

Poem

I hop through typed definitions bright,
And stamp each Karta just right.
YAML blooms in orderly rows,
Tests guard what the catalog knows.
Carrots cheer the build tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main changes: catalog package, sample generator, and seeded definitions.
Docstring Coverage ✅ Passed Docstring coverage is 92.59% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch catalog/pr1-foundation

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/catalog/batch-job-v1.yaml`:
- Line 6: The BatchJob constructor currently emits the inconsistent name
batch-v1-job; update kartas.BatchJob() to set Name to batch-job-v1, then
regenerate the catalog samples with make generate-samples so the YAML and
generated artifacts match.

In `@pkg/catalog/catalog_completeness_test.go`:
- Around line 58-66: Replace parser.ParseDir in the catalog completeness test
with os.ReadDir over kartasDir, then parse each non-test Go file individually
using parser.ParseFile and retain the existing error handling and package
collection behavior. Remove the now-unneeded ParseDir-specific usage while
preserving the single-directory scan.

In `@pkg/catalog/catalog.go`:
- Around line 83-89: Update the error message returned by key when root.Kind is
nil so its text starts with a lowercase word, while preserving the existing
context and error condition.
- Around line 92-108: Update Catalog.Get and Catalog.List to return deep-copied
Karta objects rather than pointers to the stored entries. Preserve Get’s
not-found error behavior and List’s GVK ordering, while ensuring each returned
entry is independently mutable without affecting the catalog’s backing data.

In `@pkg/catalog/kartas/batch_job.go`:
- Line 17: Update the ObjectMeta.Name in the Job Karta definition to use the
catalog slug identity “batch-job-v1” instead of “batch-v1-job”, keeping the
metadata name consistent with Slug and the generated manifest.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: dfb7048d-5b2d-485b-ac69-dba901b40621

📥 Commits

Reviewing files that changed from the base of the PR and between adf0c53 and 4cd6a66.

📒 Files selected for processing (18)
  • Makefile
  • docs/catalog/apps-deployment-v1.yaml
  • docs/catalog/apps-statefulset-v1.yaml
  • docs/catalog/batch-cronjob-v1.yaml
  • docs/catalog/batch-job-v1.yaml
  • docs/catalog/core-pod-v1.yaml
  • docs/samples/batch-job.yaml
  • docs/samples/statefulset.yaml
  • hack/gen-samples/main.go
  • pkg/catalog/catalog.go
  • pkg/catalog/catalog_completeness_test.go
  • pkg/catalog/catalog_test.go
  • pkg/catalog/kartas/batch_job.go
  • pkg/catalog/kartas/cronjob.go
  • pkg/catalog/kartas/deployment.go
  • pkg/catalog/kartas/kartas.go
  • pkg/catalog/kartas/pod.go
  • pkg/catalog/kartas/statefulset.go
💤 Files with no reviewable changes (2)
  • docs/samples/batch-job.yaml
  • docs/samples/statefulset.yaml

Comment thread docs/catalog/batch-job-v1.yaml Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/kartas/batch_job.go Resolved
@rogirun
rogirun force-pushed the catalog/pr1-foundation branch 4 times, most recently from 10da6b8 to 68dbf08 Compare July 19, 2026 09:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/catalog/catalog.go`:
- Around line 83-89: Update key to reject root.Kind values with empty Version or
Kind, returning the existing missing-kind error pattern before constructing the
schema.GroupVersionKind. Continue allowing an empty Group for core workloads,
while preserving valid GVK indexing behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 92e93d80-3b69-4ca9-be62-ef5197ac1c20

📥 Commits

Reviewing files that changed from the base of the PR and between 10da6b8 and 68dbf08.

📒 Files selected for processing (19)
  • Makefile
  • docs/catalog/apps-deployment-v1.yaml
  • docs/catalog/apps-statefulset-v1.yaml
  • docs/catalog/batch-cronjob-v1.yaml
  • docs/catalog/batch-job-v1.yaml
  • docs/catalog/core-pod-v1.yaml
  • docs/design/builtin-catalog/detailed-design.md
  • docs/samples/batch-job.yaml
  • docs/samples/statefulset.yaml
  • hack/gen-samples/main.go
  • pkg/catalog/catalog.go
  • pkg/catalog/catalog_completeness_test.go
  • pkg/catalog/catalog_test.go
  • pkg/catalog/kartas/batch_job.go
  • pkg/catalog/kartas/cronjob.go
  • pkg/catalog/kartas/deployment.go
  • pkg/catalog/kartas/kartas.go
  • pkg/catalog/kartas/pod.go
  • pkg/catalog/kartas/statefulset.go
💤 Files with no reviewable changes (2)
  • docs/samples/batch-job.yaml
  • docs/samples/statefulset.yaml
🚧 Files skipped from review as they are similar to previous changes (14)
  • pkg/catalog/kartas/statefulset.go
  • pkg/catalog/kartas/cronjob.go
  • pkg/catalog/kartas/deployment.go
  • docs/catalog/batch-job-v1.yaml
  • Makefile
  • docs/catalog/apps-statefulset-v1.yaml
  • pkg/catalog/kartas/pod.go
  • hack/gen-samples/main.go
  • docs/catalog/apps-deployment-v1.yaml
  • docs/catalog/batch-cronjob-v1.yaml
  • pkg/catalog/catalog_completeness_test.go
  • pkg/catalog/kartas/batch_job.go
  • pkg/catalog/catalog_test.go
  • docs/catalog/core-pod-v1.yaml

Comment thread pkg/catalog/catalog.go Resolved
@rogirun
rogirun force-pushed the catalog/pr1-foundation branch from 68dbf08 to f5394c3 Compare July 19, 2026 09:19
Introduce the pkg/catalog catalog: an immutable set of built-in Karta
definitions indexed by their root component GVK, with Get/List resolvers
and no runtime registration. Add the hack/gen-samples generator that
renders the typed definitions to docs/catalog/ YAML, and fold a
generate-samples target into make validate so drift fails CI.

Seed the catalog with the five basic Kubernetes workloads (Job, CronJob,
Deployment, StatefulSet, Pod) and remove their hand-written copies from
docs/samples. Tests cover structural validity, catalog semantics,
round-trip YAML equality, and a go/ast completeness check that every
constructor is wired into the catalog.

Relates to #86 and #118.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Roee Gil <roeeg@nvidia.com>
@rogirun
rogirun force-pushed the catalog/pr1-foundation branch from f5394c3 to 242d18a Compare July 19, 2026 10:27
Comment thread Makefile Resolved
Comment thread docs/catalog/batch-job-v1.yaml Resolved
Comment thread docs/catalog/batch-job-v1.yaml Resolved
Comment thread docs/catalog/apps-deployment-v1.yaml Resolved
Comment thread docs/catalog/batch-job-v1.yaml Resolved
Unmarshal each docs/catalog/*.yaml and run the shared Karta validator so the
on-disk artifacts are checked directly, not just the Go definitions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Roee Gil <roee.gil@run.ai>
@rogirun
rogirun requested a review from yuval-gr July 20, 2026 09:55
Comment thread hack/gen-samples/main.go Resolved
Comment thread Makefile Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
rogirun and others added 2 commits July 21, 2026 09:40
Address review feedback: trim verbose doc comments, replace the key helper
with an exported RootKey GVK converter, build the samples output path via
filepath.Join, and make `make validate` fail on untracked generated files
via git status --porcelain.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Roee Gil <roee.gil@run.ai>
Drop the redundant sorted slice and build the sorted, deep-copied List from
the byGVK map on demand, keeping a single source of truth. Update the detailed
design to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Roee Gil <roee.gil@run.ai>

@Isan-Rivkin Isan-Rivkin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you the newer version looks much better!
Requesting changes due to unresolved comments:

  • use of panics
  • sentinel errors + error wrap
  • mistakenly resolved comment about comment (un-resolved)

Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Resolved
Comment thread pkg/catalog/catalog.go Outdated
root := k.Spec.StructureDefinition.RootComponent
// Group may be empty (core workloads such as Pod), but Version and Kind are required.
if root.Kind == nil || root.Kind.Version == "" || root.Kind.Kind == "" {
return schema.GroupVersionKind{}, fmt.Errorf("root component GVK incomplete for Karta %q", k.Name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? use error wrap... and re-use ErrInvalidGVK where (if) needed

In general: everywhere there's no err to uwnrap, use sentinel error + error wrap

var ErrInvalidGVK = errors.New("invalid gvk") 
return "", fmt.Errorf("missing version/kind %q: %w", k.Name, ErrInvalidGVK) 

Address review feedback: newCatalog now returns an error instead of panicking,
with New as the single panic at the init boundary, so the construction tests
assert on errors instead of recover. Introduce ErrInvalidGVK and wrap it at the
incomplete-GVK sites; switch ErrNotFound to errors.New for sentinel consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Roee Gil <roee.gil@run.ai>
@rogirun
rogirun requested a review from Isan-Rivkin July 22, 2026 07:10

@Isan-Rivkin Isan-Rivkin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not pushed

Avoid ST1005 (capitalized error string) by formatting as %w first, matching
the existing ErrNotFound wrap in Get.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Roee Gil <roee.gil@run.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants