Repository: kubernetes/kubernetes
File: pkg/controller/statefulset/stateful_set.go (Go)

Code before:
	revInformer appsinformers.ControllerRevisionInformer,
	kubeClient clientset.Interface,
) *StatefulSetController {
	logger := klog.FromContext(ctx)
	eventBroadcaster := record.NewBroadcaster(record.WithContext(ctx))
	recorder := eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "statefulset-controller"})

	// Register metrics
	metrics.Register()
	if err := history.AddControllerRevisionControllerIndexer(revInformer.Informer()); err != nil {
		utilruntime.HandleError(fmt.Errorf("unable to add controller revision controller indexer: %w", err))
	}

	var consistencyStore consistencyutil.ConsistencyStore
	var podWriteCallback func(pod *v1.Pod, rs *metav1.OwnerReference)
	if utilfeature.DefaultFeatureGate.Enabled(features.StaleControllerConsistencyStatefulSet) {
		consistencyStore = consistencyutil.NewConsistencyStore(map[schema.GroupResource]consistencyutil.LastSyncRVGetter{
			podGroupResource:                   podInformer.Informer().GetStore(),
			persistentVolumeClaimGroupResource: pvcInformer.Informer().GetStore(),
			controllerRevisionGroupResource:    revInformer.Informer().GetStore(),
			statefulSetGroupResource:           setInformer.Informer().GetStore(),
		})
		podWriteCallback = func(pod *v1.Pod, rs *metav1.OwnerReference) {
			if rs == nil {
				return
			}
			consistencyStore.WroteAt(
				types.NamespacedName{
					Namespace: pod.Namespace,
					Name:      rs.Name,
				},
				rs.UID,
				podGroupResource,
				pod.ResourceVersion,
			)
		}
	} else {
		consistencyStore = consistencyutil.NewNoopConsistencyStore()
	}
	ssc := &StatefulSetController{
		kubeClient: kubeClient,
		control: NewDefaultStatefulSetControl(
			NewStatefulPodControl(
				kubeClient,
				podInformer.Lister(),
				pvcInformer.Lister(),
				recorder,
				consistencyStore),
			NewRealStatefulSetStatusUpdater(kubeClient, setInformer.Lister()),
			history.NewHistory(kubeClient, revInformer.Lister(), revInformer.Informer().GetIndexer()),
			consistencyStore,

Review comment (suggestion):
```suggestion
		podWriteCallback = func(pod *v1.Pod, ss *metav1.OwnerReference) {
			if ss == nil {
				return
			}
```

Code after:
	eventBroadcaster := record.NewBroadcaster(record.WithContext(ctx))
	recorder := eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "statefulset-controller"})

	// Register metrics
	metrics.Register()
	if err := history.AddControllerRevisionControllerIndexer(revInformer.Informer()); err != nil {
		utilruntime.HandleError(fmt.Errorf("unable to add controller revision controller indexer: %w", err))
	}

	var consistencyStore consistencyutil.ConsistencyStore
	var podWriteCallback func(pod *v1.Pod, rs *metav1.OwnerReference)
	if utilfeature.DefaultFeatureGate.Enabled(features.StaleControllerConsistencyStatefulSet) {
		consistencyStore = consistencyutil.NewConsistencyStore(map[schema.GroupResource]consistencyutil.LastSyncRVGetter{
			podGroupResource:                   podInformer.Informer().GetStore(),
			persistentVolumeClaimGroupResource: pvcInformer.Informer().GetStore(),
			statefulSetGroupResource:           setInformer.Informer().GetStore(),
		})
		podWriteCallback = func(pod *v1.Pod, ss *metav1.OwnerReference) {
			if ss == nil {
				return
			}
			consistencyStore.WroteAt(
				types.NamespacedName{
					Namespace: pod.Namespace,
					Name:      ss.Name,
				},
				ss.UID,
				podGroupResource,
				pod.ResourceVersion,
			)
		}
	} else {
		consistencyStore = consistencyutil.NewNoopConsistencyStore()
	}
	ssc := &StatefulSetController{
		kubeClient: kubeClient,
		control: NewDefaultStatefulSetControl(
			NewStatefulPodControl(
				kubeClient,
				podInformer.Lister(),
				pvcInformer.Lister(),
				recorder,
				consistencyStore),
			NewRealStatefulSetStatusUpdater(kubeClient, setInformer.Lister(), consistencyStore),
			history.NewHistory(kubeClient, revInformer.Lister(), revInformer.Informer().GetIndexer()),
		),
		pvcListerSynced: pvcInformer.Informer().HasSynced,
		revListerSynced: revInformer.Informer().HasSynced,
		queue: workqueue.NewTypedRateLimitingQueueWithConfig(
			workqueue.DefaultTypedControllerRateLimiter[string](),
			workqueue.TypedRateLimitingQueueConfig[string]{Name: "statefulset"},