Skip to content

fix: support PSC cluster cleanup in break-glass #929

Open
RaphaelBut wants to merge 1 commit into
openshift:masterfrom
RaphaelBut:fix-rosaeng-16043
Open

fix: support PSC cluster cleanup in break-glass #929
RaphaelBut wants to merge 1 commit into
openshift:masterfrom
RaphaelBut:fix-rosaeng-16043

Conversation

@RaphaelBut

@RaphaelBut RaphaelBut commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

break-glass cleanup was not detecting GCP Private Service Connect (PSC) clusters, causing it to fall through to the local KUBECONFIG path instead of cleaning up jump pods on hive.
Also adds --hive-ocm-url flag to the cleanup subcommand so it can connect to the correct hive shard when a non-default OCM environment was used during break-glass. ( needed for testing in stage or if we would actually want to breakglass in stage at some point )

https://redhat.atlassian.net/browse/ROSAENG-16042

Summary by CodeRabbit

  • New Features

    • Added support for cleaning up both PrivateLink and PSC clusters.
    • Added an option to point cleanup and access commands at a specific Hive OCM URL.
  • Bug Fixes

    • Improved error messages with a helpful hint when Hive shard access or login fails.
    • Validates cluster IDs and Hive URL input before cleanup continues.
  • Tests

    • Expanded cleanup coverage for PSC clusters and Hive URL validation.

@openshift-ci openshift-ci Bot requested review from Tafhim and typeid July 6, 2026 12:56
@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RaphaelBut

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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@RaphaelBut, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 20 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: bba6d72f-1463-4ba2-9dab-3b1c426c66e4

📥 Commits

Reviewing files that changed from the base of the PR and between 4c1cffe and 3376ec8.

📒 Files selected for processing (5)
  • cmd/cluster/access/access.go
  • cmd/cluster/access/cleanup.go
  • cmd/cluster/access/cleanup_test.go
  • docs/README.md
  • docs/osdctl_cluster_break-glass_cleanup.md

Walkthrough

This PR adds hint messages for hive shard access failures in the access command, and extends the cluster cleanup command to support Private Service Connect (PSC) clusters alongside PrivateLink, introducing a --hive-ocm-url flag for resolving a Hive client used for pod listing, deletion, and termination polling, plus corresponding tests.

Changes

Hive access hints and PSC cleanup support

Layer / File(s) Summary
Access command hint messages
cmd/cluster/access/access.go
Adds hint messages guiding use of --hive-ocm-url on hive shard retrieval and login failures.
Cleanup command flags and imports
cmd/cluster/access/cleanup.go
Adds OCM SDK and scheme imports, updates long description and --reason help text for PrivateLink/PSC, and adds a new --hive-ocm-url flag.
Cleanup completion validation
cmd/cluster/access/cleanup.go
Validates --cluster-id and, when set, validates/resolves --hive-ocm-url; adds hiveOcmUrl field to the options struct.
PSC/PrivateLink cleanup execution with Hive client
cmd/cluster/access/cleanup.go
Detects PSC clusters, routes PrivateLink/PSC clusters through an updated cleanup path using a Hive client (via --hive-ocm-url or impersonation), and switches pod listing/deletion/polling to use the Hive client.
Cleanup tests for PSC and Hive URL validation
cmd/cluster/access/cleanup_test.go
Updates existing test call signature, adds PSC cleanup test with fake client fixtures, adds Hive OCM URL validation tests, and adds a PSC test-object generator helper.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant cleanupCmd as cleanupAccessOptions
  participant HiveOCM as Hive OCM Connection
  participant HiveClient
  participant KubeClient

  User->>cleanupCmd: run cleanup (--hive-ocm-url, --cluster-id)
  cleanupCmd->>cleanupCmd: detect PSC or PrivateLink cluster
  alt hive-ocm-url provided
    cleanupCmd->>HiveOCM: resolve hive shard connection
    HiveOCM-->>cleanupCmd: backplane cluster-admin elevation
    cleanupCmd->>HiveClient: create Hive client
  else no hive-ocm-url
    cleanupCmd->>KubeClient: derive client with impersonation
  end
  cleanupCmd->>HiveClient: list jump pods
  cleanupCmd->>HiveClient: delete jump pods
  cleanupCmd->>HiveClient: poll pod termination
  HiveClient-->>cleanupCmd: termination status
  cleanupCmd-->>User: cleanup result
Loading

Related PRs: None identified.

Suggested labels: enhancement, tests

Suggested reviewers: None identified.

