Skip to content

Conversation

liouk
Copy link
Member

@liouk liouk commented Oct 16, 2025

The create subcommands of oc do not pass along the --dry-run option when used on the command-line. Therefore, the server-side dry run is ignored, and the resources get created.

The fix provided in openshift/openshift-apiserver#511 was necessary for image streams, but we also need wiring on the oc side.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 16, 2025
@openshift-ci-robot openshift-ci-robot added jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Oct 16, 2025
@openshift-ci-robot
Copy link

@liouk: This pull request references Jira Issue OCPBUGS-62875, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.21.0) matches configured target version for branch (4.21.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @wangke19

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

The create subcommands of oc do not pass along the --dry-run option when used on the command-line. Therefore, the server-side dry run is ignored, and the resources get created.

The fix provided in openshift/openshift-apiserver#511 was necessary for image streams, but we also need wiring on the oc side.

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 a review from wangke19 October 16, 2025 14:27
Copy link

coderabbitai bot commented Oct 16, 2025

Walkthrough

This PR systematically replaces hardcoded empty metav1.CreateOptions{} arguments across 12 CLI create commands with dynamic options built from toCreateOptions() helper methods. Two new helper methods conditionally set the DryRun field based on the DryRunStrategy configuration.

Changes

Cohort / File(s) Summary
Helper Method Definitions
pkg/cli/create/create.go, pkg/cli/create/route.go
Added toCreateOptions() methods to CreateSubcommandOptions and CreateRouteSubcommandOptions respectively. Both methods construct metav1.CreateOptions instances and conditionally set DryRun to metav1.DryRunAll when DryRunStrategy is DryRunServer. Added metav1 import to create.go.
Build/Cluster/Deployment/Identity Commands
pkg/cli/create/build.go, pkg/cli/create/clusterquota.go, pkg/cli/create/deploymentconfig.go, pkg/cli/create/identity.go
Updated Create calls to use o.CreateSubcommandOptions.toCreateOptions() instead of static metav1.CreateOptions{}.
Image/User Commands
pkg/cli/create/imagestream.go, pkg/cli/create/imagestreamtag.go, pkg/cli/create/user.go, pkg/cli/create/user_identity_mapping.go
Updated Create calls to use o.CreateSubcommandOptions.toCreateOptions() instead of static metav1.CreateOptions{}.
Route Subcommand Variants
pkg/cli/create/routeedge.go, pkg/cli/create/routepassthrough.go, pkg/cli/create/routereenecrypt.go
Updated Create calls to use o.CreateRouteSubcommandOptions.toCreateOptions() instead of static metav1.CreateOptions{}. Removed metav1 imports (no longer directly needed).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

The review scope is broad (12 files affected), but the changes are highly homogeneous—the same refactoring pattern is applied consistently across multiple files. The new logic is straightforward (simple conditional assignment). The mechanical nature of replacing static options with dynamic method calls and the low behavioral impact keep complexity minimal. The main verification task is confirming consistency of the implementation across all callsites.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "WIP: OCPBUGS-62875: Pass dry-run option to all create API calls" directly and clearly describes the main objective of the changeset. The raw summary confirms that multiple files across pkg/cli/create/ have been modified to replace static metav1.CreateOptions{} with dynamic calls to toCreateOptions(), which conditionally sets the DryRun field when appropriate. The title accurately reflects this change without being vague or overly broad, and it includes the relevant Jira issue identifier.
Description Check ✅ Passed The pull request description is directly related to the changeset. It explains the problem—that create subcommands do not pass the --dry-run option to the server, causing server-side dry-run behavior to be ignored—and identifies the solution as wiring on the oc client side. This matches exactly what the changes accomplish: adding toCreateOptions() methods and updating create API calls throughout multiple files to use dynamic options instead of static empty CreateOptions. The description provides meaningful context about the issue and references the corresponding server-side fix.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 atiratree and tchap October 16, 2025 14:28
Copy link
Contributor

openshift-ci bot commented Oct 16, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

The full list of commands accepted by this bot can be found here.

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: 0

🧹 Nitpick comments (1)
pkg/cli/create/route.go (1)

126-133: Consider consolidating duplicate toCreateOptions() implementations.

This method duplicates the logic from CreateSubcommandOptions.toCreateOptions() in create.go (lines 68-75). Both helpers have identical implementations.

Consider one of these approaches:

Option 1: Make CreateRouteSubcommandOptions embed or reference CreateSubcommandOptions:

 type CreateRouteSubcommandOptions struct {
+	CreateSubcommandOptions *CreateSubcommandOptions
 	// PrintFlags holds options necessary for obtaining a printer
 	PrintFlags *genericclioptions.PrintFlags

Then delegate to the shared helper:

 func (o *CreateRouteSubcommandOptions) toCreateOptions() metav1.CreateOptions {
-	createOptions := metav1.CreateOptions{}
-	if o.DryRunStrategy == cmdutil.DryRunServer {
-		createOptions.DryRun = []string{metav1.DryRunAll}
-	}
-
-	return createOptions
+	return o.CreateSubcommandOptions.toCreateOptions()
 }

Option 2: Extract a standalone helper function that both can call:

func buildCreateOptions(dryRunStrategy cmdutil.DryRunStrategy) metav1.CreateOptions {
	createOptions := metav1.CreateOptions{}
	if dryRunStrategy == cmdutil.DryRunServer {
		createOptions.DryRun = []string{metav1.DryRunAll}
	}
	return createOptions
}

This reduces maintenance burden if the dry-run logic needs updating.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 672ff62 and b89c9f9.

📒 Files selected for processing (13)
  • pkg/cli/create/build.go (1 hunks)
  • pkg/cli/create/clusterquota.go (1 hunks)
  • pkg/cli/create/create.go (2 hunks)
  • pkg/cli/create/deploymentconfig.go (1 hunks)
  • pkg/cli/create/identity.go (1 hunks)
  • pkg/cli/create/imagestream.go (1 hunks)
  • pkg/cli/create/imagestreamtag.go (1 hunks)
  • pkg/cli/create/route.go (2 hunks)
  • pkg/cli/create/routeedge.go (1 hunks)
  • pkg/cli/create/routepassthrough.go (1 hunks)
  • pkg/cli/create/routereenecrypt.go (1 hunks)
  • pkg/cli/create/user.go (1 hunks)
  • pkg/cli/create/user_identity_mapping.go (1 hunks)
🔇 Additional comments (13)
pkg/cli/create/routeedge.go (1)

139-139: LGTM! Consistent application of the new options builder pattern.

The change correctly replaces the static metav1.CreateOptions{} with a dynamic call to o.CreateRouteSubcommandOptions.toCreateOptions(), aligning with the PR objective to pass dry-run options to the server. The existing DryRunClient check on line 138 is preserved, ensuring correct flow control.

pkg/cli/create/deploymentconfig.go (1)

114-114: LGTM! Correctly applies the dynamic options pattern.

The change appropriately replaces the literal metav1.CreateOptions{} with o.CreateSubcommandOptions.toCreateOptions(), enabling server-side dry-run behavior. The dry-run strategy check on line 112 remains intact, maintaining the expected control flow.

pkg/cli/create/imagestreamtag.go (1)

184-184: LGTM! Pattern applied correctly.

The replacement of metav1.CreateOptions{} with o.CreateSubcommandOptions.toCreateOptions() is consistent with the PR's objective to properly forward dry-run options to the API server. The existing dry-run handling on line 183 is preserved.

pkg/cli/create/identity.go (1)

115-115: LGTM! Change aligns with the PR objective.

The update correctly replaces the hardcoded metav1.CreateOptions{} with o.CreateSubcommandOptions.toCreateOptions(), ensuring that dry-run options are properly communicated to the server. The dry-run strategy check on line 113 remains unchanged.

pkg/cli/create/clusterquota.go (1)

140-140: LGTM! Consistent with the broader refactoring.

The change from metav1.CreateOptions{} to o.CreateSubcommandOptions.toCreateOptions() properly implements the pattern for forwarding dry-run options to the API server. The control flow with the dry-run check on line 138 is maintained.

pkg/cli/create/imagestream.go (1)

102-102: LGTM! Properly implements the options builder pattern.

The substitution of metav1.CreateOptions{} with o.CreateSubcommandOptions.toCreateOptions() correctly enables dynamic configuration of create options, particularly for dry-run behavior. The dry-run strategy check on line 100 is preserved.

pkg/cli/create/routepassthrough.go (1)

105-105: LGTM! Change is consistent with the refactoring pattern.

The replacement of metav1.CreateOptions{} with o.CreateRouteSubcommandOptions.toCreateOptions() follows the established pattern across the PR, ensuring dry-run options are passed to the API server. The dry-run check on line 104 remains intact.

pkg/cli/create/routereenecrypt.go (2)

154-154: LGTM! Pattern correctly applied.

The change from metav1.CreateOptions{} to o.CreateRouteSubcommandOptions.toCreateOptions() aligns with the PR's goal of forwarding dry-run options to the server. The dry-run strategy check on line 153 is preserved.


1-161: Implementation verified; add tests for dry-run forwarding.

All toCreateOptions() implementations are correctly in place:

  • CreateSubcommandOptions.toCreateOptions() at pkg/cli/create/create.go:68
  • CreateRouteSubcommandOptions.toCreateOptions() at pkg/cli/create/route.go:126

Both properly set DryRun: []string{metav1.DryRunAll} when DryRunStrategy == cmdutil.DryRunServer. All 11 create subcommands (routereenecrypt, routepassthrough, routeedge, user, user_identity_mapping, imagestreamtag, identity, deploymentconfig, clusterquota, build, imagestream) have been updated to use toCreateOptions() in their API calls.

However, no test files exist in pkg/cli/create/ to verify dry-run options are properly forwarded to the API server. Add tests to validate this behavior.

pkg/cli/create/user.go (1)

110-110: LGTM!

The Create call now correctly uses dynamic CreateOptions from toCreateOptions(), enabling server-side dry-run when --dry-run=server is specified.

pkg/cli/create/create.go (1)

68-75: LGTM!

The helper correctly builds CreateOptions with DryRun set to metav1.DryRunAll when DryRunStrategy is DryRunServer, enabling server-side dry-run validation without creating resources.

pkg/cli/create/build.go (1)

222-222: LGTM!

The Create call now uses dynamic CreateOptions, consistent with the PR objectives to pass --dry-run to the server.

pkg/cli/create/user_identity_mapping.go (1)

134-134: LGTM!

The Create call correctly uses dynamic CreateOptions from the helper method.

@ardaguclu
Copy link
Member

Overall idea sounds good to me. Nice catch!

Copy link
Contributor

openshift-ci bot commented Oct 16, 2025

@liouk: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/okd-scos-e2e-aws-ovn b89c9f9 link false /test okd-scos-e2e-aws-ovn

Full PR test history. Your PR dashboard.

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/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants