Skip to content

Conversation

@CWAbhi
Copy link

@CWAbhi CWAbhi commented Oct 24, 2025

Description

This PR fixes #731

Current Behaviour

Previously, the group field was treated as a regular property instead of a key identifier for associating custom resources with their API groups.

Enhancement

•Updated CRD parsing logic to recognize and use the group field.
•Implemented component-to-model mapping based on the API group value.
•Ensured compatibility with both native and custom Kubernetes resources.
•Improved maintainability by centralizing group-based mapping logic.

Testing

•Validated functionality with multiple CRDs, ensuring:
•Accurate mapping across different API groups.
•No regression in existing CRD handling.
•Successful parsing and model association for both standard and custom resources.

@welcome
Copy link

welcome bot commented Oct 24, 2025

Yay, your first pull request! 👍 A contributor will be by to give feedback soon. In the meantime, you can find updates in the #github-notifications channel in the community Slack.
Be sure to double-check that you have signed your commits. Here are instructions for making signing an implicit activity while performing a commit.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CWAbhi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the system's ability to process and categorize Kubernetes Custom Resource Definitions (CRDs) by correctly interpreting their API group information. The core change involves updating the CRD parsing logic to leverage the group field for generating more accurate and descriptive model names and display names for components. This improvement ensures that both standard and custom Kubernetes resources are consistently and correctly mapped, leading to better organization and representation within the system.

Highlights

  • CRD Group Field Recognition: The system now correctly recognizes and utilizes the group field within Custom Resource Definitions (CRDs) as a key identifier for associating custom resources with their respective API groups. Previously, this field was treated as a regular property.
  • Enhanced Component-to-Model Mapping: Implemented new logic to derive component model names and display names based on the API group value extracted from the CRD's apiVersion. This ensures more accurate and meaningful categorization of resources.
  • New Utility Functions: Introduced GroupToModel and ExtractGroupFromAPIVersion utility functions in utils/component/generator.go to centralize the logic for parsing API versions and generating appropriate model and display names.
  • Broader Compatibility: The changes ensure compatibility with both native and custom Kubernetes resources, improving the system's ability to handle a wider range of definitions consistently.
  • Improved Maintainability: Centralizing the group-based mapping logic enhances the overall maintainability of the codebase.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the model generation process by incorporating the group field from CRDs to improve the association of custom resources with their API groups. The changes include updates to CRD parsing logic, component-to-model mapping, and compatibility with both native and custom Kubernetes resources. The changes look good overall, and I have provided a few comments to address potential issues.

comp.Model.Name = pkg.Name

// Derive model from the CRD's API group when available; otherwise, fallback to package name
group := component.ExtractGroupFromAPIVersion(comp.Component.Version)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It would be beneficial to add a comment explaining the purpose of extracting the group from the API version here. This will improve the code's readability and maintainability.

comp.Model.Name = gp.Name

// Derive model from the CRD's API group when available; otherwise, fallback to package name
group := component.ExtractGroupFromAPIVersion(comp.Component.Version)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It would be beneficial to add a comment explaining the purpose of extracting the group from the API version here. This will improve the code's readability and maintainability.

Copy link
Contributor

@n2h9 n2h9 left a comment

Choose a reason for hiding this comment

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

Hey hey hello @CWAbhi

Thanks for your pr, left couple comments 😇 .

t.Fatalf("expected fallback model name 'fooBarBaz', got '%s'", name)
}
if display != "Foo Bar Baz" {
t.Fatalf("expected display name 'Foo Bar Baz', got '%s'", display)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this test is failing link

}
}

func TestGroupToModel_WithGroup(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We generally arrange tests which test the same functionality with different cases inside one test function, f.e. TestGroupModel, and test cases are called inside using t.Run, f.e. TestGenerate in the same generator_test.go file.

@CWAbhi
Copy link
Author

CWAbhi commented Oct 25, 2025

@n2h9 I will look into it

@CWAbhi
Copy link
Author

CWAbhi commented Oct 26, 2025

@n2h9 Please run the test

@CWAbhi CWAbhi requested a review from n2h9 October 26, 2025 06:13
@CWAbhi
Copy link
Author

CWAbhi commented Oct 26, 2025

@Darshan174 , @aabidsofi19 , @winkletinkle Can you guys review this???

@CWAbhi
Copy link
Author

CWAbhi commented Oct 27, 2025

@leecalcote everything looks good to me , what are your thoughts about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model Generation: Support mapping of group field in CRDs

2 participants