Skip to content

SREP-3896: Add --hive-ocm-url flag to cluster resync for multi-env OCM support#866

Open
nephomaniac wants to merge 1 commit intoopenshift:masterfrom
nephomaniac:SREP-3896-resync-multi-env-ocm
Open

SREP-3896: Add --hive-ocm-url flag to cluster resync for multi-env OCM support#866
nephomaniac wants to merge 1 commit intoopenshift:masterfrom
nephomaniac:SREP-3896-resync-multi-env-ocm

Conversation

@nephomaniac
Copy link
Contributor

@nephomaniac nephomaniac commented Mar 13, 2026

Summary

Adds --hive-ocm-url flag to osdctl cluster resync command to enable multi-environment OCM support for staging/integration testing.

Changes

  • Added --hive-ocm-url optional flag to cluster resync command
  • Implements conditional logic to use separate OCM connections for target cluster and hive when flag is provided
  • Added early validation in New() method to fail fast on invalid OCM URLs
  • Preserves backward compatibility - original code path unchanged when flag not provided
  • Supports OCM URL aliases: 'production', 'staging', 'integration'
  • Added unit tests in resync_test.go to verify early validation behavior

Implementation Details

When --hive-ocm-url is specified:

  1. Creates separate OCM connection for hive using utils.CreateConnectionWithUrl()
  2. Uses utils.GetHiveClusterWithConn() to query hive from different OCM environment
  3. Creates hive k8s client with k8s.NewWithConn()
  4. Validates OCM URL early using utils.ValidateAndResolveOcmUrl()

Testing

  • ✅ Tested in staging environment with valid --hive-ocm-url values
  • ✅ Tested in production environment with valid --hive-ocm-url values
  • ✅ Validated early failure with invalid --hive-ocm-url values
  • ✅ Backward compatibility verified (command works without --hive-ocm-url flag)
  • ✅ Unit tests passing (including new tests for validation logic)

Related

Note

This PR is part of a series adding multi-environment OCM support to osdctl commands. Will place on hold until the common implementation pattern can be reviewed across all related PRs.

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

@openshift-ci-robot
Copy link

@nephomaniac: An error was encountered searching for bug SREP-3896 on the Jira server at https://issues.redhat.com. No known errors were detected, please see the full error message for details.

Full error message. No response returned: Get "https://issues.redhat.com/rest/api/2/issue/SREP-3896": GET https://issues.redhat.com/rest/api/2/issue/SREP-3896 giving up after 5 attempt(s)

Please contact an administrator to resolve this issue, then request a bug refresh with /jira refresh.

Details

In response to this:

Summary

Adds --hive-ocm-url flag to osdctl cluster resync command to enable multi-environment OCM support for staging/integration testing.

Changes

  • Added --hive-ocm-url optional flag to cluster resync command
  • Implements conditional logic to use separate OCM connections for target cluster and hive when flag is provided
  • Added early validation in New() method to fail fast on invalid OCM URLs
  • Preserves backward compatibility - original code path unchanged when flag not provided
  • Supports OCM URL aliases: 'production', 'staging', 'integration'

Implementation Details

When --hive-ocm-url is specified:

  1. Creates separate OCM connection for hive using utils.CreateConnectionWithUrl()
  2. Uses utils.GetHiveClusterWithConn() to query hive from different OCM environment
  3. Creates hive k8s client with k8s.NewWithConn()
  4. Validates OCM URL early using utils.ValidateAndResolveOcmUrl()

Testing

  • ✅ Tested in staging environment with valid --hive-ocm-url values
  • ✅ Tested in production environment with valid --hive-ocm-url values
  • ✅ Validated early failure with invalid --hive-ocm-url values
  • ✅ Backward compatibility verified (command works without --hive-ocm-url flag)

Related

Note

This PR is part of a series adding multi-environment OCM support to osdctl commands. Will place on hold until the common implementation pattern can be reviewed across all related PRs.

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

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.

@nephomaniac
Copy link
Contributor Author

Placing on hold until all the similar commands/PRs adding multiple OCM env support can have the common implementation pattern reviewed. Will unhold after the other PRs and general pattern get a chance for review.

