Skip to content

feat(validator): apply hybrid resource pattern to ValidatorCatalog#831

Merged
mchmarny merged 6 commits into
NVIDIA:mainfrom
xdu31:feature/issue-733
May 12, 2026
Merged

feat(validator): apply hybrid resource pattern to ValidatorCatalog#831
mchmarny merged 6 commits into
NVIDIA:mainfrom
xdu31:feature/issue-733

Conversation

@xdu31

@xdu31 xdu31 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Moves ValidatorCatalog types from pkg/validator/catalog to pkg/api/validator/v1 and updates the API group to validator.nvidia.com/v1alpha1, consistent with the refactoring done for ValidationInput in #830.

Motivation/Context

Fixes #733
Related to #732 (ValidationInput refactoring)

Mark's review feedback requested:

  1. Move ValidatorCatalog to pkg/api/validator/v1 (same location as ValidationInput)
  2. Change API group from aicr.nvidia.com/v1 to validator.nvidia.com/v1alpha1
  3. Add JSON omitempty tags (only YAML tags were present)
  4. Relax validation for embedded usage (allow empty APIVersion/Kind when Metadata is nil)

Type of Change

  • Refactoring (non-breaking change which improves code organization)

Components Affected

  • pkg/api/validator/v1 - New location for ValidatorCatalog types
  • pkg/validator/catalog - Re-exports types for backward compatibility
  • recipes/validators/catalog.yaml - Updated API version

Implementation Notes

New Structure

  • Created pkg/api/validator/v1/catalog.go with all catalog types:
    • ValidatorCatalog
    • CatalogMetadata
    • ValidatorEntry
    • ResourceRequirements
    • EnvVar
  • Added both json and yaml omitempty tags to all optional fields
  • Moved ForPhase method to v1 package
  • Changed API version constant from aicr.nvidia.com/v1 to validator.nvidia.com/v1alpha1

Backward Compatibility

  • pkg/validator/catalog now re-exports types as aliases
  • All existing code continues to work without changes
  • Validation functions and image resolution remain in catalog package

Validation Updates

  • Updated validate() to allow embedded usage:
    • When Metadata is nil: APIVersion and Kind are optional (embedded usage)
    • When Metadata is present: APIVersion and Kind are required (standalone file)

Test Updates

  • Updated all test YAML strings to use new API version validator.nvidia.com/v1alpha1
  • Updated test expectations to use v1.CatalogAPIVersion and v1.CatalogKind constants

Testing

  • ✅ All catalog tests passing (97.6% coverage)
  • ✅ All validator tests passing
  • ✅ Full test suite: 75.3% coverage (above 70% threshold)
  • ✅ golangci-lint: 0 issues
  • ✅ make qualify: PASS

Risk Assessment

Low Risk

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code commented where needed
  • Documentation updated (godoc)
  • No new warnings generated
  • Tests updated for new API version
  • All tests passing locally
  • make qualify passed
  • License headers ensured

xdu31 added 2 commits May 9, 2026 09:01
Make ValidatorCatalog type support both standalone file usage and embedding
in Kubernetes CRs by adding omitempty tags to APIVersion/Kind/Metadata
fields and changing Metadata to pointer type.

Changes:
- Add omitempty tags to APIVersion and Kind fields
- Change Metadata from CatalogMetadata to *CatalogMetadata (pointer)
- Add omitempty tag to Metadata field
- Keep Validators as required field (no omitempty)
- Add nil check for Metadata in TestLoadEmbeddedCatalog
- Add TestCatalogOmitEmpty to verify clean serialization without metadata
- Add TestCatalogEmbedding to verify clean CR embedding
- Import gopkg.in/yaml.v3 for YAML marshaling in tests

This enables clean embedding without redundant metadata when used in CRs
while supporting standalone catalog.yaml files with full resource metadata.
@xdu31 xdu31 requested a review from a team as a code owner May 9, 2026 16:49
@coderabbitai

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@mchmarny mchmarny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mechanically the change is small and clean (omitempty tags + pointer Metadata + tests), and it mirrors the pattern from #830. Holding for the same shape-level concerns plus one use-case question:

  • (a) Public type belongs in a dedicated pkg/api/validator/v1 package, not co-located with the orchestration code in pkg/validator/catalog.
  • (b) apiVersion: aicr.nvidia.com/... implies a CRD group AICR doesn't ship — drop or explicitly scope as a non-binding example.
  • (d) Tag the package v1alpha1 with stability docs, not v1.
  • Confirm there's a real external consumer for the embed affordance before locking the pointer-Metadata change into the public API.

This PR and #830 set the public-API package shape together — recommend deciding both at once and re-landing as a single coherent Phase 1 change.

Unrelated nit: PR body has 🤖 Generated with [Claude Code] — repo policy in CLAUDE.md prohibits that attribution.

Comment thread pkg/validator/catalog/catalog.go Outdated
Comment thread pkg/validator/catalog/catalog.go Outdated
Comment thread pkg/validator/catalog/catalog.go Outdated
@xdu31 xdu31 requested a review from a team as a code owner May 12, 2026 07:11
coderabbitai[bot]

This comment was marked as resolved.

@xdu31 xdu31 force-pushed the feature/issue-733 branch from 0aef411 to c98e686 Compare May 12, 2026 07:25
@xdu31 xdu31 requested a review from mchmarny May 12, 2026 07:27
coderabbitai[bot]

This comment was marked as resolved.

@mchmarny mchmarny enabled auto-merge (squash) May 12, 2026 15:48
@mchmarny mchmarny merged commit 9f61446 into NVIDIA:main May 12, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract ValidatorCatalog as standalone portable type

2 participants