Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/workloads/v1alpha2/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
func (r *RoleSpec) GetCustomComponentsPattern() *CustomComponentsPattern {
return r.CustomComponentsPattern
}

// GetTemplate returns the PodTemplateSpec for this role.
// It checks both StandalonePattern and LeaderWorkerPattern.
func (r *RoleSpec) GetTemplate() *corev1.PodTemplateSpec {
Expand Down
13 changes: 9 additions & 4 deletions api/workloads/v1alpha2/rolebasedgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@ type RoleSpec struct {
// +optional
Pattern `json:",inline"`

// Components describe the components that will be created.
// +optional
Components []InstanceComponent `json:"components,omitempty"`

// +optional
ServicePorts []corev1.ServicePort `json:"servicePorts,omitempty"`

Expand All @@ -234,6 +230,10 @@ type Pattern struct {
// LeaderWorkerPattern defines a multi-pod pattern with leader and workers.
// +optional
LeaderWorkerPattern *LeaderWorkerPattern `json:"leaderWorkerPattern,omitempty"`

// CustomComponentsPattern defines a pattern with custom components.
// +optional
CustomComponentsPattern *CustomComponentsPattern `json:"customComponentsPattern,omitempty"`
}

// TemplateSource defines either an inline template or a reference to a RoleTemplate.
Expand Down Expand Up @@ -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.
type CustomComponentsPattern struct {
// +optional
Components []InstanceComponent `json:"components,omitempty"`
}

type WorkloadSpec struct {
// +optional
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/v[0-9]+((alpha|beta)[0-9]+)?$`
Expand Down
34 changes: 27 additions & 7 deletions api/workloads/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client-go/applyconfiguration/utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions client-go/applyconfiguration/workloads/v1alpha2/pattern.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions client-go/applyconfiguration/workloads/v1alpha2/rolespec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 29 additions & 26 deletions config/crd/bases/workloads.x-k8s.io_rolebasedgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23905,32 +23905,35 @@ spec:
description: Annotations is an unstructured key value map stored
with a resource.
type: object
components:
description: Components describe the components that will be
created.
items:
properties:
name:
description: Name is the type name of the component.
type: string
serviceName:
description: ServiceName is the name of the service that
governs this Instance Component.
type: string
size:
description: Size is the number of replicas for Pods that
match the PodRule.
format: int32
type: integer
template:
description: Template is the template for the component
pods.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- template
type: object
type: array
customComponentsPattern:
description: CustomComponentsPattern defines a pattern with
custom components.
properties:
components:
items:
properties:
name:
description: Name is the type name of the component.
type: string
serviceName:
description: ServiceName is the name of the service
that governs this Instance Component.
type: string
size:
description: Size is the number of replicas for Pods
that match the PodRule.
format: int32
type: integer
template:
description: Template is the template for the component
pods.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- template
type: object
type: array
type: object
dependencies:
description: Dependencies of the role
items:
Expand Down
55 changes: 29 additions & 26 deletions config/crd/bases/workloads.x-k8s.io_rolebasedgroupsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24284,32 +24284,35 @@ spec:
description: Annotations is an unstructured key value map
stored with a resource.
type: object
components:
description: Components describe the components that will
be created.
items:
properties:
name:
description: Name is the type name of the component.
type: string
serviceName:
description: ServiceName is the name of the service
that governs this Instance Component.
type: string
size:
description: Size is the number of replicas for Pods
that match the PodRule.
format: int32
type: integer
template:
description: Template is the template for the component
pods.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- template
type: object
type: array
customComponentsPattern:
description: CustomComponentsPattern defines a pattern with
custom components.
properties:
components:
items:
properties:
name:
description: Name is the type name of the component.
type: string
serviceName:
description: ServiceName is the name of the service
that governs this Instance Component.
type: string
size:
description: Size is the number of replicas for
Pods that match the PodRule.
format: int32
type: integer
template:
description: Template is the template for the
component pods.
x-kubernetes-preserve-unknown-fields: true
required:
- name
- template
type: object
type: array
type: object
dependencies:
description: Dependencies of the role
items:
Expand Down
17 changes: 9 additions & 8 deletions pkg/reconciler/roleinstanceset_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ func (r *RoleInstanceSetReconciler) constructRoleInstanceSetApplyConfiguration(
WithRestartPolicy(restartPolicy)
var constructErr error
switch {
case len(role.Components) > 0:
roleInstanceSetLabel[constants.RoleTypeLabelKey] = string(constants.ComponentsTemplateType)
constructErr = r.constructRoleInstanceTemplateByCustomComponentPattern(ctx, rbg, role, matchLabels, roleInstanceTemplateConfig)
case role.GetLeaderWorkerPattern() != nil:
roleInstanceSetLabel[constants.RoleTypeLabelKey] = string(constants.LeaderWorkerSetTemplateType)
constructErr = r.constructRoleInstanceTemplateByLeaderWorkerPattern(ctx, rbg, role, matchLabels, roleInstanceTemplateConfig)
case role.GetStandalonePattern() != nil:
roleInstanceSetLabel[constants.RoleTypeLabelKey] = string(constants.PodTemplateTemplateType)
constructErr = r.constructRoleInstanceTemplateFromStandalonePattern(ctx, rbg, role, matchLabels, roleInstanceTemplateConfig)
case role.GetLeaderWorkerPattern() != nil:
roleInstanceSetLabel[constants.RoleTypeLabelKey] = string(constants.LeaderWorkerSetTemplateType)
constructErr = r.constructRoleInstanceTemplateByLeaderWorkerPattern(ctx, rbg, role, matchLabels, roleInstanceTemplateConfig)
case role.GetCustomComponentsPattern() != nil:
roleInstanceSetLabel[constants.RoleTypeLabelKey] = string(constants.ComponentsTemplateType)
constructErr = r.constructRoleInstanceTemplateByCustomComponentsPattern(ctx, rbg, role, matchLabels, roleInstanceTemplateConfig)

default:
constructErr = fmt.Errorf("no valid pattern found for role %s", role.Name)
}
Expand Down Expand Up @@ -231,15 +232,15 @@ func (r *RoleInstanceSetReconciler) constructRoleInstanceSetApplyConfiguration(
return roleInstanceSetConfig, nil
}

func (r *RoleInstanceSetReconciler) constructRoleInstanceTemplateByCustomComponentPattern(
func (r *RoleInstanceSetReconciler) constructRoleInstanceTemplateByCustomComponentsPattern(
ctx context.Context,
rbg *workloadsv1alpha2.RoleBasedGroup,
role *workloadsv1alpha2.RoleSpec,
matchLabels map[string]string,
roleInstanceTemplateConfig *workloadsv1alpha2client.RoleInstanceTemplateApplyConfiguration,
) error {
podReconciler := NewPodReconciler(r.scheme, r.client)
for _, component := range role.Components {
for _, component := range role.GetCustomComponentsPattern().Components {
podTemplateApplyConfiguration, err := podReconciler.ConstructPodTemplateSpecApplyConfiguration(
ctx, rbg, role, maps.Clone(matchLabels), component.Template)
if err != nil {
Expand Down
Loading