feat: add session label controller for Workbench session pods#123
feat: add session label controller for Workbench session pods#123
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude review this PR |
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude review again please |
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude one more time! review please. |
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude review again please |
|
Claude finished @amdove's task —— View job Code Review: Session Group Label Controller
Overall this is a well-structured, focused feature. The controller design is clean, the configuration is appropriately flexible, and the test coverage for the extraction/sanitization logic is thorough. The documentation is excellent. A few items worth considering before merge: Issues1. Regex compiled on every reconcile —
2. JSON marshal/unmarshal round-trip per pod — Every reconcile marshals the entire pod to JSON and unmarshals it back to 3. The 4. RBAC: The RBAC annotation scopes to 5. Workbench CR RBAC only grants The controller //+kubebuilder:rbac:namespace=posit-team,groups=core.posit.team,resources=workbenches,verbs=getThis should be: //+kubebuilder:rbac:namespace=posit-team,groups=core.posit.team,resources=workbenches,verbs=get;list;watchWithout Suggestions (non-blocking)6. After truncating to 63 chars, 7. Test coverage for 8. Consider adding a
9. Stale label cleanup prefix match is broad — The cleanup loop deletes any label whose key starts with Looks Good
TL;DR: Fix the Workbench RBAC annotation (item 5 — needs |
Description
Adds a
SessionGroupLabelReconcilerthat watches Workbench session pods and injects numbered labels derived from values extracted from a configurable pod field — e.g.user-group-1: some_value,user-group-2: another_value. Labels can be consumed by any downstream tooling that reads pod metadata.Replaces functionality for: #113
Intends to be more lightweight and supportable.
How it works
The controller reads a configurable field from each session pod, applies a regex to find matching entries, sanitizes them to valid Kubernetes label values, and patches the pod with numbered labels (up to 30). A
posit.co/session-group-labels-injected: "true"marker prevents reprocessing.Configuration is per-site via a new
sessionLabelsfield on the Workbench CRD. Adding it tosite.yamlenables the feature for that site; omitting it disables it. PTD automatically enables the controller via Helm when any site has the block configured — no manual flag needed.Enabling
All fields are optional — defaults cover the standard Workbench + Entra ID setup.
Reprocessing existing pods
By default, already-processed pods are skipped (the marker label prevents re-reconciliation). To force re-labeling of existing session pods — e.g. after changing
searchRegexortrimPrefix— setreprocess: true:When
reprocess: trueis set on a Workbench CR, the controller re-enqueues all existing session pods for that site immediately. Previously written group labels are cleared before the new set is applied, so stale labels from the old config are removed. Set back tofalse(or omit it) once done — it defaults tofalseand has no effect otherwise.Config flow
Category of change
Checklist
just testand all tests pass