🐰 A rabbit hops through hive and shard,
PSC and PrivateLink, now both starred,
With hints to guide when URLs go astray,
And tests that seed pods along the way,
Cleanup's burrow grows deep and wide today.

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: break-glass cleanup now supports PSC clusters.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Stable And Deterministic Test Names ✅ Passed cleanup_test.go uses plain t.Run names only; no It/Describe/Context/When blocks or dynamic identifiers were added.
Test Structure And Quality ✅ Passed This package uses plain table-driven Go tests, not Ginkgo; cases are isolated, create no persistent cluster resources, avoid waits, and include contextual failure messages.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; cleanup_test.go uses standard testing with fake clients and no MicroShift-unsupported OpenShift APIs/features.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests were added; cleanup_test.go contains only unit tests with fake clients and no multi-node/SNO assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed Only CLI cleanup/access code and tests changed; no manifests, replicas, affinity, topology spread, or node selectors were introduced.
Ote Binary Stdout Contract ✅ Passed PASS: The new hint messages use Errorln (ErrOut), and no main/init/TestMain/RunSpecs setup was added in the touched files.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added tests are plain unit tests; no Ginkgo e2e blocks, IPv4-specific assumptions, or external connectivity were introduced.
No-Weak-Crypto ✅ Passed Searched changed files and related helpers; found no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret/token comparisons.
Container-Privileges ✅ Passed Diff only adds CLI validation/hints and PSC cleanup logic; no container/K8s manifests or securityContext changes.
No-Sensitive-Data-In-Logs ✅ Passed New log output is a generic --hive-ocm-url hint; it doesn’t print secrets, tokens, PII, or hostnames beyond existing cluster/path details.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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 (4)
cmd/cluster/access/cleanup.go (2)

146-146: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

hiveOCM.Close() error is discarded.

The primary connection at Line 116 wraps conn.Close() in cmdutil.CheckErr, but this deferred close silently drops its error. Consider handling it consistently (e.g. defer func(){ cmdutil.CheckErr(hiveOCM.Close()) }()).

As per path instructions: "Never ignore error returns".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/cluster/access/cleanup.go` at line 146, The deferred close in cleanup
logic discards the error returned by hiveOCM.Close(), unlike the earlier
connection close handled with cmdutil.CheckErr. Update the defer in the cleanup
flow to call hiveOCM.Close() through an inline deferred function and pass its
error to cmdutil.CheckErr, keeping the handling consistent with the existing
close behavior in the same command path.

Source: Path instructions


153-153: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

fmt.Sprintf with no format arguments.

Both calls pass a constant string with no verbs/args; staticcheck flags this (S1039) and it may fail CI lint. Use the string literal directly.

♻️ Proposed change
-		hiveClient, err = k8s.NewAsBackplaneClusterAdminWithConn(hive.ID(), kclient.Options{Scheme: scheme.Scheme}, hiveOCM, c.reason, fmt.Sprintf("Elevation required to clean break-glass on PrivateLink/PSC Clusters"))
+		hiveClient, err = k8s.NewAsBackplaneClusterAdminWithConn(hive.ID(), kclient.Options{Scheme: scheme.Scheme}, hiveOCM, c.reason, "Elevation required to clean break-glass on PrivateLink/PSC Clusters")
-		c.kubeCli.Impersonate("backplane-cluster-admin", c.reason, fmt.Sprintf("Elevation required to clean break-glass on PrivateLink/PSC Clusters"))
+		c.kubeCli.Impersonate("backplane-cluster-admin", c.reason, "Elevation required to clean break-glass on PrivateLink/PSC Clusters")

Also applies to: 158-158

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/cluster/access/cleanup.go` at line 153, The calls in the cleanup flow are
using fmt.Sprintf with a constant string and no formatting arguments, which
triggers the lint issue. In cleanup.go, update the
k8s.NewAsBackplaneClusterAdminWithConn calls in the cleanup path to pass the
string literal directly instead of wrapping it in fmt.Sprintf, keeping the
existing hive.ID(), kclient.Options, hiveOCM, and c.reason arguments unchanged.
cmd/cluster/access/cleanup_test.go (2)

140-234: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

PSC test doesn't exercise the new PSC-detection logic.

