Add options construct to EndpointSlice NewReconciler for the new trafficDistributionEnabled field

This commit is contained in:
Gaurav Ghildiyal 2024-03-04 14:07:45 -08:00
parent 606cae9b47
commit ec6fd2befa
3 changed files with 25 additions and 13 deletions

View File

@ -173,9 +173,9 @@ func NewController(ctx context.Context, podInformer coreinformers.PodInformer,
c.maxEndpointsPerSlice, c.maxEndpointsPerSlice,
c.endpointSliceTracker, c.endpointSliceTracker,
c.topologyCache, c.topologyCache,
utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution),
c.eventRecorder, c.eventRecorder,
controllerName, controllerName,
endpointslicerec.WithTrafficDistributionEnabled(utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution)),
) )
return c return c

View File

@ -59,6 +59,16 @@ type Reconciler struct {
controllerName string controllerName string
} }
type ReconcilerOption func(*Reconciler)
// WithTrafficDistributionEnabled controls whether the Reconciler considers the
// `trafficDistribution` field while reconciling EndpointSlices.
func WithTrafficDistributionEnabled(enabled bool) ReconcilerOption {
return func(r *Reconciler) {
r.trafficDistributionEnabled = enabled
}
}
// endpointMeta includes the attributes we group slices on, this type helps with // endpointMeta includes the attributes we group slices on, this type helps with
// that logic in Reconciler // that logic in Reconciler
type endpointMeta struct { type endpointMeta struct {
@ -327,18 +337,21 @@ func (r *Reconciler) reconcileByAddressType(logger klog.Logger, service *corev1.
} }
func NewReconciler(client clientset.Interface, nodeLister corelisters.NodeLister, maxEndpointsPerSlice int32, endpointSliceTracker *endpointsliceutil.EndpointSliceTracker, topologyCache *topologycache.TopologyCache, trafficDistributionEnabled bool, eventRecorder record.EventRecorder, controllerName string) *Reconciler { func NewReconciler(client clientset.Interface, nodeLister corelisters.NodeLister, maxEndpointsPerSlice int32, endpointSliceTracker *endpointsliceutil.EndpointSliceTracker, topologyCache *topologycache.TopologyCache, eventRecorder record.EventRecorder, controllerName string, options ...ReconcilerOption) *Reconciler {
return &Reconciler{ r := &Reconciler{
client: client, client: client,
nodeLister: nodeLister, nodeLister: nodeLister,
maxEndpointsPerSlice: maxEndpointsPerSlice, maxEndpointsPerSlice: maxEndpointsPerSlice,
endpointSliceTracker: endpointSliceTracker, endpointSliceTracker: endpointSliceTracker,
metricsCache: metrics.NewCache(maxEndpointsPerSlice), metricsCache: metrics.NewCache(maxEndpointsPerSlice),
topologyCache: topologyCache, topologyCache: topologyCache,
trafficDistributionEnabled: trafficDistributionEnabled, eventRecorder: eventRecorder,
eventRecorder: eventRecorder, controllerName: controllerName,
controllerName: controllerName,
} }
for _, option := range options {
option(r)
}
return r
} }
// placeholderSliceCompare is a conversion func for comparing two placeholder endpoint slices. // placeholderSliceCompare is a conversion func for comparing two placeholder endpoint slices.

View File

@ -2199,7 +2199,6 @@ func newReconciler(client *fake.Clientset, nodes []*corev1.Node, maxEndpointsPer
maxEndpointsPerSlice, maxEndpointsPerSlice,
endpointsliceutil.NewEndpointSliceTracker(), endpointsliceutil.NewEndpointSliceTracker(),
nil, nil,
false,
eventRecorder, eventRecorder,
controllerName, controllerName,
) )