Skip to content

SREP-3937: Add --hive-ocm-url flag to cluster resize infra for multi-env OCM support#868

Open
nephomaniac wants to merge 1 commit intoopenshift:masterfrom
nephomaniac:SREP-3937-resize-infra-multi-env-ocm
Open

SREP-3937: Add --hive-ocm-url flag to cluster resize infra for multi-env OCM support#868
nephomaniac wants to merge 1 commit intoopenshift:masterfrom
nephomaniac:SREP-3937-resize-infra-multi-env-ocm

Conversation

@nephomaniac
Copy link
Contributor

Summary

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

Changes

  • Added --hive-ocm-url optional flag to cluster resize infra 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'
  • Updated unit tests in infra_node_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 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 14, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98d62f8d-9e17-4e66-9a2f-d6abfa7592fa

📥 Commits

Reviewing files that changed from the base of the PR and between 5485f25 and 24e5982.

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

Walkthrough

Adds a new optional --hive-ocm-url CLI flag to the cluster resize infra command and a corresponding hiveOcmUrl field. Implements a multi-environment OCM flow when provided (separate target/hive OCM connections and hive admin client), includes validation, and preserves the original single-OCM behavior when omitted.

Changes

Cohort / File(s) Summary
Core Implementation
cmd/cluster/resize/infra_node.go
Added hiveOcmUrl string field and --hive-ocm-url flag. Implemented validation of the flag and a multi-environment OCM path that creates separate target and hive OCM connections, resolves cluster IDs via target OCM, constructs Kubernetes/hive admin clients appropriately, and retains the original single-OCM flow when the flag is empty. Updated logging and error messages.
Unit Tests
cmd/cluster/resize/infra_node_test.go
Added TestHiveOcmUrlValidation table-driven tests covering valid aliases (production, staging, integration), full URL forms, invalid environment error, and omitted/empty flag behavior; asserts error presence/absence via utils.ValidateAndResolveOcmUrl. (Note: test function appears duplicated in the diff.)
Documentation
docs/README.md, docs/osdctl_cluster_resize_infra.md
Documented the new optional --hive-ocm-url string flag, its accepted aliases (production, staging, integration) and default behavior (uses target cluster OCM when not provided).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 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.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

@openshift-ci-robot
Copy link

@nephomaniac: An error was encountered searching for bug SREP-3937 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-3937": GET https://issues.redhat.com/rest/api/2/issue/SREP-3937 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 resize infra command to enable multi-environment OCM support for staging/integration testing.

Changes

  • Added --hive-ocm-url optional flag to cluster resize infra 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'
  • Updated unit tests in infra_node_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.

@openshift-ci openshift-ci bot requested review from MateSaary and joshbranham March 14, 2026 01:36
@openshift-ci
Copy link
Contributor

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

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 (2)
cmd/cluster/resize/infra_node.go (2)

118-124: Use the resolved OCM URL for connection creation.

Line 120 resolves the input, but the resolved value is discarded and Line 149 still uses the raw flag string. Persisting the resolved value keeps validation and connection behavior strictly aligned.

Suggested change
 	// Validate --hive-ocm-url if provided
 	if r.hiveOcmUrl != "" {
-		_, err := utils.ValidateAndResolveOcmUrl(r.hiveOcmUrl)
+		resolvedHiveOcmURL, err := utils.ValidateAndResolveOcmUrl(r.hiveOcmUrl)
 		if err != nil {
 			return fmt.Errorf("invalid --hive-ocm-url: %w", err)
 		}
+		r.hiveOcmUrl = resolvedHiveOcmURL
 	}

Also applies to: 149-151

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

In `@cmd/cluster/resize/infra_node.go` around lines 118 - 124, The validation
discards the resolved OCM URL returned by utils.ValidateAndResolveOcmUrl and
later code still uses the raw r.hiveOcmUrl when creating the connection; change
the validation call in the infra node flow to capture the resolved value (e.g.,
resolvedHiveOcmUrl, or overwrite r.hiveOcmUrl) and then use that resolved value
when constructing the connection (the code that currently references
r.hiveOcmUrl for connection creation). Ensure you call
utils.ValidateAndResolveOcmUrl only once, persist its returned URL, and pass
that persisted resolved URL into the connection creation code paths that
currently read r.hiveOcmUrl.

141-221: Reduce duplicated client/bootstrap logic across both paths.

The two branches repeat most setup steps (cluster lookup, r.clusterId assignment, client creation, admin client creation). Extracting shared setup into helpers will lower drift risk and make future changes safer.

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

