Skip to content

fix: execute all container hooks targeting the same pod/container#10013

Open
singhlovepreet9 wants to merge 1 commit intoGoogleContainerTools:mainfrom
singhlovepreet9:fix/multiple-container-hooks-8356
Open

fix: execute all container hooks targeting the same pod/container#10013
singhlovepreet9 wants to merge 1 commit intoGoogleContainerTools:mainfrom
singhlovepreet9:fix/multiple-container-hooks-8356

Conversation

@singhlovepreet9
Copy link

Summary

Fixes #8356

  • When multiple container hooks are configured in deploy.kubectl.hooks.after targeting the same pod and container (but with different commands), only the first hook executes. Subsequent hooks are silently skipped.
  • Root cause: The shared visitedContainers sync.Map in filterContainersSelector uses a key of phase:podName:containerName. When the second hook targets the same pod/container, the key already exists and the container is filtered out.
  • Fix: Include the hook index in the key (phase:hookIndex:podName:containerName) so each hook definition independently tracks which containers it has processed, while still preventing duplicate execution within the same hook across deploy iterations.

Reproduction

deploy:
  kubectl:
    hooks:
      after:
        - container:
            command: ["echo", "container-hook-0"]
            containerName: test
            podName: repro*
        - container:
            command: ["echo", "container-hook-1"]
            containerName: test
            podName: repro*

Before this fix, only container-hook-0 would execute.

Test plan

  • Added TestMultipleContainerHooksOnSamePod unit test that verifies both container hooks execute
  • Existing TestDeployHooks continues to pass
  • go test ./pkg/skaffold/hooks/ -v passes

🤖 Generated with Claude Code

@singhlovepreet9 singhlovepreet9 requested a review from a team as a code owner March 16, 2026 19:49
@gemini-code-assist
Copy link
Contributor

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 addresses a critical bug in the deployment hook mechanism where only the initial container hook would run if multiple hooks were configured for the same pod and container. By refining the internal tracking logic to include a unique identifier for each hook, the system now correctly executes all defined container hooks, ensuring that complex deployment workflows with multiple container-level actions are fully supported.

Highlights

  • Bug Fix: Multiple Container Hooks: Resolved an issue where only the first container hook would execute when multiple hooks targeted the same pod and container, silently skipping subsequent hooks.
  • Root Cause Identified: The problem stemmed from the visitedContainers sync.Map using a key (phase:podName:containerName) that did not differentiate between distinct hook definitions, causing subsequent hooks to be filtered out.
  • Solution Implemented: The fix involves incorporating the hook's index into the visitedContainers key (phase:hookIndex:podName:containerName), ensuring each hook independently tracks its processed containers and allows all configured hooks to execute.
  • New Unit Test: A new unit test, TestMultipleContainerHooksOnSamePod, was added to specifically verify that all container hooks execute as expected when targeting the same pod and container.

🧠 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.

Changelog
  • pkg/skaffold/hooks/deploy.go
    • Modified the loop iterating over deploy hooks to provide an index for each hook.
    • Updated the filterContainersSelector function call to pass the hook index.
    • Adjusted the filterContainersSelector function signature and its internal key generation logic to include the hook index, ensuring unique tracking for each hook.
  • pkg/skaffold/hooks/deploy_test.go
    • Added a new unit test TestMultipleContainerHooksOnSamePod to validate the correct execution of multiple container hooks targeting the same pod and container.
Activity
  • The author identified a bug where only the first container hook would execute if multiple hooks targeted the same pod/container.
  • The root cause was traced to the visitedContainers map key not being unique per hook definition.
  • A fix was implemented by including the hook index in the key for visitedContainers.
  • A new unit test TestMultipleContainerHooksOnSamePod was added to confirm the fix.
  • Existing TestDeployHooks were verified to continue passing.
  • All go test ./pkg/skaffold/hooks/ -v tests passed.
  • The pull request was generated with Claude Code.
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 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 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

  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.

@google-cla
Copy link

google-cla bot commented Mar 16, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 addresses a bug where multiple container hooks targeting the same pod and container would not all execute. The fix correctly resolves this by making the key used to track executed hooks unique for each hook definition by including the hook's index. The changes are logical, well-contained, and include a new unit test that effectively validates the fix by simulating the problematic scenario. The implementation is clean and directly solves the described issue.

…ogleContainerTools#8356)

When multiple container hooks were configured in deploy.kubectl.hooks.after
targeting the same pod and container, only the first hook would execute.
The shared visitedContainers map used a key of phase:podName:containerName,
causing subsequent hooks for the same container to be silently skipped.

Fix by including the hook index in the visitedContainers key so each hook
definition independently tracks which containers it has processed.

Fixes GoogleContainerTools#8356
@singhlovepreet9 singhlovepreet9 force-pushed the fix/multiple-container-hooks-8356 branch from f1a8d76 to c0b0cd9 Compare March 16, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After-deploy hooks: Only the first container hook executes

1 participant