{"record":{"id":"fe31f24bc5ad3bc0","repo":"kubernetes/kops","slug":"error-listing-pods-v","errorCode":null,"errorMessage":"error listing pods: %v","messagePattern":"error listing pods: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns-controller/pkg/watchers/pod.go","lineNumber":80,"sourceCode":"\tstopCh := c.StopChannel()\n\tgo c.runWatcher(stopCh)\n\n\t<-stopCh\n\tklog.Infof(\"shutting down pod controller\")\n}\n\nfunc (c *PodController) runWatcher(stopCh <-chan struct{}) {\n\trunOnce := func() (bool, error) {\n\t\tctx := context.TODO()\n\n\t\tvar listOpts metav1.ListOptions\n\t\tklog.V(4).Infof(\"querying without label filter\")\n\n\t\tallKeys := c.scope.AllKeys()\n\n\t\tpodList, err := c.client.CoreV1().Pods(c.namespace).List(ctx, listOpts)\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"error listing pods: %v\", err)\n\t\t}\n\t\tfoundKeys := make(map[string]bool)\n\t\tfor i := range podList.Items {\n\t\t\tpod := &podList.Items[i]\n\t\t\tklog.V(4).Infof(\"found pod: %v\", pod.Name)\n\t\t\tkey := c.updatePodRecords(pod)\n\t\t\tfoundKeys[key] = true\n\t\t}\n\t\tfor _, key := range allKeys {\n\t\t\tif !foundKeys[key] {\n\t\t\t\t// The pod previous existed, but no longer exists; delete it from the scope\n\t\t\t\tklog.V(2).Infof(\"removing pod not found in list: %s\", key)\n\t\t\t\tc.scope.Replace(key, nil)\n\t\t\t}\n\t\t}\n\t\tc.scope.MarkReady()\n\n\t\tlistOpts.Watch = true","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/dns-controller/pkg/watchers/pod.go#L62-L98","documentation":"podController.runUpdater wraps failures from client.CoreV1().Pods(c.namespace).List(ctx, listOpts) as \"error listing pods: %v\". The controller lists pods (all pods or a single namespace) to build DNS records for pod IPs; on failure the sync is aborted and retried. The wrapped error identifies the underlying client-go failure.","triggerScenarios":"client.CoreV1().Pods(c.namespace).List(ctx, listOpts) errors: 403 (missing RBAC 'list pods' in the target namespace), context deadline, invalid namespace, or network failure to the apiserver.","commonSituations":"Namespace-restricted dns-controller whose ServiceAccount lacks pod list rights in that namespace; the specified namespace does not exist; apiserver connectivity problems during cluster upgrades.","solutions":["Grant the controller's ServiceAccount 'list'/'get' on pods in the configured namespace (or cluster-wide when namespace is empty).","Verify the --watch-namespace value exists and is spelled correctly.","Check the wrapped error after '%v': 403 => RBAC, timeout => connectivity.","Rely on the built-in retry for transient failures; investigate only if it loops."],"exampleFix":"// before: pod list denied in namespace\nrules:\n- apiGroups: [\"\"]\n  resources: [\"services\"]\n  verbs: [\"list\",\"watch\"]\n// after: add pods\nrules:\n- apiGroups: [\"\"]\n  resources: [\"services\",\"pods\"]\n  verbs: [\"list\",\"watch\"]","handlingStrategy":"try-catch","validationCode":"// Go: preflight pod list in the target namespace\nns := \"\" // empty means all namespaces\nif _, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{Limit: 1}); err != nil {\n    return fmt.Errorf(\"preflight pod list failed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"podList, err := client.CoreV1().Pods(c.namespace).List(ctx, listOpts)\nif err != nil {\n    klog.Errorf(\"pod list failed in ns %q: %v\", c.namespace, err)\n    time.Sleep(backoff)\n    return false, nil\n}","preventionTips":["Grant pod list/get RBAC in the watched namespace (cluster-wide if --watch-namespace is empty).","Verify the namespace exists before setting --watch-namespace.","Use 'kubectl auth can-i list pods -n <ns> --as=system:serviceaccount:<ns>:<sa>' to precheck."],"tags":["kubernetes","dns-controller","rbac","pods"],"backgroundTag":"kubernetes-api-list-failed","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"}