Skip to content

CNTRLPLANE-3890: Add product-cli unit tests for HCP create cluster - #9107

Open
mehabhalodiya wants to merge 1 commit into
openshift:mainfrom
mehabhalodiya:unittest_create
Open

CNTRLPLANE-3890: Add product-cli unit tests for HCP create cluster#9107
mehabhalodiya wants to merge 1 commit into
openshift:mainfrom
mehabhalodiya:unittest_create

Conversation

@mehabhalodiya

@mehabhalodiya mehabhalodiya commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

The four platforms — AWS, KubeVirt, OpenStack, and Agent — have no product-cli cluster creation tests at all.

What this PR does / why we need it:

File Subtests What's Tested
aws/create_test.go 10 Use field, release stream, region/volume/endpoint defaults, product credential flags, developer-only flag exclusion, pull-secret required, exact 25-flag enumeration
kubevirt/create_test.go 5 Use field, infra-kubeconfig-file, nodepool flags, developer-only flag exclusion, exact 17-flag enumeration
openstack/create_test.go 5 Use field, credential flags, cloud config flags, nodepool flags, exact 10-flag enumeration
agent/create_test.go 4 Use field, agent-namespace required, pull-secret required (with parent command), exact 3-flag enumeration

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/CNTRLPLANE-3890

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Tests
    • Added/expanded unit and manifest-rendering tests for cluster creation commands across agent, AWS, KubeVirt, OpenStack, and Azure.
    • Verified each create command’s identity plus key default values (including release stream–related behavior where applicable).
    • Confirmed correct inheritance of shared options such as pull-secret.
    • Ensured developer-only flags are excluded and validated the exact allowlisted set of user-facing flags (including required flag annotations for shell completion).
    • Compared rendered manifests against stored fixtures.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 24, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 24, 2026

Copy link
Copy Markdown

@mehabhalodiya: This pull request references CNTRLPLANE-3890 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

The four platforms — AWS, KubeVirt, OpenStack, and Agent — have no product-cli cluster creation tests at all.

What this PR does / why we need it:

File Subtests What's Tested
aws/create_test.go 10 Use field, release stream, region/volume/endpoint defaults, product credential flags, developer-only flag exclusion, pull-secret required, exact 25-flag enumeration
kubevirt/create_test.go 5 Use field, infra-kubeconfig-file, nodepool flags, developer-only flag exclusion, exact 17-flag enumeration
openstack/create_test.go 5 Use field, credential flags, cloud config flags, nodepool flags, exact 10-flag enumeration
agent/create_test.go 4 Use field, agent-namespace required, pull-secret required (with parent command), exact 3-flag enumeration

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/CNTRLPLANE-3890

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

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-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci openshift-ci Bot added do-not-merge/needs-area area/platform/aws PR/issue for AWS (AWSPlatform) platform area/platform/kubevirt PR/issue for KubeVirt (KubevirtPlatform) platform labels Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 66da9c8d-d0f1-448f-84c2-b20d566a58f4

📥 Commits

Reviewing files that changed from the base of the PR and between 6c759d7 and bc9800c.

⛔ Files ignored due to path filters (5)
  • product-cli/cmd/cluster/agent/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/aws/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/azure/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/kubevirt/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/openstack/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
📒 Files selected for processing (5)
  • product-cli/cmd/cluster/agent/create_test.go
  • product-cli/cmd/cluster/aws/create_test.go
  • product-cli/cmd/cluster/azure/create_test.go
  • product-cli/cmd/cluster/kubevirt/create_test.go
  • product-cli/cmd/cluster/openstack/create_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • product-cli/cmd/cluster/kubevirt/create_test.go
  • product-cli/cmd/cluster/aws/create_test.go
  • product-cli/cmd/cluster/agent/create_test.go
  • product-cli/cmd/cluster/openstack/create_test.go

📝 Walkthrough

Walkthrough

Adds Go tests for agent, AWS, Azure, KubeVirt, and OpenStack cluster creation. The tests validate command metadata, flag registration and defaults, required annotations, inheritance, developer-only flag exclusions, and exact flag sets. Rendering tests use deterministic inputs and temporary credential files, invoke cluster creation, and compare generated manifests with fixtures.

