Skip to content

feat: Supports using controllerrevision hash to update role - #34

Merged
cheyang merged 3 commits into
sgl-project:mainfrom
bcfre:dev-0922
Oct 10, 2025
Merged

cheyang merged 3 commits into
sgl-project:mainfrom
bcfre:dev-0922

Conversation

@bcfre

@bcfre bcfre commented Sep 22, 2025 •

Copy link
Copy Markdown
Contributor

Ⅰ. Motivation

  1. Store the state of RBG Roles in ControllerRevisions to prepare for future rollback support.
  2. Track the revision hash for each Role deployment on the RBG via labels, and compare it against the corresponding ControllerRevision to ensure Role changes on the RBG are not overlooked.

Ⅱ. Modifications

Added two types of labels: RBG and specific role.
Added logic for creating and cleaning up ControllerRevisions.

Ⅲ. Does this pull request fix one issue?

fixes #21

Ⅳ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Add ut and update e2e

ok      sigs.k8s.io/rbgs/cmd/cli        0.486s  coverage: 71.6% of statements
ok      sigs.k8s.io/rbgs/cmd/rbgs       2.230s  coverage: 7.5% of statements
ok      sigs.k8s.io/rbgs/internal/controller/workloads  0.721s  coverage: 61.6% of statements
ok      sigs.k8s.io/rbgs/pkg/dependency 3.117s  coverage: 94.4% of statements
ok      sigs.k8s.io/rbgs/pkg/discovery  2.739s  coverage: 92.7% of statements
ok      sigs.k8s.io/rbgs/pkg/reconciler 26.263s coverage: 73.0% of statements
ok      sigs.k8s.io/rbgs/pkg/scale      3.343s  coverage: 100.0% of statements
ok      sigs.k8s.io/rbgs/pkg/scheduler  1.575s  coverage: 34.4% of statements
ok      sigs.k8s.io/rbgs/pkg/utils      3.845s  coverage: 77.0% of statements
go tool cover -func=cover.out | awk '/^total:/ {print $3}'
67.2%
Ran 27 of 27 Specs in 285.618 seconds
SUCCESS! -- 27 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestE2E (285.62s)
PASS
ok      sigs.k8s.io/rbgs/test/e2e       286.468s

Ⅴ. Describe how to verify it

  • example for rbg
kubectl apply -f examples/basics/rbg-base.yaml 

kubectl get rbg,lws,sts,deploy,po,controllerrevision -l rolebasedgroup.workloads.x-k8s.io/name=nginx-cluster
# output
NAME                                    READY   AGE
statefulset.apps/nginx-cluster-leader   1/1     3m53s

NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-cluster-worker   3/3     3            3           3m53s

NAME                                       READY   STATUS    RESTARTS   AGE
pod/nginx-cluster-leader-0                 1/1     Running   0          3m54s
pod/nginx-cluster-worker-97b95d9cd-52frk   1/1     Running   0          3m52s
pod/nginx-cluster-worker-97b95d9cd-6h9rs   1/1     Running   0          3m52s
pod/nginx-cluster-worker-97b95d9cd-vjjfh   1/1     Running   0          3m52s

NAME                                                      CONTROLLER                                        REVISION   AGE
controllerrevision.apps/nginx-cluster-654fb598b9-1        rolebasedgroup.workloads.x-k8s.io/nginx-cluster   1          3m58s
controllerrevision.apps/nginx-cluster-leader-5b77c6c65f   statefulset.apps/nginx-cluster-leader             1          3m54s
  • view the labels of a ControllerRevision
kubectl get  controllerrevision.apps/nginx-cluster-654fb598b9-1 --show-labels
NAME                         CONTROLLER                                        REVISION   AGE     LABELS
nginx-cluster-8676cf98bd-1   rolebasedgroup.workloads.x-k8s.io/nginx-cluster   1          93m   rolebasedgroup.workloads.x-k8s.io/controller-revision-hash=8676cf98bd,rolebasedgroup.workloads.x-k8s.io/name=nginx-cluster

VI. Special notes for reviews

Checklist

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

