{"record":{"id":"438b891d4b9eaeb4","repo":"derailed/k9s","slug":"failed-to-locate-pod-q-w","errorCode":null,"errorMessage":"failed to locate pod %q: %w","messagePattern":"failed to locate pod %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dao/container.go","lineNumber":138,"sourceCode":"\t\t\tif status.InitContainerStatuses[i].Name == name {\n\t\t\t\treturn &status.InitContainerStatuses[i]\n\t\t\t}\n\t\t}\n\tcase ephIDX:\n\t\tfor i := range status.EphemeralContainerStatuses {\n\t\t\tif status.EphemeralContainerStatuses[i].Name == name {\n\t\t\t\treturn &status.EphemeralContainerStatuses[i]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (c *Container) fetchPod(fqn string) (*v1.Pod, error) {\n\to, err := c.getFactory().Get(client.PodGVR, fqn, true, labels.Everything())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to locate pod %q: %w\", fqn, err)\n\t}\n\tvar po v1.Pod\n\terr = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &po)\n\treturn &po, err\n}\n","sourceCodeStart":120,"sourceCodeEnd":144,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/dao/container.go#L120-L144","documentation":"Container.fetchPod (internal/dao/container.go:135-141) looks up a pod by fully-qualified name (ns/pod) in the shared watch-factory cache via client.PodGVR. This error wraps the factory Get failure; it is a cache/informer lookup, not a live API call, so a pod that exists on the cluster can still be missed if the cache has not synced or the FQN is malformed.","triggerScenarios":"Calling a container DAO method (exec, logs, shell) with a pod path that is not in the informer cache: typo in the pod name, wrong namespace in the ns/name pair, pod already deleted, or the pod informer has not finished its initial list right after k9s connects to a large cluster.","commonSituations":"Acting on a stale UI row after the pod was OOM-killed/rescheduled; scripts or plugin args passing a pod name without its namespace; slow cache sync on clusters with tens of thousands of pods; filtered contexts hiding the namespace from the informer's watch.","solutions":["Verify the pod exists: kubectl get pod <name> -n <ns>; if gone, refresh the view and retry on the new pod","Confirm the path format is exactly namespace/name with no extra segments","If k9s just started, wait a few seconds for informer sync and retry the action","Check that the namespace is watchable by the current user (RBAC on pods) so the cache can populate"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before using a pod path, confirm the informer cache has it.\nfunc PodCached(f watch.Factory, fqn string) bool {\n\t_, err := f.Get(client.PodGVR, fqn, true, labels.Everything())\n\treturn err == nil\n}","typeGuard":null,"tryCatchPattern":"// pod lookup: distinguish gone-vs-not-synced, retry briefly on cache miss.\nerr := dao.Inspect(ctx, podFQN)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to locate pod\") {\n        if ok := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 5*time.Second, true,\n            func(ctx context.Context) (bool, error) { return PodCached(f, podFQN), nil }); ok == nil {\n            err = dao.Inspect(ctx, podFQN) // cache caught up\n        }\n    }\n    if err != nil { return err }\n}","preventionTips":["Always pass the full namespace/name path, never a bare pod name","Give k9s a few seconds on huge clusters before acting on freshly observed pods","Refresh the pod view (key 0/reload) after reschedules before exec/log actions"],"tags":["go","kubernetes","k9s","cache","informer","pod"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}