{"record":{"id":"657d7a1dbe173f6b","repo":"slimtoolkit/slim","slug":"unexpected-more-than-one-target-pod-found","errorCode":null,"errorMessage":"unexpected - more than one target pod found","messagePattern":"unexpected - more than one target pod found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/inspectors/pod/pod_inspector.go","lineNumber":731,"sourceCode":"\t\t\tStatic().\n\t\t\tCoreV1().\n\t\t\tPods(namespace).\n\t\t\tList(context.TODO(), metav1.ListOptions{\n\t\t\t\tLabelSelector: targetPodLabelName + \"=\" + targetPodLabelValue,\n\t\t\t})\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\n\t\tif len(pods.Items) == 0 {\n\t\t\treturn false, nil // Keep waiting\n\t\t}\n\t\tif len(pods.Items) == 1 {\n\t\t\tpod = pods.Items[0]\n\t\t\treturn true, nil // Done\n\t\t}\n\n\t\treturn false, errors.New(\"unexpected - more than one target pod found\")\n\t})\n\n\treturn pod, err\n}\n\nfunc waitForContainer(\n\tctx context.Context,\n\tclient *kubernetes.Client,\n\tnamespace string,\n\tpodName string,\n\tcontName string,\n\tisInit bool,\n) error {\n\treturn wait.PollImmediateWithContext(ctx, 1*time.Second, 5*time.Minute, func(ctx context.Context) (bool, error) {\n\t\tpod, err := client.Static().CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/inspectors/pod/pod_inspector.go#L713-L749","documentation":"The pod inspector resolves a single target pod by polling until exactly one pod matches the selector. If the poll finds more than one matching pod, it aborts with this error rather than guessing which pod is the target. It is a guard against ambiguous pod selection.","triggerScenarios":"Calling an inspector flow that waits for a target pod (via waitForPod) when the pod selector/label query matches 2+ pods in the namespace at the same time.","commonSituations":"ReplicaSets/Deployments with more than one replica behind the inspected workload; leftover pods from a previous run still matching the same labels; two containers/rollouts overlapping during a rolling update.","solutions":["Ensure the target workload runs a single replica (scale down others) while inspecting","Narrow the pod selector/labels so only one pod matches","Delete stale/terminating pods from prior runs that still match the selector"],"exampleFix":"// before\ndeploy.spec.replicas = 3\n// after\ndeploy.spec.replicas = 1 // keep one target pod during inspection","handlingStrategy":"validation","validationCode":"// before waiting for the pod\npods, _ := clientset.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: sel})\nif len(pods.Items) != 1 { return fmt.Errorf(\"selector %q matches %d pods, need exactly 1\", sel, len(pods.Items)) }","typeGuard":null,"tryCatchPattern":"if err := runInspection(); err != nil {\n  if strings.Contains(err.Error(), \"more than one target pod\") {\n    // list matching pods, scale to 1 or refine selector, then retry\n  }\n}","preventionTips":["Run inspections against single-replica workloads","Use unique labels per inspected instance","Clean up stale pods from previous runs"],"tags":["kubernetes","pod","ambiguity"],"backgroundTag":"ambiguous-resource-selector","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}