GoogleContainerTools/skaffold · error
hook execution failed for pod %q container %q: %w
Error message
hook execution failed for pod %q container %q: %w
What it means
Once a matching pod/container is found, the hook command runs via util.RunCmd in an errgroup goroutine. If the command exits non-zero or fails to run, the error is wrapped as 'hook execution failed for pod %q container %q: %w', attributing the failure to the specific pod and container.
Source
Thrown at pkg/skaffold/hooks/container.go:125
for _, c := range p.Spec.Containers {
if matched, err := h.selector(p, c); err != nil {
return err
} else if !matched {
continue
}
args := []string{p.Name, "--namespace", p.Namespace, "-c", c.Name, "--"}
args = append(args, h.cfg.Command...)
cmd := h.cli.Command(ctx, "exec", args...)
tr, tw := io.Pipe()
cmd.Stderr = tw
cmd.Stdout = tw
podName := p.Name
containerName := c.Name
errs.Go(func() error {
defer tw.Close()
err := util.RunCmd(ctx, cmd)
if err != nil {
return fmt.Errorf("hook execution failed for pod %q container %q: %w", podName, containerName, err)
}
return nil
})
pod := p
var containerStatus v1.ContainerStatus
for _, status := range pod.Status.ContainerStatuses {
if status.Name == c.Name {
containerStatus = status
}
}
errs.Go(func() error {
return stream.StreamRequest(ctx, out, h.formatter(pod, containerStatus, func() bool { return false }), tr)
})
}
}
}
return errs.Wait()
}View on GitHub (pinned to a1189de023)
Solutions
- Check the wrapped stderr/stdout in the error to see the actual command failure
- Verify the command exists in the container image (kubectl exec <pod> -c <ctr> -- which <cmd>)
- Fix the command/args in the skaffold.yaml hook definition
- Ensure the container stays Running during the hook and the app exits 0
Example fix
// before
containerHooks:
postBuild:
- command: ["./scripts/notify.sh"] # not present in image
// after
containerHooks:
postBuild:
- command: ["/bin/sh", "-c", "[ -f /scripts/notify.sh ] && /scripts/notify.sh || true"] Defensive patterns
Strategy: try-catch
Validate before calling
// ensure the command exists in the image before running the hook
if err := exec.Command("kubectl", "exec", pod, "-c", container, "--", "which", cmdName).Run(); err != nil {
return fmt.Errorf("command %q not present in %s/%s", cmdName, pod, container)
} Try / catch
err := hook.Run(ctx, out)
var exitErr *exec.ExitError
if err != nil {
if errors.As(err, &exitErr) {
log.Printf("hook failed in pod/container (exit %d): %v", exitErr.ExitCode(), err)
}
return err
} Prevention
- Bake hook commands into the container image
- Make hook scripts idempotent and exit 0 on benign conditions
- Check pod Running status before dispatching hooks
- Capture and read the wrapped command output when debugging
When it happens
Trigger: run dispatching errs.Go for a matched container where util.RunCmd returns an error — the hook command binary is missing in the container, exits non-zero, or exec into the pod fails.
Common situations: Hook command not installed in the target container image; script exits with a non-zero status due to app logic; insufficient permissions to exec into the pod; container restarted/terminated mid-hook; wrong command name in skaffold.yaml.
Related errors
- failed to evaluate pod name pattern %q due to error %w
- failed to evaluate container name pattern %q due to error %w
- getting Kubernetes client: %w
- getting pods for namespace %q: %w
- starting cmd: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/ff7e0519246296e2.
Report an issue: GitHub.