Skip to content

feat(mpi): add --disable-mpi-rbac-management flag#1

Open
vicoooo26 wants to merge 6 commits into
AliyunContainerService:developfrom
vicoooo26:fix/mpijob-role-rbac
Open

feat(mpi): add --disable-mpi-rbac-management flag#1
vicoooo26 wants to merge 6 commits into
AliyunContainerService:developfrom
vicoooo26:fix/mpijob-role-rbac

Conversation

@vicoooo26

@vicoooo26 vicoooo26 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it:

Adds a new --disable-mpi-rbac-management CLI flag (default: false) to the MPIJob controller. When set to true, the controller will:

  • Not create ServiceAccount, Role, or RoleBinding for MPIJob launchers
  • Not inject ServiceAccountName into the launcher pod template
  • Not watch RBAC resources (Role, RoleBinding, ServiceAccount)

This allows operators to run with reduced privileges and supports multi-tenant environments where users pre-provide their own ServiceAccount with the necessary permissions (pods get/list/watch, pods/exec create) via spec.serviceAccountName in the launcher pod template.

Which issue(s) this PR fixes (optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged):
Fixes #

Checklist:

- [ ] Docs included if any changes are user facing

@vicoooo26
vicoooo26 changed the base branch from master to release-1.9 July 14, 2026 16:23
@vicoooo26

Copy link
Copy Markdown
Collaborator Author

@cheyang, could you please review this PR? Thanks in advance.

@vicoooo26
vicoooo26 force-pushed the fix/mpijob-role-rbac branch from 62f5b57 to a5ad06a Compare July 20, 2026 11:05
When the flag is set to true, the MPIJob controller skips creating
ServiceAccount, Role, and RoleBinding, skips injecting
ServiceAccountName into the launcher pod, and skips watching RBAC
resources. Users must pre-provide a ServiceAccount with sufficient
permissions via the launcher pod template's spec.serviceAccountName.
ConfigMap creation and kubectl delivery remain unconditional.

Signed-off-by: Vico Chu <vico24826@gmail.com>
Add integration test that starts a second envtest instance with
DisableMPIRBACManagement=true and verifies:
- No Role/RoleBinding/ServiceAccount created by the operator
- ConfigMap and kubectl delivery init container still created
- Role changes do not trigger reconcile (watch suppressed)
- ConfigMap changes still trigger reconcile (positive control)
- Launcher pod recreated only after ConfigMap-triggered reconcile

Also adds kubectl delivery init container assertion to pin the
spec invariant that kubectl delivery remains unconditional.

Signed-off-by: Vico Chu <vico24826@gmail.com>
@vicoooo26
vicoooo26 force-pushed the fix/mpijob-role-rbac branch from a5ad06a to b847f6b Compare July 22, 2026 09:22

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

Reviewed the feature end to end and ran the MPI envtest suite against this PR head — the added “disabled RBAC management” specs pass. The gating is consistent across the three sites (watch setup, ReconcilePods, launcher SA injection), and since podSpec is a DeepCopy of the launcher template, a user-supplied serviceAccountName is correctly preserved when the flag is on. Two things worth addressing before merge, plus a docs gap (inline).

Comment thread pkg/controller.v1/mpi/mpijob_controller.go
Comment thread cmd/training-operator.v1/main.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new --disable-mpi-rbac-management flag to allow the MPIJob controller to run without creating/watching launcher RBAC resources, enabling reduced-privilege / multi-tenant deployments where users provide their own ServiceAccount.

Changes:

  • Gate RBAC watches (Role/RoleBinding/ServiceAccount) behind DisableMPIRBACManagement.
  • Skip launcher ServiceAccount/Role/RoleBinding reconciliation and ServiceAccountName injection when RBAC management is disabled.
  • Add CLI/config plumbing and controller tests covering the disabled-RBAC behavior.

Reviewed changes

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

File Description
pkg/controller.v1/mpi/mpijob_controller.go Conditionally disables RBAC watches, RBAC resource creation, and SA name injection based on the new config flag.
pkg/controller.v1/mpi/mpijob_controller_test.go Adds envtest coverage verifying no RBAC resources are created and controller still reconciles correctly when disabled.
pkg/config/config.go Adds DisableMPIRBACManagement to shared controller config.
cmd/training-operator.v1/main.go Wires up the --disable-mpi-rbac-management CLI flag.
Comments suppressed due to low confidence (1)

pkg/controller.v1/mpi/mpijob_controller_test.go:711

  • This test resets DisableMPIRBACManagement to false unconditionally. Restoring the previous value reduces coupling to global state and avoids surprising behavior if the suite default ever changes.
			ctlrconfig.Config.DisableMPIRBACManagement = true
			defer func() {
				ctlrconfig.Config.DisableMPIRBACManagement = false
			}()

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

Comment thread pkg/controller.v1/mpi/mpijob_controller_test.go
Comment thread pkg/controller.v1/mpi/mpijob_controller_test.go Outdated
Add kubectl delivery init container check to the first disabled RBAC
test context, mirroring the assertion in the SetupWithManager test.
Both ConfigMap creation and kubectl delivery are unconditional (not
gated by the flag), so both should be verified when the flag is true.

Signed-off-by: Vico Chu <vico24826@gmail.com>
@vicoooo26
vicoooo26 force-pushed the fix/mpijob-role-rbac branch from 5bdb068 to e95f639 Compare July 23, 2026 05:16
…cceeds

Signed-off-by: Vico Chu <vico24826@gmail.com>
…ment help text

Specify that the user-provided ServiceAccount needs a Role granting
get, list, watch on pods and create on pods/exec, matching the
permissions that newLauncherRole would have granted.

Signed-off-by: Vico Chu <vico24826@gmail.com>
…ncher template

Signed-off-by: Vico Chu <vicochu@gmail.com>
@vicoooo26
vicoooo26 force-pushed the fix/mpijob-role-rbac branch from d11ef50 to 8f8a791 Compare July 23, 2026 15:56
@vicoooo26
vicoooo26 changed the base branch from release-1.9 to develop July 24, 2026 05:40
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