Suggested reviewers: cblecker, nirshal

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding product-cli unit tests for HCP create cluster.
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 No dynamic or generated test titles were added; the new tests use fixed literal t.Run names and no Ginkgo-style It/Describe strings.
Test Structure And Quality ✅ Passed PASS: These are table-driven unit tests with isolated setup/cleanup (t.TempDir/t.Setenv), no waits, and fixture patterns consistent with the codebase; Ginkgo-specific concerns don’t apply.
Topology-Aware Scheduling Compatibility ✅ Passed The PR only adds test files and golden fixtures; no deployment/operator code or topology-sensitive scheduling logic was introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Adds only stdlib unit tests in product-cli; no Ginkgo e2e specs, public-internet calls, or IPv6-sensitive networking logic were found.
No-Weak-Crypto ✅ Passed Only test files were added; no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret/token comparisons beyond normal test assertions.
Container-Privileges ✅ Passed No privileged, hostPID/Network/IPC, SYS_ADMIN, root, or allowPrivilegeEscalation settings appear in the changed tests or their golden manifests.
No-Sensitive-Data-In-Logs ✅ Passed The added tests contain no log/printf/t.Log calls; sensitive values are only written to temp files or passed as flags, not emitted.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci Bot added area/platform/openstack PR/issue for OpenStack (OpenStackPlatform) platform and removed do-not-merge/needs-area labels Jul 24, 2026
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mehabhalodiya
Once this PR has been reviewed and has the lgtm label, please assign devguyio, mandre, orenc1 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 requested review from Nirshal and cblecker July 24, 2026 17:38
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.65%. Comparing base (144cca9) to head (bc9800c).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9107      +/-   ##
==========================================
+ Coverage   44.51%   44.65%   +0.14%     
==========================================
  Files         774      774              
  Lines       96997    97098     +101     
==========================================
+ Hits        43179    43363     +184     
+ Misses      50830    50735      -95     
- Partials     2988     3000      +12     

