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

Walkthrough

Adds an optional --hive-ocm-url flag and multi-environment initialization path to the cluster resync command. When set, Resync initializes separate OCM connections (target and hive), resolves the hive cluster, creates a hive k8s client, and routes deletion readiness through initWithMultiEnv; previous behavior remains when unset.

Changes

Cohort / File(s) Summary
Core Implementation
cmd/cluster/resync.go
Added hiveOcmUrl string field on Resync, new --hive-ocm-url CLI flag, and initWithMultiEnv(scheme *runtime.Scheme) error method to create separate OCM clients, resolve hive cluster mapping, and construct a hive Kubernetes client.
Tests
cmd/cluster/resync_test.go
New unit test TestHiveOcmUrlValidation validating hive OCM URL resolution and error handling for environment names, full URLs, and invalid/empty inputs via utils.ValidateAndResolveOcmUrl.
Documentation
docs/README.md, docs/osdctl_cluster_resync.md
Documented the new --hive-ocm-url flag (aliases: production, staging, integration), added example usage and notes about optional behavior and defaulting to target OCM when not provided.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 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

Comment on lines +45 to +60
name: "Empty hive-ocm-url",
hiveOcmUrl: "",
expectErr: true,
errContains: "empty OCM URL",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// This simulates the validation that occurs in the Resync.New() method
var err error
if tt.hiveOcmUrl != "" {
_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
} else {
_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Test logic for empty hiveOcmUrl does not match command behavior.

In cmd/cluster/resync.go, Line 76 validates only when the flag is non-empty. This test currently expects an error for empty input and Lines 56-60 call validation unconditionally (identical if/else), so it doesn’t actually simulate Resync.New() and can mask regressions in backward-compatible behavior.

Suggested test correction
 		{
-			name:        "Empty hive-ocm-url",
-			hiveOcmUrl:  "",
-			expectErr:   true,
-			errContains: "empty OCM URL",
+			name:       "Empty hive-ocm-url (flag omitted)",
+			hiveOcmUrl: "",
+			expectErr:  false,
 		},
 	}
@@
-			var err error
-			if tt.hiveOcmUrl != "" {
-				_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
-			} else {
-				_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
-			}
+			var err error
+			// Mirrors Resync.New(): validate only when flag is provided.
+			if tt.hiveOcmUrl != "" {
+				_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
+			}
As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: "Empty hive-ocm-url",
hiveOcmUrl: "",
expectErr: true,
errContains: "empty OCM URL",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// This simulates the validation that occurs in the Resync.New() method
var err error
if tt.hiveOcmUrl != "" {
_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
} else {
_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
}
name: "Empty hive-ocm-url (flag omitted)",
hiveOcmUrl: "",
expectErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// This simulates the validation that occurs in the Resync.New() method
var err error
// Mirrors Resync.New(): validate only when flag is provided.
if tt.hiveOcmUrl != "" {
_, err = utils.ValidateAndResolveOcmUrl(tt.hiveOcmUrl)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/cluster/resync_test.go` around lines 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().

Comment on lines 33 to 37
```
-C, --cluster-id string OCM internal/external cluster id or cluster name to delete the clustersync for.
-h, --help help for resync
-C, --cluster-id string OCM internal/external cluster id or cluster name to delete the clustersync for.
-h, --help help for resync
--hive-ocm-url string (optional) OCM environment URL for hive operations. Aliases: 'production', 'staging', 'integration'. If not specified, uses the same OCM environment as the target cluster.
```
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add a language identifier to the fenced Options block.

markdownlint MD040 is triggered at Line 33 because the fence has no language token.

Suggested doc fix
-```
+```text
  -C, --cluster-id string     OCM internal/external cluster id or cluster name to delete the clustersync for.
  -h, --help                  help for resync
      --hive-ocm-url string   (optional) OCM environment URL for hive operations. Aliases: 'production', 'staging', 'integration'. If not specified, uses the same OCM environment as the target cluster.
</details>

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.21.0)</summary>

[warning] 33-33: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

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 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.


</details>

<!-- fingerprinting:phantom:poseidon:hawk -->

<!-- This is an auto-generated comment by CodeRabbit -->

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 14, 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.

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