GoogleContainerTools/skaffold · error
failed to evaluate container name pattern %q due to error %w
Error message
failed to evaluate container name pattern %q due to error %w
What it means
Identical to the pod-name case but for the container-name selector: when path.Match errors while matching the configured containerName glob against a container's name, the error is wrapped as 'failed to evaluate container name pattern %q due to error %w'.
Source
Thrown at pkg/skaffold/hooks/container.go:74
// 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 containerSelector
namespaces []string
formatter logger.Formatter
}
// run executes the lifecycle hook inside the target container
func (h containerHook) run(ctx context.Context, out io.Writer) error {View on GitHub (pinned to a1189de023)
Solutions
- Correct the containerName glob so all character classes are closed
- Use only path.Match glob syntax: *, ?, and [..] classes
- Test the pattern against the expected container name before deploying
- Simplify to '*' or an exact name if the pattern is unnecessary
Example fix
// before containerName: "envoy-[proxy" // after containerName: "envoy-*"
Defensive patterns
Strategy: validation
Validate before calling
func validGlob(p string) bool {
_, err := path.Match(p, "")
return err == nil
}
if !validGlob(selector.ContainerName) {
return fmt.Errorf("malformed containerName glob %q", selector.ContainerName)
} Try / catch
err := hook.Run(ctx, out)
if err != nil {
if strings.Contains(err.Error(), "failed to evaluate container name pattern") {
return fmt.Errorf("fix containerName glob in hook selector: %w", err)
}
return err
} Prevention
- Keep containerName patterns simple (* or exact names)
- Avoid regex-only constructs in globs
- Test patterns with path.Match before committing config
When it happens
Trigger: Running a container hook whose selector's containerName glob is malformed (e.g. 'sidecar-[a-' unclosed character class) while the selector matches pods/containers in containerHook.run.
Common situations: Malformed globs in the containerName field of skaffold.yaml container hook selectors; mixing regex syntax into globs; copy-paste errors truncating the closing bracket.
Related errors
- failed to evaluate pod 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/644cacf1f555d7fe.
Report an issue: GitHub.