Skip to content

feat(teamrolebindings): support multiple teamRefs in a single TRB#1854

Merged
mikolajkucinski merged 9 commits intomainfrom
feat/teamrefs-in-trb
Mar 26, 2026
Merged

feat(teamrolebindings): support multiple teamRefs in a single TRB#1854
mikolajkucinski merged 9 commits intomainfrom
feat/teamrefs-in-trb

Conversation

@mikolajkucinski
Copy link
Copy Markdown
Contributor

@mikolajkucinski mikolajkucinski commented Mar 16, 2026

Description

Adds teamRefs to TeamRoleBindingSpec so a single TRB can reference multiple teams. The old teamRef is deprecated (the webhook merges it into teamRefs automatically, so existing resources migrate lazily). The controller handles partial failures (missing teams don't break RBAC for the rest) and metrics track each team individually.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

@github-actions github-actions bot added size/L feature core-apis helm-charts documentation Improvements or additions to documentation labels Mar 16, 2026
@github-actions github-actions bot added size/XXL and removed size/L labels Mar 16, 2026
@mikolajkucinski mikolajkucinski changed the title Feat/teamrefs in trb feat(teamrolebindings): support multiple teamRefs in a single TeamRoleBinding Mar 16, 2026
@mikolajkucinski mikolajkucinski force-pushed the feat/teamrefs-in-trb branch 3 times, most recently from 7f0722b to bc3804b Compare March 16, 2026 14:51
- Refactor getTeams to return partial results with missing team names
- Add deduplication of teamRefs in defaulting webhook
- Update printcolumn from teamRef to teamRefs for kubectl output
- Add unit tests for resolveTeamRefs fallback path
- Add webhook tests for dedup scenarios

On-behalf-of: @SAP <mikolaj.kucinski@sap.com>
…pproach

On-behalf-of: @SAP <mikolaj.kucinski@sap.com>
@mikolajkucinski mikolajkucinski changed the title feat(teamrolebindings): support multiple teamRefs in a single TeamRoleBinding feat(teamrolebindings): support multiple teamRefs in a single TRB Mar 18, 2026
@mikolajkucinski mikolajkucinski marked this pull request as ready for review March 18, 2026 14:14
@mikolajkucinski mikolajkucinski requested a review from a team as a code owner March 18, 2026 14:14
@IvoGoman IvoGoman requested a review from Copilot March 19, 2026 15:40
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

This PR extends TeamRoleBinding to support binding a single TeamRole to multiple Teams via spec.teamRefs, while deprecating the legacy spec.teamRef. The webhook defaults/migrates legacy fields, the controller reconciles RBAC across multiple teams (tolerating missing teams), and metrics/tests are updated accordingly.

Changes:

  • Add spec.teamRefs to the API/CRD and deprecate spec.teamRef (with deepcopy + printcolumn updates).
  • Update webhook defaulting/validation and add tests for migration/deduplication + deprecation warnings.
  • Update TeamRBAC controller/metrics to resolve multiple teams, reconcile subjects accordingly, and add/adjust tests.

Reviewed changes

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

Show a summary per file
File Description
api/v1alpha2/teamrolebinding_types.go Adds TeamRefs to the spec, deprecates TeamRef, updates printer columns.
api/v1alpha2/zz_generated.deepcopy.go Adds deepcopy support for TeamRefs.
charts/manager/crds/greenhouse.sap_teamrolebindings.yaml CRD schema + printer column updates for teamRefs and deprecation text for teamRef.
api/well_known.go Renames field index constant to .spec.teamRefs.
internal/webhook/v1alpha2/teamrolebinding_webhook.go Implements defaulting migration to teamRefs + deprecation warnings; updates warning aggregation.
internal/webhook/v1alpha2/teamrolebinding_webhook_test.go Adds/updates tests for defaulting migration, deduplication, and warnings.
internal/controller/teamrbac/teamrolebinding_controller.go Reconciles RBAC subjects from multiple teams; indexes/enqueues by teamRefs; adds resolveTeamRefs + getTeams.
internal/controller/teamrbac/metrics.go Emits readiness gauge per teamRef; cleans up old label sets on updates.
internal/controller/teamrbac/teamrolebinding_controller_test.go Adds integration tests for multi-team behavior and legacy teamRef migration.
internal/controller/teamrbac/teamrolebinding_controller_unit_test.go Adds unit tests for resolveTeamRefs.
internal/test/resources.go Adds WithTeamRefs test helper; keeps WithTeamRef for backwards compatibility.

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

Comment thread internal/webhook/v1alpha2/teamrolebinding_webhook.go
Comment thread internal/webhook/v1alpha2/teamrolebinding_webhook.go
Comment thread internal/controller/teamrbac/teamrolebinding_controller.go
@mikolajkucinski mikolajkucinski merged commit 476443b into main Mar 26, 2026
23 checks passed
@mikolajkucinski mikolajkucinski deleted the feat/teamrefs-in-trb branch March 26, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-apis documentation Improvements or additions to documentation feature helm-charts size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] - Allow multiple teamRefs in TRB

3 participants