/hold

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds an optional --hive-ocm-url flag and multi-environment initialization to the cluster resync command. When provided, Resync validates and resolves the hive OCM URL, creates separate OCM clients for target and hive, resolves the hive cluster mapping, and builds a hive Kubernetes client via a new initWithMultiEnv path; unchanged behavior when unset.

Changes

Cohort / File(s) Summary
Core Implementation
cmd/cluster/resync.go
Added hiveOcmUrl string field to Resync, new --hive-ocm-url CLI flag, and initWithMultiEnv(scheme *runtime.Scheme) error to validate/resolve the hive OCM URL, initialize separate OCM connections (target and hive), resolve the target→hive cluster, and create a hive Kubernetes client.
Tests
cmd/cluster/resync_test.go
Added TestHiveOcmUrlValidation to validate --hive-ocm-url inputs (aliases: production, staging, integration), full URLs, invalid values, and empty input; asserts expected errors or success via utils.ValidateAndResolveOcmUrl.
Documentation
docs/README.md, docs/osdctl_cluster_resync.md
Documented the new --hive-ocm-url option and aliases, added example usage showing resync with a different OCM/Hive environment, and clarified that the flag only affects Hive environment resolution while the target cluster uses the current/default OCM environment.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@openshift-ci openshift-ci bot requested review from gvnnn and zmird-r March 13, 2026 23:36
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 13, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: nephomaniac
Once this PR has been reviewed and has the lgtm label, please assign bergmannf for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 13, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/cluster/resync.go (1)

83-87: Consider collapsing the init branching into one helper.

These new branches now mirror much of the legacy init flow with only the connection source differing. Keeping both paths separate makes future fixes easy to land in one branch but not the other.

As per coding guidelines, Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Also applies to: 116-156

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

