kubernetes/kops · error

getting pod logs for the previous instance of %v/%v: %w

Error message

getting pod logs for the previous instance of %v/%v: %w

What it means

Fetching previous (restarted) container logs returned a non-400 status error; 400 is deliberately ignored because a container may have no previous instance, so any other status is a genuine API failure for that pod's previous logs.

Source

Thrown at pkg/dump/podlogs.go:108

func (d *podLogDumper) getPodLogs(ctx context.Context, pods chan v1.Pod, results chan podLogDumpResult) {
	for pod := range pods {
		var podErr error
		for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
			resPath := path.Join(d.artifactsDir, "cluster-info", pod.Namespace, pod.Name, container.Name)

			err := os.MkdirAll(path.Dir(resPath), 0755)
			if err != nil {
				podErr = errors.Join(podErr, fmt.Errorf("creating directory %q: %w", resPath, err))
				continue
			}

			{
				resp, err := d.k8sClient.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{Container: container.Name, Previous: true}).Do(ctx).Raw()
				var statusErr *k8sErrors.StatusError
				if errors.As(err, &statusErr) {
					if statusErr.ErrStatus.Code != 400 {
						podErr = errors.Join(podErr, fmt.Errorf("getting pod logs for the previous instance of %v/%v: %w", pod.Namespace, pod.Name, err))
					}
				} else {
					err := writeContainerLogs(resPath+".previous.log", resp)
					if err != nil {
						podErr = errors.Join(podErr, err)
					}
				}
			}

			{
				resp, err := d.k8sClient.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{Container: container.Name}).Do(ctx).Raw()
				var statusErr *k8sErrors.StatusError
				if errors.As(err, &statusErr) {
					if statusErr.ErrStatus.Code != 400 {
						podErr = errors.Join(podErr, fmt.Errorf("getting pod logs for the current instance of %v/%v: %w", pod.Namespace, pod.Name, err))
						continue
					}
				} else {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Ignore if previous logs are nonessential — the dump continues and the error is joined into the result
  2. Check the wrapped API error (pod deleted mid-dump, RBAC)
  3. Re-run the dump for that pod if the logs matter
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at pkg/dump/podlogs.go:108 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/50155f9ba9a4f48e. Report an issue: GitHub.