Skip to content

refactor(rbg): support customComponentsPatterns in v1alpha2 version#193

Merged
cheyang merged 2 commits intosgl-project:mainfrom
Syspretor:feature/support-custom-component-pattern
Mar 13, 2026
Merged

refactor(rbg): support customComponentsPatterns in v1alpha2 version#193
cheyang merged 2 commits intosgl-project:mainfrom
Syspretor:feature/support-custom-component-pattern

Conversation

@Syspretor
Copy link
Collaborator

Ⅰ. 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

  • Format your code make fmt.
  • Add unit tests or integration tests.
  • Update the documentation related to the change.

@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 RoleBasedGroup in its v1alpha2 version to introduce a dedicated CustomComponentsPattern. This change moves the definition of custom components from a direct field on the RoleSpec into a structured pattern, enhancing the consistency and extensibility of the API. The update ensures that custom component definitions are handled uniformly alongside other workload patterns, with corresponding adjustments made to the reconciliation logic and client-go tooling.

Highlights

  • API Refactoring: Introduced a new CustomComponentsPattern struct to encapsulate custom components, aligning them with other workload patterns.
  • RoleSpec Update: Refactored RoleSpec to remove the direct Components field, instead utilizing the new CustomComponentsPattern via the Pattern union.
  • Reconciler Logic Adjustment: Updated the reconciler logic to correctly handle the new CustomComponentsPattern when constructing RoleInstanceSet configurations.
  • Client-Go Integration: Generated new client-go apply configurations for CustomComponentsPattern and updated existing ones to support this API change.

🧠 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
  • api/workloads/v1alpha2/helper.go
    • Added a new getter method GetCustomComponentsPattern to RoleSpec.
  • api/workloads/v1alpha2/rolebasedgroup_types.go
    • Removed the Components field from RoleSpec.
    • Introduced CustomComponentsPattern struct.
    • Added CustomComponentsPatten field to the Pattern struct.
  • api/workloads/v1alpha2/zz_generated.deepcopy.go
    • Generated deepcopy methods for CustomComponentsPattern.
    • Updated existing deepcopy logic for Pattern and RoleSpec.
  • client-go/applyconfiguration/utils.go
    • Registered CustomComponentsPatternApplyConfiguration for the CustomComponentsPattern kind.
  • client-go/applyconfiguration/workloads/v1alpha2/customcomponentspattern.go
    • Added a new file defining CustomComponentsPatternApplyConfiguration and its builder methods.
  • client-go/applyconfiguration/workloads/v1alpha2/pattern.go
    • Updated PatternApplyConfiguration to include CustomComponentsPatten.
    • Added a corresponding WithCustomComponentsPatten method.
  • client-go/applyconfiguration/workloads/v1alpha2/rolespec.go
    • Removed the Components field and WithComponents method.
    • Added a WithCustomComponentsPatten method to RoleSpecApplyConfiguration.
  • pkg/reconciler/roleinstanceset_reconciler.go
    • Refactored the constructRoleInstanceSetApplyConfiguration function to use GetCustomComponentsPattern.
    • Renamed constructRoleInstanceTemplateByCustomComponentPattern to constructRoleInstanceTemplateByCustomComponentsPattern and updated its component access.
Activity
  • No specific activity has been recorded for this pull request yet.
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

@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 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.

Comment on lines +234 to +236
// CustomComponentsPatten defines a pattern with custom components.
// +optional
CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"`

Choose a reason for hiding this comment

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

high

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.

Suggested change
// 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"`

@RongGu RongGu requested a review from Copilot March 12, 2026 12:01
// +optional
LeaderWorkerPattern *LeaderWorkerPattern `json:"leaderWorkerPattern,omitempty"`

// CustomComponentsPatten defines a pattern with custom components.
Copy link
Collaborator

Choose a reason for hiding this comment

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

CustomComponentsPatten -》 CustomComponentsPattern

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 CustomComponentsPattern struct and moved Components from RoleSpec into it as a field within Pattern.
  • 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.

Comment on lines +234 to +236
// CustomComponentsPatten defines a pattern with custom components.
// +optional
CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"`
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// 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"`

Copilot uses AI. Check for mistakes.
Comment on lines +23908 to +23909
customComponentsPatten:
description: CustomComponentsPatten defines a pattern with custom
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Typo propagated from the API types: customComponentsPatten should be customComponentsPattern (missing 'r'). This will be part of the CRD schema seen by users.

Copilot uses AI. Check for mistakes.
Comment on lines +24287 to +24288
customComponentsPatten:
description: CustomComponentsPatten defines a pattern with
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Same typo: customComponentsPatten should be customComponentsPattern (missing 'r').

Copilot uses AI. Check for mistakes.
LeaderWorkerPattern *LeaderWorkerPatternApplyConfiguration `json:"leaderWorkerPattern,omitempty"`
StandalonePattern *StandalonePatternApplyConfiguration `json:"standalonePattern,omitempty"`
LeaderWorkerPattern *LeaderWorkerPatternApplyConfiguration `json:"leaderWorkerPattern,omitempty"`
CustomComponentsPatten *CustomComponentsPatternApplyConfiguration `json:"customComponentsPatten,omitempty"`
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@@ -185,6 +185,10 @@ func (r *RoleSpec) GetLeaderWorkerPattern() *LeaderWorkerPattern {
return r.LeaderWorkerPattern
}

Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// GetCustomComponentsPattern returns the CustomComponentsPattern if set, nil otherwise.

Copilot uses AI. Check for mistakes.
@@ -281,6 +281,11 @@ type LeaderWorkerPattern struct {
WorkerTemplatePatch *runtime.RawExtension `json:"workerTemplatePatch,omitempty"`
}

Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// CustomComponentsPattern defines the custom component-based deployment pattern.

Copilot uses AI. Check for mistakes.
Comment on lines +233 to +236

// CustomComponentsPatten defines a pattern with custom components.
// +optional
CustomComponentsPatten *CustomComponentsPattern `json:"customComponentsPatten,omitempty"`
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Copy link
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@cheyang cheyang enabled auto-merge (squash) March 13, 2026 03:43
@cheyang cheyang disabled auto-merge March 13, 2026 05:59
@cheyang cheyang enabled auto-merge (squash) March 13, 2026 05:59
@cheyang cheyang disabled auto-merge March 13, 2026 06:00
@cheyang cheyang merged commit cb717a3 into sgl-project:main Mar 13, 2026
5 of 8 checks passed
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.

3 participants