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

  1. Correct the containerName glob so all character classes are closed
  2. Use only path.Match glob syntax: *, ?, and [..] classes
  3. Test the pattern against the expected container name before deploying
  4. 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

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


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/644cacf1f555d7fe. Report an issue: GitHub.