In `@cmd/cluster/resync.go` around lines 83 - 87, The branching between the
multi-environment path (r.initWithMultiEnv) and the legacy init is duplicating
most of the init flow; refactor by extracting a single shared initializer that
accepts a connection/source provider and runs the common setup logic. Implement
a small helper (e.g., buildConnectionSource or getInitSource) that encapsulates
the differing parts (the hive OCM URL path vs. legacy connection creation) and
then call a single common init function (the current shared setup logic from
r.initWithMultiEnv / r.init) with that provider so all environment-specific
differences are isolated to the provider and the rest of the initialization is
unified.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/cluster/resync.go`:
- Around line 49-50: The example/help text for the resync command is misleading
about --hive-ocm-url; update the wording in the osdctl cluster resync
help/example so it explicitly states that the --hive-ocm-url flag only changes
which OCM endpoint is used to contact Hive and does NOT change how the target
cluster is resolved (New() still resolves the target cluster from the
current/default OCM connection). Mention this prerequisite and clarify that
cluster selection remains tied to the existing/default OCM client while only the
Hive side uses the provided URL.

---

Nitpick comments:
In `@cmd/cluster/resync.go`:
- Around line 83-87: The branching between the multi-environment path
(r.initWithMultiEnv) and the legacy init is duplicating most of the init flow;
refactor by extracting a single shared initializer that accepts a
connection/source provider and runs the common setup logic. Implement a small
helper (e.g., buildConnectionSource or getInitSource) that encapsulates the
differing parts (the hive OCM URL path vs. legacy connection creation) and then
call a single common init function (the current shared setup logic from
r.initWithMultiEnv / r.init) with that provider so all environment-specific
differences are isolated to the provider and the rest of the initialization is
unified.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f598db0b-edba-403a-a2b0-0a8f68474fb7

📥 Commits

Reviewing files that changed from the base of the PR and between 71e44ff and 314765f.

📒 Files selected for processing (3)
  • cmd/cluster/resync.go
  • docs/README.md
  • docs/osdctl_cluster_resync.md

@nephomaniac nephomaniac force-pushed the SREP-3896-resync-multi-env-ocm branch from 314765f to b1a86c4 Compare March 14, 2026 00:01
@openshift-ci-robot
Copy link

@nephomaniac: An error was encountered searching for bug SREP-3896 on the Jira server at https://issues.redhat.com. No known errors were detected, please see the full error message for details.

Full error message. No response returned: Get "https://issues.redhat.com/rest/api/2/issue/SREP-3896": GET https://issues.redhat.com/rest/api/2/issue/SREP-3896 giving up after 5 attempt(s)

Please contact an administrator to resolve this issue, then request a bug refresh with /jira refresh.

Details

In response to this:

Summary

Adds --hive-ocm-url flag to osdctl cluster resync command to enable multi-environment OCM support for staging/integration testing.

Changes

  • Added --hive-ocm-url optional flag to cluster resync command
  • Implements conditional logic to use separate OCM connections for target cluster and hive when flag is provided
  • Added early validation in New() method to fail fast on invalid OCM URLs
  • Preserves backward compatibility - original code path unchanged when flag not provided
  • Supports OCM URL aliases: 'production', 'staging', 'integration'
  • Added unit tests in resync_test.go to verify early validation behavior

Implementation Details

When --hive-ocm-url is specified:

  1. Creates separate OCM connection for hive using utils.CreateConnectionWithUrl()
  2. Uses utils.GetHiveClusterWithConn() to query hive from different OCM environment
  3. Creates hive k8s client with k8s.NewWithConn()
  4. Validates OCM URL early using utils.ValidateAndResolveOcmUrl()

Testing

  • ✅ Tested in staging environment with valid --hive-ocm-url values
  • ✅ Tested in production environment with valid --hive-ocm-url values
  • ✅ Validated early failure with invalid --hive-ocm-url values
  • ✅ Backward compatibility verified (command works without --hive-ocm-url flag)
  • ✅ Unit tests passing (including new tests for validation logic)

Related

Note

This PR is part of a series adding multi-environment OCM support to osdctl commands. Will place on hold until the common implementation pattern can be reviewed across all related PRs.

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/cluster/resync_test.go`:
- Around line 45-60: The test in resync_test.go incorrectly calls
utils.ValidateAndResolveOcmUrl unconditionally (the if/else blocks are
identical) and expects an error for an empty hiveOcmUrl, but Resync.New() only
validates when the flag is non-empty; update the test to mimic Resync.New():
call utils.ValidateAndResolveOcmUrl only when tt.hiveOcmUrl != "" (otherwise
skip validation) and adjust the test expectations for the empty hiveOcmUrl case
(set expectErr=false / remove errContains) so the test verifies the same
behavior as Resync.New().

