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   containerSelector

View on GitHub (pinned to a1189de023)

Solutions

  1. Fix the podName pattern to be a valid glob: close all '[' ... ']' character classes
  2. Remove regex-only syntax (path.Match supports only * ? [class] and no alternation)
  3. Test the pattern with a quick Go snippet or shell: path.Match(pattern, podName)
  4. 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

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


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