feat(rbg): support use templateRef in lwp#254
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
baseTemplateforLeaderWorkerPatternfrom either inlinetemplateortemplateRef+templatePatch, then applyleaderTemplatePatch/workerTemplatePatch. - Update RoleInstanceSet leader/worker template construction to use
applyStrategicMergePatchand pass templates by value. - Remove controller-side validation that previously rejected
templateReffor 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.
Ⅰ. 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.