{"record":{"id":"50155f9ba9a4f48e","repo":"kubernetes/kops","slug":"getting-pod-logs-for-the-previous-instance-of-v","errorCode":null,"errorMessage":"getting pod logs for the previous instance of %v/%v: %w","messagePattern":"getting pod logs for the previous instance of (.+?)/(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dump/podlogs.go","lineNumber":108,"sourceCode":"\nfunc (d *podLogDumper) getPodLogs(ctx context.Context, pods chan v1.Pod, results chan podLogDumpResult) {\n\tfor pod := range pods {\n\t\tvar podErr error\n\t\tfor _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {\n\t\t\tresPath := path.Join(d.artifactsDir, \"cluster-info\", pod.Namespace, pod.Name, container.Name)\n\n\t\t\terr := os.MkdirAll(path.Dir(resPath), 0755)\n\t\t\tif err != nil {\n\t\t\t\tpodErr = errors.Join(podErr, fmt.Errorf(\"creating directory %q: %w\", resPath, err))\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tresp, err := d.k8sClient.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{Container: container.Name, Previous: true}).Do(ctx).Raw()\n\t\t\t\tvar statusErr *k8sErrors.StatusError\n\t\t\t\tif errors.As(err, &statusErr) {\n\t\t\t\t\tif statusErr.ErrStatus.Code != 400 {\n\t\t\t\t\t\tpodErr = errors.Join(podErr, fmt.Errorf(\"getting pod logs for the previous instance of %v/%v: %w\", pod.Namespace, pod.Name, err))\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\terr := writeContainerLogs(resPath+\".previous.log\", resp)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tpodErr = errors.Join(podErr, err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t{\n\t\t\t\tresp, err := d.k8sClient.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{Container: container.Name}).Do(ctx).Raw()\n\t\t\t\tvar statusErr *k8sErrors.StatusError\n\t\t\t\tif errors.As(err, &statusErr) {\n\t\t\t\t\tif statusErr.ErrStatus.Code != 400 {\n\t\t\t\t\t\tpodErr = errors.Join(podErr, fmt.Errorf(\"getting pod logs for the current instance of %v/%v: %w\", pod.Namespace, pod.Name, err))\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t} else {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dump/podlogs.go#L90-L126","documentation":"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.","triggerScenarios":"Thrown at pkg/dump/podlogs.go:108 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ignore if previous logs are nonessential — the dump continues and the error is joined into the result","Check the wrapped API error (pod deleted mid-dump, RBAC)","Re-run the dump for that pod if the logs matter"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}