dropPrivateLinkAccess only uses cluster.ID(); the PSC predicate cluster.GCP().PrivateServiceConnect().ServiceAttachmentSubnet() != "" lives in Run() (cleanup.go Line 124), which this test never calls. As written, TestCleanupAccessOptions_dropPscAccess is functionally identical to the PrivateLink test and gives no coverage of the actual detection change. Consider a focused table test asserting the predicate against both PSC and non-PSC cluster objects.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/cluster/access/cleanup_test.go` around lines 140 - 234, The PSC cleanup
test currently bypasses the new detection path and only exercises
dropPrivateLinkAccess, so it does not verify the
cluster.GCP().PrivateServiceConnect().ServiceAttachmentSubnet() check used by
Run(). Update TestCleanupAccessOptions_dropPscAccess to target the PSC predicate
directly or through Run(), and add table coverage for both PSC and non-PSC
cluster objects using generatePscClusterObjectForTesting and a non-PSC
equivalent so the new branching logic is actually validated.

246-259: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Empty-URL case is a no-op assertion.

The "Empty (flag omitted)" row never reaches ValidateAndResolveOcmUrl because of the if tt.hiveOcmUrl != "" guard at Line 251, so it asserts nothing. To meaningfully cover the empty path (which mirrors cleanupCmdComplete's skip behavior), drive the test through cleanupCmdComplete or assert the skip explicitly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/cluster/access/cleanup_test.go` around lines 246 - 259, The "Empty (flag
omitted)" test case in cleanup_test.go is not exercising any behavior because
the tt.hiveOcmUrl guard skips the ValidateAndResolveOcmUrl call entirely. Update
the test around cleanupCmdComplete and the ValidateAndResolveOcmUrl path so the
empty-URL case is asserted explicitly, matching the skip behavior when the flag
is omitted. Use the cleanupCmdComplete test flow (or an equivalent direct
assertion) to verify that an empty hive-ocm-url results in no resolution attempt
and no error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/cluster/access/cleanup_test.go`:
- Around line 140-234: The PSC cleanup test currently bypasses the new detection
path and only exercises dropPrivateLinkAccess, so it does not verify the
cluster.GCP().PrivateServiceConnect().ServiceAttachmentSubnet() check used by
Run(). Update TestCleanupAccessOptions_dropPscAccess to target the PSC predicate
directly or through Run(), and add table coverage for both PSC and non-PSC
cluster objects using generatePscClusterObjectForTesting and a non-PSC
equivalent so the new branching logic is actually validated.
- Around line 246-259: The "Empty (flag omitted)" test case in cleanup_test.go
is not exercising any behavior because the tt.hiveOcmUrl guard skips the
ValidateAndResolveOcmUrl call entirely. Update the test around
cleanupCmdComplete and the ValidateAndResolveOcmUrl path so the empty-URL case
is asserted explicitly, matching the skip behavior when the flag is omitted. Use
the cleanupCmdComplete test flow (or an equivalent direct assertion) to verify
that an empty hive-ocm-url results in no resolution attempt and no error.

In `@cmd/cluster/access/cleanup.go`:
- Line 146: The deferred close in cleanup logic discards the error returned by
hiveOCM.Close(), unlike the earlier connection close handled with
cmdutil.CheckErr. Update the defer in the cleanup flow to call hiveOCM.Close()
through an inline deferred function and pass its error to cmdutil.CheckErr,
keeping the handling consistent with the existing close behavior in the same
command path.
- Line 153: The calls in the cleanup flow are using fmt.Sprintf with a constant
string and no formatting arguments, which triggers the lint issue. In
cleanup.go, update the k8s.NewAsBackplaneClusterAdminWithConn calls in the
cleanup path to pass the string literal directly instead of wrapping it in
fmt.Sprintf, keeping the existing hive.ID(), kclient.Options, hiveOCM, and
c.reason arguments unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e5f34771-4960-4549-9cdb-9f27b911e5b9

📥 Commits

Reviewing files that changed from the base of the PR and between 581f65e and 4c1cffe.

📒 Files selected for processing (3)
  • cmd/cluster/access/access.go
  • cmd/cluster/access/cleanup.go
  • cmd/cluster/access/cleanup_test.go

…l flag

break-glass cleanup was not detecting GCP Private Service Connect (PSC)
clusters, causing it to fall through to the local KUBECONFIG path instead
of cleaning up jump pods on hive. Also adds --hive-ocm-url flag to the
cleanup subcommand so it can connect to the correct hive shard when a
non-default OCM environment was used during break-glass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@RaphaelBut RaphaelBut force-pushed the fix-rosaeng-16043 branch from 4c1cffe to 3376ec8 Compare July 6, 2026 13:35
@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@RaphaelBut: all tests passed!

Full PR test history. Your PR dashboard.

Details

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

if cluster.AWS().PrivateLink() {
return c.dropPrivateLinkAccess(cluster)
isPscCluster := cluster.GCP().PrivateServiceConnect().ServiceAttachmentSubnet() != ""
if cluster.AWS().PrivateLink() || isPscCluster {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this was the missing part to do the cleanup
the rest of the PR adds the multi env hive-ocm-url support to test/make this possible in stage

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant