Skip to content

feat: Add --update-schema-for CLI option for single resource updates#2642

Open
rnetser wants to merge 3 commits intomainfrom
LlamaStackDistribution-new
Open

feat: Add --update-schema-for CLI option for single resource updates#2642
rnetser wants to merge 3 commits intomainfrom
LlamaStackDistribution-new

Conversation

@rnetser
Copy link
Collaborator

@rnetser rnetser commented Feb 2, 2026

This PR introduces the --update-schema-for CLI option, which allows updating the schema for a specific resource kind without affecting other resources in the mapping. This is particularly useful when:

  • You're connected to an older cluster but need to update a specific CRD (e.g., a newly installed operator's resources like LlamaStackDistribution)
  • A new operator was installed and you only need its resource schema
  • You want to refresh just one resource without performing a full schema update
Short description:
More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
Bug:

Summary by CodeRabbit

  • New Features

    • New CLI option to selectively update the schema for a single resource independently of full updates.
  • Documentation

    • Expanded README with onboarding, setup steps, and explicit full and single-resource schema update workflows and examples.
  • Bug Fixes

    • Improved error handling and clearer messaging when requested resources or API schema paths are not found.
  • Tests

    • Added comprehensive tests for single-resource schema updates, mutual-exclusivity rules, and related error scenarios.

Add new CLI option to update schema for individual resources without
reprocessing all schema data. Includes:

- README documentation for --update-schema-for option with examples
- Refactored duplicate code into helper functions:
  - _fetch_openapi_v3_index: Fetches OpenAPI v3 paths index
  - _build_schema_data: Constructs schema data structure from API spec
  - _merge_schema_into_mapping: Merges schema into resource mapping
- Improved code maintainability and reduced duplication
@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

Walkthrough

Adds a single-resource schema update flow via a new --update-schema-for CLI option; implements update_single_resource_schema and supporting helpers, centralizes ResourceNotFoundError, updates README, and adds tests validating the new behaviors.

Changes

Cohort / File(s) Summary
Documentation
class_generator/README.md
Expanded onboarding/update guide: explicit Dependencies, Setup, full and single-resource schema update workflows, examples, and clarifications about schema behavior.
CLI Feature
class_generator/cli.py, class_generator/tests/test_cli.py
Added --update-schema-for option and cloup constraints (mutual exclusion with --update-schema, disallow combining with kind flags); added handle_single_schema_update() and wiring through main/validate_actions; tests for success, mutual-exclusivity, invalid combinations, and ResourceNotFoundError handling.
Core Schema Logic
class_generator/core/schema.py
Added helpers _build_schema_data() and _merge_schema_into_mapping(); refactored schema processing to use them; added _fetch_openapi_v3_index() and update_single_resource_schema(kind, client=None) with API path resolution, merging, persistence, cache invalidation, and error handling.
Exceptions & Parsers
class_generator/exceptions.py, class_generator/parsers/explain_parser.py
Introduced centralized ResourceNotFoundError in exceptions.py; removed local definition from explain_parser.py and imported the new exception.
Tests — Schema
class_generator/tests/test_schema_new_functions.py
Comprehensive tests for update_single_resource_schema() covering add/update flows, missing kinds, OpenAPI index failures, absent schema definitions, and mapping persistence.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description explains the feature's purpose and use cases, but required template sections (short description, more details, issues, special notes) remain as unfilled placeholders. Complete the template sections with concise details: short description, comprehensive explanation, related issues, and any reviewer notes.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: introducing a new CLI option for single resource schema updates.
Docstring Coverage ✅ Passed Docstring coverage is 96.55% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch LlamaStackDistribution-new

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@redhat-qe-bot1
Copy link

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: Disabled for this repository
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: All label categories are enabled (default configuration)

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest python-module-install - Test Python package installation
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 0 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No WIP, hold, conflict labels
  5. Verified: PR must be marked as verified (if verification is enabled)

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@rnetser
Copy link
Collaborator Author

rnetser commented Feb 2, 2026

/verified

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@class_generator/tests/test_cli.py`:
- Around line 258-299: The test sets mock_update.side_effect to
ResourceNotFoundError but passes the message as the first positional arg (making
it the kind); change the instantiation to pass the kind keyword so the error is
constructed correctly, e.g. use ResourceNotFoundError(kind="FakeResource") in
test_update_schema_for_resource_not_found where mock_update and
update_single_resource_schema are patched.

In `@class_generator/tests/test_schema_new_functions.py`:
- Around line 1401-1419: The test function
test_update_single_resource_schema_new_resource currently accepts a mocked
SchemaValidator parameter named mock_schema_validator which is unused and
causing lint errors; rename that parameter to _mock_schema_validator to keep the
patch while silencing Ruff. Apply the same change to the other test function(s)
in this file that patch SchemaValidator (the block referenced around the later
test), renaming any unused mock_schema_validator parameters to
_mock_schema_validator so the patches remain but the names signal they are
intentionally unused.

- Fix ResourceNotFoundError instantiation to use kind keyword argument
- Rename unused mock parameters to follow Python conventions (_mock_*)
@rnetser
Copy link
Collaborator Author

rnetser commented Feb 2, 2026

/verified

@rnetser
Copy link
Collaborator Author

rnetser commented Feb 3, 2026

/verified

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.

5 participants