@bcfre
bcfre requested review from cheyang and gujingit September 22, 2025 02:49
@bcfre
bcfre force-pushed the dev-0922 branch 4 times, most recently from 0d2c424 to 1ac3b31 Compare September 22, 2025 08:30
@cheyang

cheyang commented Sep 23, 2025

Copy link
Copy Markdown
Collaborator

@bcfre Please fix the conflict issue. thanks.

Comment thread pkg/utils/revision_utils.go Outdated
@gujingit
gujingit requested a review from Copilot September 23, 2025 07:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds ControllerRevision support to enable tracking and future rollback capabilities for RoleBasedGroup deployments. The implementation creates ControllerRevisions to store RBG state snapshots and uses revision hashes to detect changes that require workload updates.

  • Implements ControllerRevision creation and lifecycle management for RBG state tracking
  • Adds revision hash labels to both ControllerRevisions and workload resources for change detection
  • Updates all workload reconcilers to include revision tracking in their reconciliation logic

Reviewed Changes

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

Show a summary per file
File Description
pkg/utils/revision_utils.go Core revision management utilities including creation, cleanup, and hashing
pkg/utils/revision_utils_test.go Unit tests for revision utilities and cleanup functionality
internal/controller/workloads/rolebasedgroup_controller.go Main controller updates to integrate revision management
pkg/reconciler/*_reconciler.go Updates to StatefulSet, LeaderWorkerSet, and Deployment reconcilers for revision support
api/workloads/v1alpha1/constant.go New constants for revision-related labels and keys
test/utils/utils.go Increased timeout for e2e tests
test/wrappers/rbg_wrapper.go Added test wrapper method for PodGroupPolicy
config/rbac/rbgs_controller_role.yaml Added RBAC permissions for ControllerRevision resources
go.mod Moved go-spew dependency from indirect to direct
Comments suppressed due to low confidence (1)

pkg/utils/revision_utils.go:1

  • Debug print statement should be removed from production code or replaced with proper logging.
package utils

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/utils/revision_utils.go Outdated
Comment thread pkg/utils/revision_utils.go Outdated
Comment thread pkg/utils/revision_utils.go
Comment thread pkg/utils/revision_utils.go Outdated
Comment thread pkg/reconciler/deploy_reconciler.go Outdated
Comment thread pkg/reconciler/deploy_reconciler.go Outdated
Comment thread pkg/reconciler/deploy_reconciler.go Outdated
Comment thread api/workloads/v1alpha1/constant.go Outdated
Comment thread api/workloads/v1alpha1/groupversion_info.go Outdated
Comment thread internal/controller/workloads/rolebasedgroup_controller.go
Comment thread api/workloads/v1alpha1/constant.go Outdated
Comment thread api/workloads/v1alpha1/constant.go Outdated
Comment thread pkg/reconciler/deploy_reconciler.go Outdated
Comment thread pkg/utils/revision_utils.go
Comment thread config/rbac/rbgs_controller_role.yaml Outdated
Comment thread internal/controller/workloads/rolebasedgroup_controller.go Outdated
@bcfre
bcfre force-pushed the dev-0922 branch 2 times, most recently from ca8af6c to d6a2f69 Compare September 28, 2025 03:15
@bcfre
bcfre requested a review from cheyang September 28, 2025 03:33
Comment thread internal/controller/workloads/rolebasedgroup_controller.go Outdated
Comment thread internal/controller/workloads/rolebasedgroup_controller.go Outdated
…update the role under rbg

Signed-off-by: bcfre <guo0xiong1feng@gmail.com>
@bcfre
bcfre requested a review from cheyang October 8, 2025 11:41

@ZYecho11 ZYecho11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: 柏存 <guoxiongfeng.gxf@alibaba-inc.com>

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

/lgtm
/approve

@cheyang
cheyang merged commit cb991ad into sgl-project:main Oct 10, 2025
3 checks passed
@bcfre
bcfre deleted the dev-0922 branch October 10, 2025 10:48
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.

[Bug] How to change the unit scale of P or D at the RGB layer, given that the P/D scale of LWS becomes unmodifiable once it is determined?

5 participants