{"record":{"id":"d18827557faa1b9a","repo":"kubernetes/kubernetes","slug":"adding-slice-event-handler-w","errorCode":null,"errorMessage":"adding slice event handler: %w","messagePattern":"adding slice event handler: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/controller/devicetainteviction/device_taint_eviction.go","lineNumber":1018,"sourceCode":"\t\t\t}\n\t\t\ttc.mutex.Lock()\n\t\t\tdefer tc.mutex.Unlock()\n\t\t\ttc.handleSliceChange(oldSlice, newSlice)\n\t\t},\n\t\tDeleteFunc: func(obj any) {\n\t\t\t// No need to check for DeletedFinalStateUnknown here, the resourceslicetracker doesn't use that.\n\t\t\tslice, ok := obj.(*resourceapi.ResourceSlice)\n\t\t\tif !ok {\n\t\t\t\tlogger.Error(nil, \"Expected ResourceSlice\", \"actual\", fmt.Sprintf(\"%T\", obj))\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttc.mutex.Lock()\n\t\t\tdefer tc.mutex.Unlock()\n\t\t\ttc.handleSliceChange(slice, nil)\n\t\t},\n\t}, cache.HandlerOptions{Logger: &logger})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"adding slice event handler: %w\", err)\n\t}\n\tdefer func() {\n\t\t_ = tc.sliceInformer.Informer().RemoveEventHandler(sliceHandler)\n\t}()\n\ttc.haveSynced = append(tc.haveSynced, sliceHandler.HasSyncedChecker())\n\n\tif !cache.WaitFor(ctx, \"cache and event handler sync\", tc.haveSynced...) {\n\t\t// If we get here, the caller canceled the context. This is not an error.\n\t\treturn nil\n\t}\n\tlogger.V(1).Info(\"Underlying informers have synced\")\n\ttc.hasSynced.Store(1)\n\n\tfor i := range numWorkers {\n\t\twg.Go(func() {\n\t\t\ttc.worker(klog.NewContext(ctx, klog.LoggerWithName(queueLogger, fmt.Sprintf(\"worker-%d\", i))))\n\t\t})\n\t}","sourceCodeStart":1000,"sourceCodeEnd":1036,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/b882c60b4023bdf09264c2d5d30a2cadebc240fb/pkg/controller/devicetainteviction/device_taint_eviction.go#L1000-L1036","documentation":"Returned when AddEventHandlerWithOptions fails on the ResourceSlice informer (device_taint_eviction.go:1018). ResourceSlices carry the taint state published by drivers; the controller must react to slice changes to recompute evictions. Failure here aborts Run. Wrapped error comes from client-go informer handler registration.","triggerScenarios":"Registering ResourceSlice handlers on a stopped or non-started informer, or when the resourceslice informer was never constructed (nil sliceInformer). Also fires under concurrent factory shutdown.","commonSituations":"Missing ResourceSlice CRD during a partial DRA rollout; kube-controller-manager memory pressure tearing down informers mid-flight; CI runs that wire up the eviction controller but omit the ResourceSlice informer factory.","solutions":["Confirm the ResourceSlice CRD is installed and the API server serves resource.k8s.io/v1beta1.","Start the DRA informer factory and wait for slice cache sync before Run.","Inspect the wrapped error for the exact registration failure.","Restart the controller-manager to reset informer state if transient."],"exampleFix":"// before\ntc.sliceInformer = draInformer.Resource().V1beta1().ResourceSlices()\ngo tc.Run(ctx)\n\n// after\ntc.sliceInformer = draInformer.Resource().V1beta1().ResourceSlices()\ndraInformer.Start(ctx.Done())\ncache.WaitForCacheSync(ctx.Done(), tc.sliceInformer.Informer().HasSynced)\ngo func() { _ = tc.Run(ctx) }()","handlingStrategy":"retry","validationCode":"if sliceInformer == nil {\n  return fmt.Errorf(\"slice informer not configured\")\n}\ncache.WaitForCacheSync(ctx.Done(), sliceInformer.Informer().HasSynced)","typeGuard":null,"tryCatchPattern":"sliceHandler, err := sliceInformer.Informer().AddEventHandlerWithOptions(funcs, opts)\nif err != nil {\n  return fmt.Errorf(\"adding slice event handler: %w\", err)\n}\ndefer sliceInformer.Informer().RemoveEventHandler(sliceHandler)","preventionTips":["Construct the ResourceSlice informer from the same DRA factory as the rule/claim informers.","Verify the ResourceSlice CRD is installed via discovery at controller startup.","Always pair AddEventHandler with a deferred RemoveEventHandler.","In tests, start the fake DRA factory before invoking Run."],"tags":["kubernetes","controller","informer","dra","resource-slice","startup"],"analyzedSha":"b882c60b4023bdf09264c2d5d30a2cadebc240fb","analyzedAt":"2026-08-07T04:07:48.144Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}