Skip to content

fix: handle deployments without command in patcher#7706

Open
Elvand-Lie wants to merge 1 commit into
karmada-io:masterfrom
Elvand-Lie:fix-patcher-empty-command
Open

fix: handle deployments without command in patcher#7706
Elvand-Lie wants to merge 1 commit into
karmada-io:masterfrom
Elvand-Lie:fix-patcher-empty-command

Conversation

@Elvand-Lie

@Elvand-Lie Elvand-Lie commented Jul 3, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

Patcher.ForDeployment currently assumes the first container has a non-empty Command when applying extraArgs or featureGates, and indexes baseArguments[0] unconditionally.

This PR hardens that path for deployments that rely on the image entrypoint and leave Command empty. When Command is present, the patcher keeps the existing behavior and preserves the first command element as the binary name. When Command is empty, the command-argument merge is skipped so the patcher does not panic and does not reinterpret arbitrary Kubernetes Args.

A regression case is added to the existing TestPatchForDeployment table.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Local checks run:

  • go test ./operator/pkg/util/patcher -run 'TestPatchForDeployment/PatchForDeployment_WithExtraArgsAndEmptyCommand_Patched' -count=1 -v
  • go test ./operator/pkg/util/patcher -count=1
  • gofmt -l operator/pkg/util/patcher/pather.go operator/pkg/util/patcher/pather_test.go
  • git diff --check

mingw32-make test is not usable in this Windows shell; it fails before Go tests at mkdir -p ./_output/coverage/. A previous hack/verify-all.sh run in MSYS bash failed on unrelated pkg/util/lifted/doc.go generated-doc drift.

Does this PR introduce a user-facing change?:

NONE

Copilot AI review requested due to automatic review settings July 3, 2026 16:06
@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 3, 2026
@karmada-bot karmada-bot requested review from Poor12 and jabellard July 3, 2026 16:06
@karmada-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign calvin0327 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

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the reliability of the Patcher component by adding support for Kubernetes deployments that do not explicitly define a container command. By intelligently choosing between updating the Command or Args fields, the patcher now avoids errors and correctly preserves image entrypoints while still applying necessary configuration updates.

Highlights

  • Patcher Robustness: Updated the Patcher logic to handle deployments where the container Command is empty, preventing potential panics.
  • Argument Merging Logic: Modified the patcher to merge extra arguments into the container Args field when Command is empty, preserving the image entrypoint.
  • Regression Testing: Added a new test case to TestPatchForDeployment to verify correct behavior when applying extra arguments to containers without a defined command.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 3, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the deployment patcher to support patching container arguments (Args) when the container command (Command) is empty, and adds a corresponding unit test. A review comment points out a critical issue where subcommands or non-flag arguments in Args could be silently dropped during parsing and overwriting, and provides a code suggestion to preserve them.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread operator/pkg/util/patcher/pather.go Outdated
Comment on lines +175 to +177
if useArgs {
container.Args = command
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

When useArgs is true, if the first element of container.Args is a subcommand or a non-flag argument (e.g., ["run", "--config=..."]), it will fail parseArgument validation and be ignored during parsing. Consequently, when container.Args is overwritten with command, this subcommand will be silently dropped, which can break the deployment.

To prevent this, we should check if the first element of baseArguments is a non-flag argument (by verifying if parseArgument returns an error) and preserve it by prepending it to the generated command list, similar to how we preserve the binary name in Command.

		if useArgs {
			if len(baseArguments) > 0 {
				if _, _, err := parseArgument(baseArguments[0]); err != nil {
					command = append([]string{baseArguments[0]}, command...)
				}
			}
			container.Args = command
		} else {

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

Pull request overview

Hardens Patcher.ForDeployment so it no longer panics when patching a Deployment whose first container relies on the image entrypoint (empty Command). The patcher now falls back to patching Args in that case, and a regression test is added.

Changes:

  • Update ForDeployment to patch Args when Command is empty, while preserving existing behavior when Command is present.
  • Add a table-driven regression test covering the empty Command scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
operator/pkg/util/patcher/pather.go Adds Command vs Args selection logic when merging extraArgs/featureGates for Deployments.
operator/pkg/util/patcher/pather_test.go Adds a regression case for Deployments with empty Command to ensure patching doesn’t panic and writes flags into Args.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread operator/pkg/util/patcher/pather.go Outdated
Comment on lines 154 to 158
useArgs := len(baseArguments) == 0
if useArgs {
baseArguments = container.Args
}
argsMap := parseArgumentListToMap(baseArguments)
Comment on lines +198 to +202
Containers: []corev1.Container{
{
Name: "test-container",
Image: "nginx:latest",
},
@codecov-commenter

codecov-commenter commented Jul 3, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.06%. Comparing base (09eb45a) to head (d07fcdb).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7706   +/-   ##
=======================================
  Coverage   42.06%   42.06%           
=======================================
  Files         879      879           
  Lines       54831    54832    +1     
=======================================
+ Hits        23063    23067    +4     
+ Misses      30023    30021    -2     
+ Partials     1745     1744    -1     
Flag Coverage Δ
unittests 42.06% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

Signed-off-by: Elvand-Lie <elvandlie@gmail.com>
@Elvand-Lie Elvand-Lie force-pushed the fix-patcher-empty-command branch from ee6fc4c to d07fcdb Compare July 3, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants