Repository: kubernetes/kubernetes
File: staging/src/k8s.io/client-go/tools/cache/controller.go (Go)

Code before:

	fifo := newQueueFIFO(clientState, options.Transform)

	cfg := &Config{
		Queue:            fifo,
		ListerWatcher:    options.ListerWatcher,
		ObjectType:       options.ObjectType,
		FullResyncPeriod: options.ResyncPeriod,
		MinWatchTimeout:  options.MinWatchTimeout,

		Process: func(obj interface{}, isInInitialList bool) error {
			if deltas, ok := obj.(Deltas); ok {
				return processDeltas(options.Handler, clientState, deltas, isInInitialList, MetaNamespaceKeyFunc)
			}
			return errors.New("object given as Process argument is not Deltas")
		},
		ProcessBatch: func(deltaList []Delta, isInInitialList bool) error {
			return processDeltasInBatch(options.Handler, clientState, deltaList, isInInitialList, MetaNamespaceKeyFunc)
		},
	}
	return New(cfg)
}

func newQueueFIFO(clientState Store, transform TransformFunc) Queue {
	if clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.InOrderInformers) {
		atomic := clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.AtomicFIFO)
		// Unset clientState in the case of atomic events as we cannot pass a
		// store to an atomic fifo.
		if atomic {
			clientState = nil
		}
		return NewRealFIFOWithOptions(RealFIFOOptions{
			KeyFunction:  MetaNamespaceKeyFunc,
			KnownObjects: clientState,
			Transformer:  transform,
			AtomicEvents: atomic,
		})
	} else {
		return NewDeltaFIFOWithOptions(DeltaFIFOOptions{
			KnownObjects:          clientState,
			EmitDeltaTypeReplaced: true,
			Transformer:           transform,
		})
	}
}


Review comment (suggestion):
make the AtomicEvents / KnownObjects clearly mutually exclusive like this:

```go
options = RealFIFOOptions{
... everything except AtomicEvents and KnownObjects
}

if clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.AtomicFIFO) {
  options.AtomicEvents = true
} else {
  options.KnownObjects = clientState
}
```

Code after:
	fifo := newQueueFIFO(clientState, options.Transform)

	cfg := &Config{
		Queue:            fifo,
		ListerWatcher:    options.ListerWatcher,
		ObjectType:       options.ObjectType,
		FullResyncPeriod: options.ResyncPeriod,
		MinWatchTimeout:  options.MinWatchTimeout,

		Process: func(obj interface{}, isInInitialList bool) error {
			if deltas, ok := obj.(Deltas); ok {
				return processDeltas(options.Handler, clientState, deltas, isInInitialList, keyFunc)
			}
			return errors.New("object given as Process argument is not Deltas")
		},
		ProcessBatch: func(deltaList []Delta, isInInitialList bool) error {
			return processDeltasInBatch(options.Handler, clientState, deltaList, isInInitialList, keyFunc)
		},
	}
	return New(cfg)
}

func newQueueFIFO(clientState Store, transform TransformFunc) Queue {
	if clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.InOrderInformers) {
		options := RealFIFOOptions{
			KeyFunction: MetaNamespaceKeyFunc,
			Transformer: transform,
		}
		// If atomic events are enabled, unset clientState in the case of atomic events as we cannot pass a
		// store to an atomic fifo.
		if clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.AtomicFIFO) {
			options.AtomicEvents = true
		} else {
			options.KnownObjects = clientState
		}
		return NewRealFIFOWithOptions(options)
	} else {
		return NewDeltaFIFOWithOptions(DeltaFIFOOptions{
			KnownObjects:          clientState,
			EmitDeltaTypeReplaced: true,
			Transformer:           transform,
		})
	}
}