see 14 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.39% <ø> (ø)
cpo-hostedcontrolplane 47.22% <ø> (ø)
cpo-other 45.25% <ø> (ø)
hypershift-operator 54.55% <ø> (+0.09%) ⬆️
other 33.76% <ø> (+1.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
product-cli/cmd/cluster/openstack/create_test.go (1)

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

Consider adding a developer-only flag exclusion subtest for consistency.

Agent, AWS, and KubeVirt sibling test files each assert specific developer-only flags are absent; this file doesn't. Optional for consistency across the cohort, not blocking.

🤖 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 `@product-cli/cmd/cluster/openstack/create_test.go` around lines 17 - 93,
Optionally add a developer-only flag exclusion subtest alongside the existing
NewCreateCommand flag tests, asserting the relevant developer-only flags are
absent for the OpenStack create command. Follow the corresponding exclusion
assertions in the Agent, AWS, and KubeVirt sibling tests while keeping the
existing expected-flags coverage unchanged.
🤖 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.

Inline comments:
In `@product-cli/cmd/cluster/agent/create_test.go`:
- Around line 44-62: The required-flag tests are vacuous because they mark
pull-secret on a synthetic parent instead of verifying command wiring. In
product-cli/cmd/cluster/agent/create_test.go lines 44-62 and
product-cli/cmd/cluster/aws/create_test.go lines 99-117, add each command to the
actual cluster parent setup, remove the test’s manual MarkPersistentFlagRequired
call, and assert the inherited pull-secret flag on the resulting command tree.

---

Nitpick comments:
In `@product-cli/cmd/cluster/openstack/create_test.go`:
- Around line 17-93: Optionally add a developer-only flag exclusion subtest
alongside the existing NewCreateCommand flag tests, asserting the relevant
developer-only flags are absent for the OpenStack create command. Follow the
corresponding exclusion assertions in the Agent, AWS, and KubeVirt sibling tests
while keeping the existing expected-flags coverage unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 090e068f-c65a-4316-a888-5edb8e0ee03f

📥 Commits

Reviewing files that changed from the base of the PR and between 144cca9 and c494b6b.

📒 Files selected for processing (4)
  • product-cli/cmd/cluster/agent/create_test.go
  • product-cli/cmd/cluster/aws/create_test.go
  • product-cli/cmd/cluster/kubevirt/create_test.go
  • product-cli/cmd/cluster/openstack/create_test.go

Comment thread product-cli/cmd/cluster/agent/create_test.go
@mehabhalodiya
mehabhalodiya force-pushed the unittest_create branch 2 times, most recently from 1b8806c to de0d041 Compare July 27, 2026 09:08
@Nirshal

Nirshal commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

The tests themselves look correct — flag registration, defaults, and developer-only exclusion are all properly verified.

That said, I'd suggest aligning with the same approach Bryan flagged on #9121: adding fixture-based tests that invoke the command with --render and compare the output against golden YAML files via testutil.CompareWithFixture(). This is the pattern used in cmd/cluster/aws/create_test.go and would give end-to-end coverage on what the commands actually produce.

For example (not tested, just to illustrate the shape):

func TestCreateCluster(t *testing.T) {
    ctx := framework.InterruptableContext(t.Context())
    t.Setenv("FAKE_CLIENT", "true")
    tempDir := t.TempDir()

    // set up credential/pull-secret files in tempDir...

    flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
    coreOpts := core.DefaultOptions()
    core.BindDeveloperOptions(coreOpts, flags)
    agentOpts := agent.DefaultOptions()
    agent.BindDeveloperOptions(agentOpts, flags)

    if err := flags.Parse([]string{
        "--name=example",
        "--pull-secret=" + pullSecretFile,
        "--agent-namespace=test-ns",
        "--render-sensitive",
    }); err != nil {
        t.Fatalf("failed to parse flags: %v", err)
    }

    manifestsFile := filepath.Join(tempDir, "manifests.yaml")
    coreOpts.Render = true
    coreOpts.RenderInto = manifestsFile

    if err := core.CreateCluster(ctx, coreOpts, agentOpts); err != nil {
        t.Fatalf("failed to create cluster: %v", err)
    }

    manifests, err := os.ReadFile(manifestsFile)
    if err != nil {
        t.Fatalf("failed to read manifests: %v", err)
    }
    testutil.CompareWithFixture(t, manifests)
}

@openshift-ci openshift-ci Bot added the area/platform/azure PR/issue for Azure (AzurePlatform) platform label Jul 28, 2026

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

🧹 Nitpick comments (1)
product-cli/cmd/cluster/kubevirt/create_test.go (1)

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

Consider adding the pull-secret inheritance case here too.

NewCreateCommand marks pull-secret persistent-required (cmd/cluster/kubevirt/create.go), but unlike the agent/AWS suites this file has no test covering it. Same gap in product-cli/cmd/cluster/openstack/create_test.go.

🤖 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 `@product-cli/cmd/cluster/kubevirt/create_test.go` around lines 60 - 71, Extend
the NewCreateCommand tests in the KubeVirt and OpenStack create suites to verify
that the pull-secret flag is inherited as a persistent required flag, matching
the existing agent/AWS coverage. Use the pull-secret flag definition and its
required/persistent properties, while preserving the current developer-only flag
assertions.
🤖 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 `@product-cli/cmd/cluster/kubevirt/create_test.go`:
- Around line 60-71: Extend the NewCreateCommand tests in the KubeVirt and
OpenStack create suites to verify that the pull-secret flag is inherited as a
persistent required flag, matching the existing agent/AWS coverage. Use the
pull-secret flag definition and its required/persistent properties, while
preserving the current developer-only flag assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 7d0b8811-b981-49d5-9c70-95b8819dcd6e

📥 Commits

Reviewing files that changed from the base of the PR and between de0d041 and 6c759d7.

⛔ Files ignored due to path filters (5)
  • product-cli/cmd/cluster/agent/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/aws/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/azure/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/kubevirt/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
  • product-cli/cmd/cluster/openstack/testdata/zz_fixture_TestCreateCluster_When_minimal_flags_are_provided__it_should_render_correctly.yaml is excluded by !**/testdata/**
📒 Files selected for processing (5)
  • product-cli/cmd/cluster/agent/create_test.go
  • product-cli/cmd/cluster/aws/create_test.go
  • product-cli/cmd/cluster/azure/create_test.go
  • product-cli/cmd/cluster/kubevirt/create_test.go
  • product-cli/cmd/cluster/openstack/create_test.go

The four platforms — AWS, KubeVirt, OpenStack, and
Agent — have no product-cli cluster creation tests
at all.

Signed-off-by: mehabhalodiya <mehabhalodiya@gmail.com>
@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

@Nirshal

Nirshal commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-azure-v2-self-managed
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws
/test e2e-v2-gke
/test unit
/test verify

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

Labels

area/platform/aws PR/issue for AWS (AWSPlatform) platform area/platform/azure PR/issue for Azure (AzurePlatform) platform area/platform/kubevirt PR/issue for KubeVirt (KubevirtPlatform) platform area/platform/openstack PR/issue for OpenStack (OpenStackPlatform) platform jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants