GoogleContainerTools/skaffold · error
failed to evaluate pod name pattern %q due to error %w
Error message
failed to evaluate pod name pattern %q due to error %w
What it means
Container lifecycle hooks select target pods/containers using glob-style patterns matched with path.Match. If evaluating the pod-name pattern itself returns an error (path.Match only errors on malformed patterns, e.g. unclosed '['), the failure is wrapped as 'failed to evaluate pod name pattern %q due to error %w'.
Source
Thrown at pkg/skaffold/hooks/container.go:68
}
return c.Image == image, nil
}
}
// namePatternSelector chooses containers that match the glob patterns for pod and container names
func namePatternSelector(podName, containerName string) containerSelector {
return func(p v1.Pod, c v1.Container) (bool, error) {
if p.Status.Phase != v1.PodRunning {
return false, nil
}
for _, status := range p.Status.ContainerStatuses {
if status.Name == c.Name && status.State.Running == nil {
return false, nil
}
}
if matched, err := path.Match(podName, p.Name); err != nil {
return false, fmt.Errorf("failed to evaluate pod name pattern %q due to error %w", podName, err)
} else if podName != "" && !matched {
return false, nil
}
if matched, err := path.Match(containerName, c.Name); err != nil {
return false, fmt.Errorf("failed to evaluate container name pattern %q due to error %w", containerName, err)
} else if containerName != "" && !matched {
return false, nil
}
return true, nil
}
}
// containerHook represents a lifecycle hook to be executed inside a running container
type containerHook struct {
cfg latest.ContainerHook
cli *kubectl.CLI
selector containerSelectorView on GitHub (pinned to a1189de023)
Solutions
- Fix the podName pattern to be a valid glob: close all '[' ... ']' character classes
- Remove regex-only syntax (path.Match supports only * ? [class] and no alternation)
- Test the pattern with a quick Go snippet or shell: path.Match(pattern, podName)
- Escape literal '[' in pod names if that character is intended to match literally
Example fix
// before (skaffold.yaml container hook selector) podName: "myapp-[abc" // after podName: "myapp-[abc]" // valid character class # or simply podName: "myapp-*" # plain glob
Defensive patterns
Strategy: validation
Validate before calling
func validGlob(p string) bool {
_, err := path.Match(p, "")
return err == nil
}
if !validGlob(selector.PodName) {
return fmt.Errorf("malformed podName glob %q", selector.PodName)
} Try / catch
err := hook.Run(ctx, out)
if err != nil {
if strings.Contains(err.Error(), "failed to evaluate pod name pattern") {
return fmt.Errorf("fix podName glob in hook selector: %w", err)
}
return err
} Prevention
- Use only glob syntax (* ? [..]) not regex in selectors
- Close all [ ] character classes
- Unit-test selector globs against expected pod names
When it happens
Trigger: Running a container hook whose selector's podName glob is malformed — e.g. 'mypod-[abc' with an unterminated character class — while iterating pods in containerHook.run via h.selector(p, c).
Common situations: Hand-written glob patterns in skaffold.yaml container hooks with unbalanced brackets; patterns copied from regex syntax (using constructs path.Match doesn't support); typos like 'pod-*-[0-9' missing the closing bracket.
Related errors
- failed to evaluate container name pattern %q due to error %w
- getting Kubernetes client: %w
- getting pods for namespace %q: %w
- hook execution failed for pod %q container %q: %w
- failed to execute container %s hook %d for artifact %q: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/c451199f6c9a4c73.
Report an issue: GitHub.