kubernetes/kubernetes · error

adding slice event handler: %w

Error message

adding slice event handler: %w

What it means

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.

Source

Thrown at pkg/controller/devicetainteviction/device_taint_eviction.go:1018

			}
			tc.mutex.Lock()
			defer tc.mutex.Unlock()
			tc.handleSliceChange(oldSlice, newSlice)
		},
		DeleteFunc: func(obj any) {
			// No need to check for DeletedFinalStateUnknown here, the resourceslicetracker doesn't use that.
			slice, ok := obj.(*resourceapi.ResourceSlice)
			if !ok {
				logger.Error(nil, "Expected ResourceSlice", "actual", fmt.Sprintf("%T", obj))
				return
			}
			tc.mutex.Lock()
			defer tc.mutex.Unlock()
			tc.handleSliceChange(slice, nil)
		},
	}, cache.HandlerOptions{Logger: &logger})
	if err != nil {
		return fmt.Errorf("adding slice event handler: %w", err)
	}
	defer func() {
		_ = tc.sliceInformer.Informer().RemoveEventHandler(sliceHandler)
	}()
	tc.haveSynced = append(tc.haveSynced, sliceHandler.HasSyncedChecker())

	if !cache.WaitFor(ctx, "cache and event handler sync", tc.haveSynced...) {
		// If we get here, the caller canceled the context. This is not an error.
		return nil
	}
	logger.V(1).Info("Underlying informers have synced")
	tc.hasSynced.Store(1)

	for i := range numWorkers {
		wg.Go(func() {
			tc.worker(klog.NewContext(ctx, klog.LoggerWithName(queueLogger, fmt.Sprintf("worker-%d", i))))
		})
	}

View on GitHub (pinned to b882c60b40)

Solutions

  1. Confirm the ResourceSlice CRD is installed and the API server serves resource.k8s.io/v1beta1.
  2. Start the DRA informer factory and wait for slice cache sync before Run.
  3. Inspect the wrapped error for the exact registration failure.
  4. Restart the controller-manager to reset informer state if transient.

Example fix

// before
tc.sliceInformer = draInformer.Resource().V1beta1().ResourceSlices()
go tc.Run(ctx)

// after
tc.sliceInformer = draInformer.Resource().V1beta1().ResourceSlices()
draInformer.Start(ctx.Done())
cache.WaitForCacheSync(ctx.Done(), tc.sliceInformer.Informer().HasSynced)
go func() { _ = tc.Run(ctx) }()
Defensive patterns

Strategy: retry

Validate before calling

if sliceInformer == nil {
  return fmt.Errorf("slice informer not configured")
}
cache.WaitForCacheSync(ctx.Done(), sliceInformer.Informer().HasSynced)

Try / catch

sliceHandler, err := sliceInformer.Informer().AddEventHandlerWithOptions(funcs, opts)
if err != nil {
  return fmt.Errorf("adding slice event handler: %w", err)
}
defer sliceInformer.Informer().RemoveEventHandler(sliceHandler)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of kubernetes/kubernetes@b882c60b40 (2026-08-07). Data as JSON: /api/errors/d18827557faa1b9a. Report an issue: GitHub.