Repository navigation
feat(catalog): catalog, generator, and seed definitions - #158
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughTyped Go constructors now define built-in Karta resources for Kubernetes workloads. A catalog indexes and serializes them into ChangesTyped Karta catalog
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (18)
Makefiledocs/catalog/apps-deployment-v1.yamldocs/catalog/apps-statefulset-v1.yamldocs/catalog/batch-cronjob-v1.yamldocs/catalog/batch-job-v1.yamldocs/catalog/core-pod-v1.yamldocs/samples/batch-job.yamldocs/samples/statefulset.yamlhack/gen-samples/main.gopkg/catalog/catalog.gopkg/catalog/catalog_completeness_test.gopkg/catalog/catalog_test.gopkg/catalog/kartas/batch_job.gopkg/catalog/kartas/cronjob.gopkg/catalog/kartas/deployment.gopkg/catalog/kartas/kartas.gopkg/catalog/kartas/pod.gopkg/catalog/kartas/statefulset.go
💤 Files with no reviewable changes (2)
- docs/samples/batch-job.yaml
- docs/samples/statefulset.yaml
10da6b8 to
68dbf08
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (19)
Makefiledocs/catalog/apps-deployment-v1.yamldocs/catalog/apps-statefulset-v1.yamldocs/catalog/batch-cronjob-v1.yamldocs/catalog/batch-job-v1.yamldocs/catalog/core-pod-v1.yamldocs/design/builtin-catalog/detailed-design.mddocs/samples/batch-job.yamldocs/samples/statefulset.yamlhack/gen-samples/main.gopkg/catalog/catalog.gopkg/catalog/catalog_completeness_test.gopkg/catalog/catalog_test.gopkg/catalog/kartas/batch_job.gopkg/catalog/kartas/cronjob.gopkg/catalog/kartas/deployment.gopkg/catalog/kartas/kartas.gopkg/catalog/kartas/pod.gopkg/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
68dbf08 to
f5394c3
Compare
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>
f5394c3 to
242d18a
Compare
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>
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
left a comment
There was a problem hiding this comment.
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)
| 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) |
There was a problem hiding this comment.
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>
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>
What does this PR do?
Introduces the
pkg/catalogpackage: an immutable, in-process catalog of built-inKarta definitions indexed by their root-component GVK, with
Get/Listresolvers andno runtime registration. Typed Go is the single source of truth (
pkg/catalog/kartas/),and a generator (
hack/gen-samples) renders the definitions to YAML underdocs/catalog/.A
generate-samplestarget is folded intomake validateso drift between the Go sourceand 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 portthe remaining workloads.
Tests cover structural validity, catalog semantics (
Gethit/miss,Listdeterminism,duplicate-GVK panic), round-trip YAML equality against
docs/catalog/, and ago/astcompleteness check that every constructor is wired into the catalog.
Related issue(s)
Part of #86. Relates to #118.
Checklist
git commit -s)make check)Summary by CodeRabbit
status.