{"record":{"id":"8428fd2d8fcb6ead","repo":"derailed/k9s","slug":"expecting-pod-resource","errorCode":null,"errorMessage":"expecting Pod resource","messagePattern":"expecting Pod resource","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dao/pod.go","lineNumber":301,"sourceCode":"\t}\n\n\treturn refs, nil\n}\n\n// Scan scans for cluster resource refs.\nfunc (p *Pod) Scan(_ context.Context, gvr *client.GVR, fqn string, wait bool) (Refs, error) {\n\tns, n := client.Namespaced(fqn)\n\too, err := p.getFactory().List(p.gvr, ns, wait, labels.Everything())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\trefs := make(Refs, 0, len(oo))\n\tfor _, o := range oo {\n\t\tvar pod v1.Pod\n\t\terr = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &pod)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"expecting Pod resource\")\n\t\t}\n\t\t// Just pick controller less pods...\n\t\tif len(pod.OwnerReferences) > 0 {\n\t\t\tcontinue\n\t\t}\n\t\tswitch gvr {\n\t\tcase client.CmGVR:\n\t\t\tif !hasConfigMap(&pod.Spec, n) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\trefs = append(refs, Ref{\n\t\t\t\tGVR: p.GVR(),\n\t\t\t\tFQN: client.FQN(pod.Namespace, pod.Name),\n\t\t\t})\n\t\tcase client.SecGVR:\n\t\t\tfound, err := hasSecret(p.Factory, &pod.Spec, pod.Namespace, n, wait)\n\t\t\tif err != nil {\n\t\t\t\tslog.Warn(\"Locate secret failed\",","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/dao/pod.go#L283-L319","documentation":"Pod.Scan converts every controller-less pod in a namespace into v1.Pod to find ConfigMap, Secret and PVC references (internal/dao/pod.go:301); it backs the xray view and UsedBy on configmaps/secrets/PVCs. If any object fails conversion, the sentinel 'expecting Pod resource' aborts the whole scan and the underlying converter error is discarded.","triggerScenarios":"Opening an xray or reference scan (CmGVR, SecGVR, PvcGVR) in a namespace where one cached pod object cannot convert to the compiled v1.Pod struct — k9s/cluster version skew (pod spec fields changing across Kubernetes releases), injector webhooks writing out-of-schema fields, or an aggregated source shadowing pods.core.","commonSituations":"xray or UsedBy views failing wholesale after cluster upgrades on older k9s builds; service meshes or mutating sidecar injectors adding non-schema fields to pods; environments running mixed Kubernetes versions.","solutions":["Audit pods in the namespace (kubectl get pods -o yaml) for unexpected or mistyped fields; fix injector templates or manifests.","Upgrade k9s so its vendored k8s.io/* versions match the cluster minor version.","Verify pods.core is served by the core apiserver and not shadowed.","Restart k9s to rebuild informer caches.","Patch the loop to skip unparsable pods with a warning so one object cannot kill the scan."],"exampleFix":"// before\nif err != nil {\n    return nil, errors.New(\"expecting Pod resource\")\n}\n// after (scan loops: degrade per object)\nif err != nil {\n    slog.Warn(\"skip unparsable pod\", \"index\", i, \"err\", err)\n    continue\n}","handlingStrategy":"try-catch","validationCode":"for _, o := range oo {\n    u, ok := o.(*unstructured.Unstructured)\n    if !ok || u.GroupVersionKind().Kind != \"Pod\" {\n        continue\n    }\n    // safe to convert below\n}","typeGuard":"func isPod(o runtime.Object) bool {\n    u, ok := o.(*unstructured.Unstructured)\n    return ok && u.GroupVersionKind().Kind == \"Pod\" && u.GroupVersionKind().Group == \"\"\n}","tryCatchPattern":"if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &pod); err != nil {\n    slog.Warn(\"skip unparsable pod\", \"err\", err)\n    continue\n}","preventionTips":["Treat pod-scan conversions as per-object warnings, not fatal errors.","Validate mutating webhooks (meshes, sidecar injectors) against the v1 Pod schema.","Keep k9s's k8s.io/api in sync with the cluster minor version.","Wrap converter errors with %w to keep the offending field visible."],"tags":["kubernetes","go","type-conversion","pod","references"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}