In `@docs/osdctl_cluster_resync.md`:
- Around line 33-37: The fenced code block showing the CLI Options lacks a
language identifier and triggers markdownlint MD040; update the Options fenced
block in docs/osdctl_cluster_resync.md by adding a language token (e.g., use
```text) immediately after the opening backticks for the block containing the
three option lines so the block becomes a labeled code fence and resolves the
lint warning.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a8be291-a525-4990-883d-8ff4216c765b

📥 Commits

Reviewing files that changed from the base of the PR and between 314765f and b1a86c4.

📒 Files selected for processing (4)
  • cmd/cluster/resync.go
  • cmd/cluster/resync_test.go
  • docs/README.md
  • docs/osdctl_cluster_resync.md

@nephomaniac nephomaniac force-pushed the SREP-3896-resync-multi-env-ocm branch 2 times, most recently from 55e6c52 to 7df8eee Compare March 17, 2026 03:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/cluster/resync.go`:
- Around line 75-81: The validation call to ValidateAndResolveOcmUrl returns a
resolved URL but its value is discarded; capture that resolved value and use it
for the Hive connection instead of the original r.hiveOcmUrl. Specifically, in
the pre-check where ValidateAndResolveOcmUrl is called, assign the returned
string (e.g., resolvedOcmUrl) and either set r.hiveOcmUrl = resolvedOcmUrl or
pass resolvedOcmUrl into the later connection setup that currently references
r.hiveOcmUrl (ensure functions/config that use the Hive OCM URL use the resolved
variable).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e79b4492-f64c-49b2-8dfd-2ecfa47b9931

📥 Commits

Reviewing files that changed from the base of the PR and between 55e6c52 and 7df8eee.

📒 Files selected for processing (4)
  • cmd/cluster/resync.go
  • cmd/cluster/resync_test.go
  • docs/README.md
  • docs/osdctl_cluster_resync.md

@nephomaniac nephomaniac force-pushed the SREP-3896-resync-multi-env-ocm branch from 7df8eee to 6225a27 Compare March 17, 2026 05:14
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 17, 2026

@nephomaniac: 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
docs/osdctl_cluster_resync.md (1)

33-37: ⚠️ Potential issue | 🟡 Minor

Add a language identifier to the Options fenced block.

The fence is still unlabeled and triggers markdownlint MD040; use a labeled fence like ```text.

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

In `@docs/osdctl_cluster_resync.md` around lines 33 - 37, The fenced Options block
shown (the triple-backtick block containing the option lines "-C, --cluster-id
...", "-h, --help ...", and "--hive-ocm-url ...") lacks a language identifier
and triggers markdownlint MD040; update the opening fence from ``` to ```text
(i.e., label the code fence with "text") so the block becomes ```text and the
linter stops flagging it.
🧹 Nitpick comments (1)
cmd/cluster/resync.go (1)

90-157: Consider extracting shared init steps to reduce path drift.

The legacy path and initWithMultiEnv repeat core initialization steps (cluster resolution, Hive lookup, client assignment/logging). A shared helper would improve maintainability and reduce future divergence bugs.

As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."

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

In `@cmd/cluster/resync.go` around lines 90 - 157, The two init paths duplicate
cluster resolution, hive lookup and hive k8s client creation; extract these into
a shared helper (e.g., resolveClusterAndHive or initHiveClient) that accepts the
OCM connection(s) and clusterId and returns the resolved cluster (ID/Name), hive
name/ID and the k8s client; then have the legacy path (which uses
utils.CreateConnection, utils.GetClusterAnyStatus, utils.GetHiveCluster,
k8s.New) and initWithMultiEnv (which uses
CreateConnection/CreateConnectionWithUrl, utils.GetClusterAnyStatus,
utils.GetHiveClusterWithConn, k8s.NewWithConn) call that helper to perform the
common steps and only keep connection-creation/logging differences in each path
to eliminate duplication and reduce path drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@docs/osdctl_cluster_resync.md`:
- Around line 33-37: The fenced Options block shown (the triple-backtick block
containing the option lines "-C, --cluster-id ...", "-h, --help ...", and
"--hive-ocm-url ...") lacks a language identifier and triggers markdownlint
MD040; update the opening fence from ``` to ```text (i.e., label the code fence
with "text") so the block becomes ```text and the linter stops flagging it.

---

Nitpick comments:
In `@cmd/cluster/resync.go`:
- Around line 90-157: The two init paths duplicate cluster resolution, hive
lookup and hive k8s client creation; extract these into a shared helper (e.g.,
resolveClusterAndHive or initHiveClient) that accepts the OCM connection(s) and
clusterId and returns the resolved cluster (ID/Name), hive name/ID and the k8s
client; then have the legacy path (which uses utils.CreateConnection,
utils.GetClusterAnyStatus, utils.GetHiveCluster, k8s.New) and initWithMultiEnv
(which uses CreateConnection/CreateConnectionWithUrl, utils.GetClusterAnyStatus,
utils.GetHiveClusterWithConn, k8s.NewWithConn) call that helper to perform the
common steps and only keep connection-creation/logging differences in each path
to eliminate duplication and reduce path drift.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c62501ce-d7c0-498b-b323-63d6414a9df2

📥 Commits

Reviewing files that changed from the base of the PR and between 7df8eee and 6225a27.

📒 Files selected for processing (4)
  • cmd/cluster/resync.go
  • cmd/cluster/resync_test.go
  • docs/README.md
  • docs/osdctl_cluster_resync.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/cluster/resync_test.go
  • docs/README.md

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

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants