fix: enable multiple container hooks#9965
fix: enable multiple container hooks#9965mleddy-NS1 wants to merge 1 commit intoGoogleContainerTools:mainfrom
Conversation
Updating filterContainersSelector to accept this index, allowing for the expansion of the key format to include the hook index.
Summary of ChangesHello @mleddy-NS1, 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 introduces a crucial change to how Skaffold handles multiple container hooks during deployment. By adding an index to the hook iteration and incorporating it into the container filtering mechanism, the system can now uniquely identify and process each hook. This resolves an issue where identical container hooks might have been incorrectly skipped or mishandled, leading to more robust and predictable hook execution. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Code Review
This pull request correctly fixes an issue where only the first of multiple container hooks on the same container would be executed in subsequent dev loops by including the hook's index in the tracking key. However, I've identified a potential issue where hooks could still be skipped if pods in different namespaces share the same name. I've suggested a small change to include the namespace in the key to ensure its uniqueness across the cluster.
| func filterContainersSelector(visitedContainers *sync.Map, phase phase, hookIndex int, selector containerSelector) containerSelector { | ||
| return func(p corev1.Pod, c corev1.Container) (bool, error) { | ||
| key := fmt.Sprintf("%s:%s:%s", phase, p.GetName(), c.Name) | ||
| key := fmt.Sprintf("%s:%d:%s:%s", phase, hookIndex, p.GetName(), c.Name) |
There was a problem hiding this comment.
The key for visitedContainers should include the pod's namespace to be truly unique. Without the namespace, if two pods in different namespaces have the same name, they would generate the same key for the same hook. This could lead to one of the hooks being incorrectly skipped in subsequent runs. The original code also had this issue, but since this line is being modified, it's a good opportunity to make the key more robust.
| key := fmt.Sprintf("%s:%d:%s:%s", phase, hookIndex, p.GetName(), c.Name) | |
| key := fmt.Sprintf("%s:%d:%s:%s:%s", phase, hookIndex, p.Namespace, p.GetName(), c.Name) |
There was a problem hiding this comment.
I'm happy to either fix this as part of this PR. Or alternatively create a separate PR for the above suggestion to limit the size and keep to two smaller PRs.
Could someone from the Skaffold review team comment on what is preferred?
Fixes: #8356
Related: #9076
Description
Currently container deploy hooks only execute the first element from the list of post deploy hooks
This fix adds an index to the loop over the range of hooks so that all container post hooks can be uniquely added to the range of hooks to be run.
Updating filterContainersSelector to accept this index, allowing for the expansion of the key format to include the hook index.
Updated applicable unit test case for the fixed behavior.