Skip to content

refactor(operator): introduce ClusterUser to make actor-vs-SUT boundary explicit#83

Open
SamBarker wants to merge 5 commits intorefactor/operator-it-shared-resourcesfrom
refactor/operator-cluster-user
Open

refactor(operator): introduce ClusterUser to make actor-vs-SUT boundary explicit#83
SamBarker wants to merge 5 commits intorefactor/operator-it-shared-resourcesfrom
refactor/operator-cluster-user

Conversation

@SamBarker
Copy link
Copy Markdown
Owner

Type of change

  • Refactoring

Description

Introduces ClusterUser — a thin wrapper around a KubernetesClient scoped to the test namespace — to give integration tests an explicit, named object representing the actor (a regular Kubernetes user), distinct from the operator (the system under test).

Previously, LocalKroxyliciousOperatorExtension exposed create, get, replace, delete, and resources methods that silently delegated to an internal TestActor. This made test code look like the operator itself was creating resources, obscuring the actor/SUT boundary.

Changes:

  • ClusterUser: new class with create, get, replace, delete, resources — backed by the admin Kubernetes client scoped to the test namespace
  • LocallyRunningOperatorRbacHandler.userClient(): exposes the lazily-created admin client for constructing a ClusterUser
  • LocalKroxyliciousOperatorExtension.clusterUser(): returns a ClusterUser scoped to the test namespace; must be called after beforeAll
  • All seven ReconcilerIT files migrated to obtain a ClusterUser via operator.clusterUser() and route resource operations through it
  • LocalKroxyliciousOperatorExtension.create/get/replace/delete/resources removed — they are now dead code
  • patchStatus remains on the extension: it represents test infrastructure simulating another system updating status subresources, not a user action

AllReconcilersIT also updates its parameterised-test lambdas from Function<LocalKroxyliciousOperatorExtension, T> to Function<ClusterUser, T> since those lambdas create user-side resources (Secrets, ConfigMaps).

Additional Context

This is a follow-on to refactor/operator-it-shared-resources (the base branch). The ClusterUser name was chosen deliberately — it communicates a Kubernetes user perspective without overloading the term "user". A future clusterUser(ClusterRole) overload could enable RBAC-persona testing (platform team vs. app team) when needed.

Checklist

  • PR raised from a fork of this repository and made from a branch rather than main.
  • Write tests
  • Update documentation
  • Make sure all unit/integration tests pass
  • Make sure all Sonarcloud warnings are addressed or are justifiably ignored.
  • If applicable to the change, make sure system tests pass.
  • If applicable to the change, trigger the performance test suite.
  • Ensure the PR references relevant issue(s) so they are closed on merging.
  • For user facing changes, update CHANGELOG.md

ClusterUser wraps a KubernetesClient scoped to a specific namespace and
exposes create, get, replace, delete and resources. It is deliberately
separate from the operator extension (the SUT) so test code can clearly
distinguish user-side actions from operator reactions. patchStatus is
intentionally absent — that requires /status subresource RBAC that a
regular cluster user does not hold.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Sam Barker <sam@quadrocket.co.uk>
Adds userClient() to LocallyRunningOperatorRbacHandler to expose the
admin-backed KubernetesClient used for user-level interactions, then
wires it into clusterUser() on the extension. Tests can now obtain a
ClusterUser — the explicit actor in integration tests — without going
through the testActor internal interface.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Sam Barker <sam@quadrocket.co.uk>
Replace direct operator.create/get/replace/delete/resources calls with
clusterUser.create/get/replace/delete/resources to make the actor-vs-SUT
boundary explicit: ClusterUser represents a Kubernetes user interacting
with the cluster; the operator is the system under test reacting to
those user actions.

AllReconcilersIT also updates its parameterized-test lambda signatures
from Function<LocalKroxyliciousOperatorExtension, T> to Function<ClusterUser, T>
since those lambdas represent user setup actions (creating Secrets, CMs, etc.)
rather than operator behaviour.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Sam Barker <sam@quadrocket.co.uk>
… ClusterUser

Same pattern as the previous commit: route create/get/replace/delete/resources
through ClusterUser to make the actor-vs-SUT boundary explicit. patchStatus
remains on the extension — it represents test infrastructure simulating another
system updating status subresources, not a user action.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Sam Barker <sam@quadrocket.co.uk>
create, get, replace, delete, and resources were all delegating to the
internal testActor. Now that all ITs use clusterUser() for user-side
operations, these delegation methods are dead code. patchStatus remains
— it represents test infrastructure, not a user action.

Also fixes missed operator.delete() calls in four ITs from the previous
migration commit.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Sam Barker <sam@quadrocket.co.uk>
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.

1 participant