-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: avoid verify empty container cmd/args #9869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Do not copy container commands or arguments if not specified in skaffold.yaml If not, original command/argument defined in the job will be overwritten with nil.
Summary of ChangesHello @reingart, 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 addresses a critical bug in Skaffold's Highlights
Using Gemini Code AssistThe 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
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
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 correctly addresses an issue where container command
and args
from a job manifest were being overwritten. The conditional logic in patchToK8sContainer
is a good fix. The addition of extensive debug and trace logging is also a welcome improvement for maintainability. I have a few suggestions to refine the implementation. The primary concern is ensuring the fix fully covers the scenario described in the PR (using an empty slice []
). Additionally, the new logging statements should consistently use the available function context instead of context.TODO()
to preserve trace information and enable proper cancellation.
if container.Command != nil { | ||
dst.Command = container.Command | ||
} | ||
if container.Args != nil { | ||
dst.Args = container.Args | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix correctly prevents overwriting the command/args when they are not specified in the skaffold.yaml
. However, the PR description mentions that the 'bogus' behavior can be reproduced with args: []
. With the current check (container.Args != nil
), an empty slice []
is not nil
, so it would still overwrite the original arguments from the manifest with an empty list. To fully address the case described, it would be better to check if the slice has any elements before overwriting. This applies to both Command
and Args
.
if container.Command != nil { | |
dst.Command = container.Command | |
} | |
if container.Args != nil { | |
dst.Args = container.Args | |
} | |
if len(container.Command) > 0 { | |
dst.Command = container.Command | |
} | |
if len(container.Args) > 0 { | |
dst.Args = container.Args | |
} |
// This is because the k8s API server can be unresponsive when hit with a large | ||
// intitial set of Job CREATE requests | ||
if waitErr := wait.Poll(100*time.Millisecond, 30*time.Second, func() (bool, error) { | ||
olog.Entry(context.TODO()).Debugf("Creating verify job in cluster: %+v\n", job) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great that you're adding more logging. However, using context.TODO()
should be avoided when a more specific context is available. In this function, ctx
is passed as an argument and should be used here instead. This ensures that trace information and other context-scoped values are propagated correctly.
This same feedback applies to the other new logging calls in this file where ctx
is available (e.g., in watchJob
and Cleanup
). For the logs in createJobFromManifestPath
, which doesn't currently accept a context, consider refactoring that function to accept a context from its caller.
olog.Entry(context.TODO()).Debugf("Creating verify job in cluster: %+v\n", job) | |
olog.Entry(ctx).Debugf("Creating verify job in cluster: %+v\n", job) |
job.Name = jobName | ||
job.Labels["skaffold.dev/run-id"] = v.labeller.GetRunID() | ||
var original corev1.Container | ||
olog.Entry(context.TODO()).Tracef("Lookging for container %s in %+v\n", container.Name, job.Spec.Template.Spec.Containers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo here: 'Lookging' should be 'Looking'.
olog.Entry(context.TODO()).Tracef("Lookging for container %s in %+v\n", container.Name, job.Spec.Template.Spec.Containers) | |
olog.Entry(context.TODO()).Tracef("Looking for container %s in %+v\n", container.Name, job.Spec.Template.Spec.Containers) |
Description
In verify job stanzas, do not copy container commands or arguments if not specified in skaffold.yaml
If not, original command/argument defined in the job will be overwritten with nil.
Previous "bogus" behavior could be reproduced using empty string command or args, for example:
UT comming soon