Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

NO-ISSUE: Remove SystemTenancyLogic in favor of DefaultTenancyLogic - #439

Merged
openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
jhernand:remove_system_tenancy_logic
Apr 24, 2026
Merged

openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
jhernand:remove_system_tenancy_logic

Conversation

@jhernand

@jhernand jhernand commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Remove SystemTenancyLogic and use DefaultTenancyLogic for both public and private APIs,
    eliminating the separate tenancy logic that was previously used for the private API.
  • Update DefaultTenancyLogic.DetermineDefaultTenants to return the shared tenant when the
    subject has access to all tenants (universal set), since an infinite set cannot be stored as
    the tenants of an object.
  • Replace SystemTenancyLogic and SystemAttributionLogic usages in tests with mocks,
    and add auth subject context where needed.

Test plan

  • Unit tests updated for DefaultTenancyLogic to verify shared tenant behavior
  • Verify ginkgo run -r internal passes
  • Verify integration tests pass

Summary by CodeRabbit

  • Refactor

    • Consolidated tenancy logic handling and simplified system architecture.
    • Updated default tenant selection behavior for improved consistency.
  • Tests

    • Enhanced test infrastructure with improved mocking and context injection for authentication scenarios.

The `SystemTenancyLogic` was a separate implementation used by the
private API and controllers that bypassed tenant filtering entirely. Now
that admin users receive the universal tenant set from Authorino (via
the `["*"]` value), the `DefaultTenancyLogic` can handle both regular
users and admins uniformly.

`DetermineDefaultTenants` now falls back to `SharedTenants` when the
subject's tenant set is universal, since an infinite set cannot be
stored as an object's tenants. This preserves the old
`SystemTenancyLogic` behavior where objects created through the private
API defaulted to the shared tenant.

All server tests are updated to set a system subject with universal
tenants in the context, which was previously unnecessary because
`SystemTenancyLogic` ignored the context entirely.

Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
@openshift-ci-robot

Copy link
Copy Markdown

@jhernand: This pull request explicitly references no jira issue.

Details

In response to this:

Summary

  • Remove SystemTenancyLogic and use DefaultTenancyLogic for both public and private APIs,
    eliminating the separate tenancy logic that was previously used for the private API.
  • Update DefaultTenancyLogic.DetermineDefaultTenants to return the shared tenant when the
    subject has access to all tenants (universal set), since an infinite set cannot be stored as
    the tenants of an object.
  • Replace SystemTenancyLogic and SystemAttributionLogic usages in tests with mocks,
    and add auth subject context where needed.

Test plan

  • Unit tests updated for DefaultTenancyLogic to verify shared tenant behavior
  • Verify ginkgo run -r internal passes
  • Verify integration tests pass

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from eranco74 and trewest April 23, 2026 16:01
@coderabbitai

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Walkthrough

This pull request removes the SystemTenancyLogic implementation and consolidates tenancy logic across the codebase. Key changes include: deletion of internal/auth/system_tenancy_logic.go and its tests; updates to DetermineDefaultTenants to return SharedTenants instead of a universal set when assignable tenants are infinite; replacement of separate public/private tenancy logic instances with a single shared instance in the gRPC server startup; and updates to multiple test files to inject authenticated subjects via auth.ContextWithSubject and mock auth dependencies using gomock instead of concrete system logic implementations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

approved

Suggested reviewers

  • omer-vishlitzky
  • tzvatot
  • eranco74
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: removing SystemTenancyLogic and consolidating to DefaultTenancyLogic, which is the primary objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (2)
internal/cmd/service/start/grpcserver/start_grpc_server_cmd.go (1)

346-373: Nit: stale "public" label now that tenancy logic is shared.

tenancyLogic is now wired into both public and private server builders (clusters, hubs, leases, events, …), but the surrounding comment (// Create the public tenancy logic:) and log message ("Creating public tenancy logic") still describe it as public-only. Consider generalizing for clarity.

✏️ Proposed wording tweak
-	// Create the public tenancy logic:
+	// Create the tenancy logic (shared by public and private servers):
 	c.logger.InfoContext(
 		ctx,
-		"Creating public tenancy logic",
+		"Creating tenancy logic",
 		slog.String("type", c.args.tenancyLogic),
 	)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/cmd/service/start/grpcserver/start_grpc_server_cmd.go` around lines
346 - 373, The comment and log call misleadingly say "public" even though the
tenancyLogic (variable tenancyLogic built via
auth.NewDefaultTenancyLogic()/auth.NewGuestTenancyLogic() and keyed by
c.args.tenancyLogic) is shared across public and private builders; update the
inline comment and the c.logger.InfoContext message to a generalized phrase such
as "Creating tenancy logic" or "Creating shared tenancy logic" (leave the switch
and error handling unchanged) so log and comment match actual usage.
internal/servers/servers_suite_test.go (1)

65-74: Optional: suite-default mock diverges from real DefaultTenancyLogic.

With DetermineAssignableTenants returning a universal set, the real DefaultTenancyLogic.DetermineDefaultTenants would now return SharedTenants, but this suite-level default returns NewSet("system"). Tests that exercise default-tenant assignment through the suite mock (rather than their own local mock) could therefore pass assertions that wouldn't hold in production. Consider aligning the default to SharedTenants (or a value derived from the assignable mock) so suite-wide behavior better mirrors runtime.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/servers/servers_suite_test.go` around lines 65 - 74, The suite-level
mock for auth.TenancyLogic diverges from the real DefaultTenancyLogic by
returning NewUniversalSet for DetermineAssignableTenants while
DetermineDefaultTenants returns NewSet("system"); update the mock so
DetermineDefaultTenants returns the same SharedTenants set the real
DefaultTenancyLogic would derive (or compute it from the mocked
DetermineAssignableTenants result) instead of NewSet("system"), i.e. change the
tenancy.EXPECT().DetermineDefaultTenants(...) stub to return SharedTenants (or a
value built from collections.NewUniversalSet[string]()) so suite behavior
matches DefaultTenancyLogic's runtime behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@internal/cmd/service/start/grpcserver/start_grpc_server_cmd.go`:
- Around line 346-373: The comment and log call misleadingly say "public" even
though the tenancyLogic (variable tenancyLogic built via
auth.NewDefaultTenancyLogic()/auth.NewGuestTenancyLogic() and keyed by
c.args.tenancyLogic) is shared across public and private builders; update the
inline comment and the c.logger.InfoContext message to a generalized phrase such
as "Creating tenancy logic" or "Creating shared tenancy logic" (leave the switch
and error handling unchanged) so log and comment match actual usage.

In `@internal/servers/servers_suite_test.go`:
- Around line 65-74: The suite-level mock for auth.TenancyLogic diverges from
the real DefaultTenancyLogic by returning NewUniversalSet for
DetermineAssignableTenants while DetermineDefaultTenants returns
NewSet("system"); update the mock so DetermineDefaultTenants returns the same
SharedTenants set the real DefaultTenancyLogic would derive (or compute it from
the mocked DetermineAssignableTenants result) instead of NewSet("system"), i.e.
change the tenancy.EXPECT().DetermineDefaultTenants(...) stub to return
SharedTenants (or a value built from collections.NewUniversalSet[string]()) so
suite behavior matches DefaultTenancyLogic's runtime behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 336e2d6f-5ed2-4e1c-92ef-f15e0e0eab68

📥 Commits

Reviewing files that changed from the base of the PR and between 9ffcc18 and 2f442fc.

📒 Files selected for processing (12)
  • internal/auth/default_tenancy_logic.go
  • internal/auth/default_tenancy_logic_test.go
  • internal/auth/system_tenancy_logic.go
  • internal/auth/system_tenancy_logic_test.go
  • internal/cmd/service/start/grpcserver/start_grpc_server_cmd.go
  • internal/coordination/leader_elector_test.go
  • internal/servers/clusters_server_test.go
  • internal/servers/private_hubs_server_test.go
  • internal/servers/servers_suite_test.go
  • internal/servers/servers_tenancy_test.go
  • internal/servers/subnets_server_test.go
  • internal/servers/virtual_networks_server_test.go
💤 Files with no reviewable changes (2)
  • internal/auth/system_tenancy_logic_test.go
  • internal/auth/system_tenancy_logic.go

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

@openshift-ci

openshift-ci Bot commented Apr 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CrystalChun, jhernand

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants