Skip to content

feat(rbg): support use templateRef in lwp#254

Merged
cheyang merged 3 commits intosgl-project:mainfrom
Syspretor:feature/allow-roletemplate-in-lwp
Apr 10, 2026
Merged

feat(rbg): support use templateRef in lwp#254
cheyang merged 3 commits intosgl-project:mainfrom
Syspretor:feature/allow-roletemplate-in-lwp

Conversation

@Syspretor
Copy link
Copy Markdown
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.

Copy link
Copy Markdown

@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 enables templateRef support for LeaderWorkerSet and LeaderWorkerPattern workloads by updating validation rules and the RoleInstanceSet reconciler. The reconciler now resolves a base template from either a referenced RoleTemplate (applying a templatePatch if present) or an inline definition. Key feedback highlights the necessity of using DeepCopy() when retrieving and patching templates to avoid mutating the controller's cache or leaking state between leader and worker configurations. There is also a suggestion to refactor the template resolution logic into a shared utility to improve maintainability.

Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Copy link
Copy Markdown
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

Adds support for using templateRef (RoleTemplates) with LeaderWorkerPattern when constructing RoleInstanceSet leader/worker pod templates, enabling reuse of shared base pod templates while still applying leader/worker-specific patches.

Changes:

  • Resolve a baseTemplate for LeaderWorkerPattern from either inline template or templateRef + templatePatch, then apply leaderTemplatePatch/workerTemplatePatch.
  • Update RoleInstanceSet leader/worker template construction to use applyStrategicMergePatch and pass templates by value.
  • Remove controller-side validation that previously rejected templateRef for LeaderWorkerPattern (and also for LeaderWorkerSet workloads).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/reconciler/roleinstanceset_reconciler.go Resolves base PodTemplateSpec from inline template or RoleTemplate reference, then applies leader/worker patches for RoleInstanceSet LWP.
api/workloads/v1alpha2/roletemplate_validation.go Removes the validation that disallowed templateRef for LeaderWorkerPattern / LeaderWorkerSet workloads.
Comments suppressed due to low confidence (1)

api/workloads/v1alpha2/roletemplate_validation.go:122

  • Controller-side validation no longer rejects templateRef for LeaderWorkerSet workloads. The CRD currently has a CEL rule for this, but keeping the controller “defense-in-depth” check is important for clusters running older CRDs / without CEL enforcement, and the LeaderWorkerSet reconciler still assumes templateRef is unsupported (it only reads role.GetTemplate()). Consider reintroducing the role.Workload.Kind == "LeaderWorkerSet" guard while still allowing templateRef for LeaderWorkerPattern used with other workloads (e.g., RoleInstanceSet).
		if role.Workload.Kind == "InstanceSet" {
			return fmt.Errorf(
				"spec.roles[%d].templateRef: not supported for InstanceSet workloads",
				index,
			)
		}

		// Cross-resource check: referenced template must exist.
		templateRef := role.GetTemplateRef()
		if !validTemplateNames[templateRef.Name] {
			return fmt.Errorf(
				"spec.roles[%d].templateRef.name: template %q not found in spec.roleTemplates",
				index, templateRef.Name,
			)
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
Comment thread api/workloads/v1alpha2/roletemplate_validation.go
Comment thread pkg/reconciler/roleinstanceset_reconciler.go Outdated
@cheyang cheyang merged commit 0466526 into sgl-project:main Apr 10, 2026
8 of 9 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