refactor(rbg): support customComponentsPatterns in v1alpha2 version#193
Conversation
Summary of ChangesHello, 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 refactors the API for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors the v1alpha2 API to introduce a CustomComponentsPattern, moving the Components field from RoleSpec into this new pattern structure. The changes are mostly correct, but there is a recurring typo (CustomComponentsPatten instead of CustomComponentsPattern) that originates in rolebasedgroup_types.go and propagates to other files. Additionally, the CRD validation is not updated to ensure mutual exclusivity for the new pattern, which could lead to undefined behavior. I've provided a comment to address both of these issues.
| // CustomComponentsPatten defines a pattern with custom components. | ||
| // +optional | ||
| CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"` |
There was a problem hiding this comment.
There's a typo in the field name, JSON tag, and comment for the new pattern. Patten should be Pattern. This should be corrected here at the source, and then all generated files should be updated accordingly.
Additionally, with the introduction of a new pattern, the CRD validation for RoleSpec should be updated to ensure that standalonePattern, leaderWorkerPattern, and the new customComponentsPattern are mutually exclusive. The current validation only covers the first two. Without this, a user could define multiple patterns, leading to ambiguous behavior where the reconciler just picks the first one it finds based on the switch statement order. Please add validation to enforce that only one pattern can be specified at a time.
| // CustomComponentsPatten defines a pattern with custom components. | |
| // +optional | |
| CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"` | |
| // CustomComponentsPattern defines a pattern with custom components. | |
| // +optional | |
| CustomComponentsPattern *CustomComponentsPattern `json:"customComponentsPattern,omitempty"` |
| // +optional | ||
| LeaderWorkerPattern *LeaderWorkerPattern `json:"leaderWorkerPattern,omitempty"` | ||
|
|
||
| // CustomComponentsPatten defines a pattern with custom components. |
There was a problem hiding this comment.
CustomComponentsPatten -》 CustomComponentsPattern
There was a problem hiding this comment.
Pull request overview
This PR refactors the customComponentsPattern support in the v1alpha2 API by moving the Components field from being a top-level field on RoleSpec into a new CustomComponentsPattern struct nested within the Pattern type, aligning it with how StandalonePattern and LeaderWorkerPattern are structured.
Changes:
- Introduced a new
CustomComponentsPatternstruct and movedComponentsfromRoleSpecinto it as a field withinPattern. - Updated the reconciler to use the new
GetCustomComponentsPattern()accessor and reordered the pattern matching switch cases. - Regenerated CRD schemas, deep copy functions, and client-go apply configurations to reflect the new structure.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| api/workloads/v1alpha2/rolebasedgroup_types.go | Removes Components from RoleSpec, adds CustomComponentsPattern struct and field to Pattern |
| api/workloads/v1alpha2/helper.go | Adds GetCustomComponentsPattern() accessor method |
| api/workloads/v1alpha2/zz_generated.deepcopy.go | Regenerated deep copy for new CustomComponentsPattern type and updated Pattern |
| config/crd/bases/workloads.x-k8s.io_rolebasedgroups.yaml | CRD schema updated to nest components under customComponentsPatten |
| config/crd/bases/workloads.x-k8s.io_rolebasedgroupsets.yaml | CRD schema updated to nest components under customComponentsPatten |
| client-go/applyconfiguration/workloads/v1alpha2/customcomponentspattern.go | New apply configuration type for CustomComponentsPattern |
| client-go/applyconfiguration/workloads/v1alpha2/pattern.go | Adds CustomComponentsPatten field and builder method |
| client-go/applyconfiguration/workloads/v1alpha2/rolespec.go | Replaces WithComponents with WithCustomComponentsPatten |
| client-go/applyconfiguration/utils.go | Registers CustomComponentsPattern kind |
| pkg/reconciler/roleinstanceset_reconciler.go | Updates reconciler to use new pattern accessor and renamed method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // CustomComponentsPatten defines a pattern with custom components. | ||
| // +optional | ||
| CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"` |
There was a problem hiding this comment.
Typo: The field name CustomComponentsPatten is missing an 'r' — it should be CustomComponentsPattern. Since this is serialized into the JSON tag ("customComponentsPatten") and will appear in the CRD schema, this typo will be baked into the public API and become a breaking change to fix later. The Go type is correctly named CustomComponentsPattern, making the inconsistency even more confusing. This should be fixed to CustomComponentsPattern (with JSON tag "customComponentsPattern") before merging.
| // CustomComponentsPatten defines a pattern with custom components. | |
| // +optional | |
| CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"` | |
| // CustomComponentsPattern defines a pattern with custom components. | |
| // +optional | |
| CustomComponentsPattern *CustomComponentsPattern `json:"customComponentsPattern,omitempty"` |
| customComponentsPatten: | ||
| description: CustomComponentsPatten defines a pattern with custom |
There was a problem hiding this comment.
Typo propagated from the API types: customComponentsPatten should be customComponentsPattern (missing 'r'). This will be part of the CRD schema seen by users.
| customComponentsPatten: | ||
| description: CustomComponentsPatten defines a pattern with |
There was a problem hiding this comment.
Same typo: customComponentsPatten should be customComponentsPattern (missing 'r').
| LeaderWorkerPattern *LeaderWorkerPatternApplyConfiguration `json:"leaderWorkerPattern,omitempty"` | ||
| StandalonePattern *StandalonePatternApplyConfiguration `json:"standalonePattern,omitempty"` | ||
| LeaderWorkerPattern *LeaderWorkerPatternApplyConfiguration `json:"leaderWorkerPattern,omitempty"` | ||
| CustomComponentsPatten *CustomComponentsPatternApplyConfiguration `json:"customComponentsPatten,omitempty"` |
There was a problem hiding this comment.
Same typo: CustomComponentsPatten should be CustomComponentsPattern (missing 'r') in the field name and JSON tag. This needs to be fixed in the source type definition in rolebasedgroup_types.go and regenerated.
| @@ -185,6 +185,10 @@ func (r *RoleSpec) GetLeaderWorkerPattern() *LeaderWorkerPattern { | |||
| return r.LeaderWorkerPattern | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
Missing doc comment. The other getter methods (GetStandalonePattern, GetLeaderWorkerPattern) all have doc comments following the pattern // GetXxx returns the Xxx if set, nil otherwise.. This function should follow the same convention for consistency.
| // GetCustomComponentsPattern returns the CustomComponentsPattern if set, nil otherwise. |
| @@ -281,6 +281,11 @@ type LeaderWorkerPattern struct { | |||
| WorkerTemplatePatch *runtime.RawExtension `json:"workerTemplatePatch,omitempty"` | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
Missing doc comment on the CustomComponentsPattern type. The other pattern types (StandalonePattern, LeaderWorkerPattern) all have doc comments describing what they define. This type should follow the same convention.
| // CustomComponentsPattern defines the custom component-based deployment pattern. |
|
|
||
| // CustomComponentsPatten defines a pattern with custom components. | ||
| // +optional | ||
| CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"` |
There was a problem hiding this comment.
The comment says "Only one of standalonePattern or leaderWorkerPattern can be specified" but now there's a third option (customComponentsPattern). This comment should be updated to reflect all three patterns are mutually exclusive. Additionally, the XValidation rule on RoleSpec (line 164) only enforces mutual exclusivity between standalonePattern and leaderWorkerPattern — it should be extended to include customComponentsPattern as well, otherwise users could specify multiple patterns simultaneously.
Ⅰ. Motivation
Ⅱ. Modifications
Ⅲ. Does this pull request fix one issue?
fixes #XXXX
Ⅳ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
Ⅴ. Describe how to verify it
VI. Special notes for reviews
Checklist
make fmt.