{"record":{"id":"59280f7c0c69030b","repo":"kubesphere/kubesphere","slug":"expect-v1-pod-got-v","errorCode":null,"errorMessage":"expect *v1.Pod, got %v","messagePattern":"expect \\*v1\\.Pod, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kube/pkg/quota/v1/evaluator/core/pods.go","lineNumber":293,"sourceCode":"\t\t\tresult[maskResourceWithPrefix(resource, corev1.DefaultResourceRequestsPrefix)] = request\n\t\t}\n\t\t// for extended resources\n\t\tif helper.IsExtendedResourceName(resource) {\n\t\t\t// only quota objects in format of \"requests.resourceName\" is allowed for extended resource.\n\t\t\tresult[maskResourceWithPrefix(resource, corev1.DefaultResourceRequestsPrefix)] = request\n\t\t}\n\t}\n\n\treturn result\n}\n\nfunc toExternalPodOrError(obj runtime.Object) (*corev1.Pod, error) {\n\tvar pod *corev1.Pod\n\tswitch t := obj.(type) {\n\tcase *corev1.Pod:\n\t\tpod = t\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"expect *v1.Pod, got %v\", t)\n\t}\n\treturn pod, nil\n}\n\n// podMatchesScopeFunc is a function that knows how to evaluate if a pod matches a scope\nfunc podMatchesScopeFunc(selector corev1.ScopedResourceSelectorRequirement, object runtime.Object) (bool, error) {\n\tpod, err := toExternalPodOrError(object)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tswitch selector.ScopeName {\n\tcase corev1.ResourceQuotaScopeTerminating:\n\t\treturn isTerminating(pod), nil\n\tcase corev1.ResourceQuotaScopeNotTerminating:\n\t\treturn !isTerminating(pod), nil\n\tcase corev1.ResourceQuotaScopeBestEffort:\n\t\treturn isBestEffort(pod), nil\n\tcase corev1.ResourceQuotaScopeNotBestEffort:","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/kubesphere/kubesphere/blob/04a29b5c601470fa6bc2f2e92358dcb802a0d414/kube/pkg/quota/v1/evaluator/core/pods.go#L275-L311","documentation":"The pod quota evaluator's type-assertion helper toExternalPodOrError requires a *corev1.Pod. Any other runtime.Object fails the type switch and yields this error. Constraints, podMatchesScopeFunc, and PodUsageFunc all rely on it, so a wrong-typed object at any of those entry points produces this message.","triggerScenarios":"Passing a runtime.Object that is not *corev1.Pod (internal v1.Pod from another package, nil object, or another resource entirely) into podEvaluator Constraints/MatchingScopes/Usage or podMatchesScopeFunc.","commonSituations":"Custom quota/admission plugins handling unconverted internal objects; tests reusing fixtures of the wrong type; refactored code paths that forgot the internal-to-external conversion step before quota evaluation.","solutions":["Convert the object to *corev1.Pod (scheme.Convert or the evaluator's toExternalPod helper) before calling quota evaluation APIs.","Verify the informer/handler feeding the evaluator is watching pods and delivering typed *corev1.Pod objects.","In tests, use typed corev1.Pod fixtures instead of generic runtime.Objects."],"exampleFix":"// before\nmatches, err := evaluator.MatchingScopes(internalPod, selectors)\n// after\npod := &corev1.Pod{}\nif err := scheme.Convert(internalPod, pod, nil); err != nil { return err }\nmatches, err := evaluator.MatchingScopes(pod, selectors)","handlingStrategy":"type-guard","validationCode":"if obj == nil { return fmt.Errorf(\"nil object passed to pod quota evaluator\") }\npod, ok := obj.(*corev1.Pod)\nif !ok { return fmt.Errorf(\"not a *corev1.Pod: %T\", obj) }","typeGuard":"func isExternalPod(obj runtime.Object) (*corev1.Pod, bool) {\n\tpod, ok := obj.(*corev1.Pod)\n\treturn pod, ok\n}","tryCatchPattern":"if err := evaluator.Constraints(resources, obj); err != nil {\n\tif strings.Contains(err.Error(), \"expect *v1.Pod\") {\n\t\t// convert the object to *corev1.Pod and retry\n\t}\n\treturn err\n}","preventionTips":["Convert internal types to corev1 external types before quota calls","Ensure informer handlers deliver typed *corev1.Pod objects","Nil-check objects before evaluator entry points"],"tags":["kubernetes","resource-quota","type-assertion","pod"],"backgroundTag":"unexpected-object-type","analyzedSha":"04a29b5c601470fa6bc2f2e92358dcb802a0d414","analyzedAt":"2026-09-03T18:33:15.017Z","contentChangedAt":"2026-09-03T18:33:15.017Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}