In `@cmd/cluster/resize/infra_node.go` around lines 141 - 221, The two branches
for r.hiveOcmUrl share cluster lookup, r.clusterId assignment and k8s client
creation; extract that shared setup into helper(s). Create a helper like
prepareClusterAndClients(targetConn utils.OCMConnection, hiveConn
utils.OCMConnection, hiveOcmUrl string) (or two helpers: one to resolve cluster
via utils.GetClusterAnyStatus and set r.cluster/r.clusterId, and one to create
k8s clients) that calls utils.GetClusterAnyStatus, assigns r.cluster and
r.clusterId, and returns c, hc, hac (or returns error). In the hive-path call
utils.CreateConnection and utils.CreateConnectionWithUrl and pass both conns and
hiveOcmUrl into the helper so it can choose k8s.NewWithConn /
k8s.NewAsBackplaneClusterAdminWithConn (preserving error wrapping with the
hiveOcmUrl); in the non-hive path call utils.CreateConnection and pass nil
hiveConn so the helper uses k8s.New / k8s.NewAsBackplaneClusterAdmin. Ensure all
original error messages that referenced r.hiveOcmUrl remain when hiveOcmUrl is
non-empty.
🤖 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/resize/infra_node_test.go`:
- Around line 507-572: Test Hive OCM URL validation is calling
utils.ValidateAndResolveOcmUrl directly and expects empty input to error, but
Infra.New() treats an empty --hive-ocm-url as optional; update
TestHiveOcmUrlValidation to exercise the same path as the command by invoking
Infra.New() (or a thin wrapper that mirrors its preflight behavior) instead of
calling utils.ValidateAndResolveOcmUrl directly, adjust the test cases so empty
hiveOcmUrl expects no error, and remove the redundant conditional that calls
ValidateAndResolveOcmUrl twice; reference TestHiveOcmUrlValidation, Infra.New,
and utils.ValidateAndResolveOcmUrl when making the change.

---

Nitpick comments:
In `@cmd/cluster/resize/infra_node.go`:
- Around line 118-124: The validation discards the resolved OCM URL returned by
utils.ValidateAndResolveOcmUrl and later code still uses the raw r.hiveOcmUrl
when creating the connection; change the validation call in the infra node flow
to capture the resolved value (e.g., resolvedHiveOcmUrl, or overwrite
r.hiveOcmUrl) and then use that resolved value when constructing the connection
(the code that currently references r.hiveOcmUrl for connection creation).
Ensure you call utils.ValidateAndResolveOcmUrl only once, persist its returned
URL, and pass that persisted resolved URL into the connection creation code
paths that currently read r.hiveOcmUrl.
- Around line 141-221: The two branches for r.hiveOcmUrl share cluster lookup,
r.clusterId assignment and k8s client creation; extract that shared setup into
helper(s). Create a helper like prepareClusterAndClients(targetConn
utils.OCMConnection, hiveConn utils.OCMConnection, hiveOcmUrl string) (or two
helpers: one to resolve cluster via utils.GetClusterAnyStatus and set
r.cluster/r.clusterId, and one to create k8s clients) that calls
utils.GetClusterAnyStatus, assigns r.cluster and r.clusterId, and returns c, hc,
hac (or returns error). In the hive-path call utils.CreateConnection and
utils.CreateConnectionWithUrl and pass both conns and hiveOcmUrl into the helper
so it can choose k8s.NewWithConn / k8s.NewAsBackplaneClusterAdminWithConn
(preserving error wrapping with the hiveOcmUrl); in the non-hive path call
utils.CreateConnection and pass nil hiveConn so the helper uses k8s.New /
k8s.NewAsBackplaneClusterAdmin. Ensure all original error messages that
referenced r.hiveOcmUrl remain when hiveOcmUrl is non-empty.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b56f40e0-9f36-488b-af3b-8e0dc3a6f6e6

📥 Commits

Reviewing files that changed from the base of the PR and between 71e44ff and 5485f25.

📒 Files selected for processing (4)
  • cmd/cluster/resize/infra_node.go
  • cmd/cluster/resize/infra_node_test.go
  • docs/README.md
  • docs/osdctl_cluster_resize_infra.md

@nephomaniac nephomaniac force-pushed the SREP-3937-resize-infra-multi-env-ocm branch from 5485f25 to 24e5982 Compare March 17, 2026 01:52
@nephomaniac
Copy link
Contributor Author

/retest

1 similar comment
@nephomaniac
Copy link
Contributor Author

/retest

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

@nephomaniac
Copy link
Contributor Author

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 18, 2026
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.

2 participants