Client-go: Failed to watch *v1.Pod: unknown (get pods) when using an informer

Created on 2 Jul 2020  路  4Comments  路  Source: kubernetes/client-go

Hello we are implementing an informer to watch for pods with our label within a namespace but our logs are filled with the following error printing out every resync:

E0702 00:26:45.088538   78803 reflector.go:280] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:96: Failed to watch *v1.Pod: unknown (get pods)
options := func (options *metav1.ListOptions) {
        options.LabelSelector = "label"
    }
    sharedOptions := []informers.SharedInformerOption{
        informers.WithNamespace("default"),
        informers.WithTweakListOptions(options),
    }
    informer := informers.NewSharedInformerFactoryWithOptions(c, time.Second, sharedOptions...)
    podInformer := informer.Core().V1().Pods().Informer()
    podInformer.AddEventHandler(&cache.ResourceEventHandlerFuncs{
        AddFunc: func(obj interface{}) {
            pod := obj.(*v1.Pod)
            fmt.Println("Pod Added", pod.Name, pod.Status.Phase)
        },
        UpdateFunc: func(oldObj, newObj interface{}) {
            newPod := newObj.(*v1.Pod)

            fmt.Println("Pod updated", newPod.Name, newPod.Status.Phase, newPod.Status.Message)
        },
        DeleteFunc: func(obj interface{}) {
            pod := obj.(*v1.Pod)
            fmt.Println("Pod stopped", pod.Name, pod.Status.Reason)
        },
    })

    fmt.Println("startListener running,", podInformer.HasSynced())
    informer.Start(stop)
    for !podInformer.HasSynced() {

    }
    fmt.Println("startListener has synched",  podInformer.HasSynced())
lifecyclrotten

Most helpful comment

Does the ServiceAccount used by the operator has watch permissions on Pods?

All 4 comments

Does the ServiceAccount used by the operator has watch permissions on Pods?

Had similar problem with my CRD and it was because of permission as @fiunchinho noted, thanks!

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mheese picture mheese  路  5Comments

strugglingyouth picture strugglingyouth  路  5Comments

tamalsaha picture tamalsaha  路  6Comments

peterwillcn picture peterwillcn  路  5Comments

yashbhutwala picture yashbhutwala  路  4Comments