Add options construct to EndpointSlice NewReconciler for the new trafficDistributionEnabled field
This commit is contained in:
		| @@ -173,9 +173,9 @@ func NewController(ctx context.Context, podInformer coreinformers.PodInformer, | ||||
| 		c.maxEndpointsPerSlice, | ||||
| 		c.endpointSliceTracker, | ||||
| 		c.topologyCache, | ||||
| 		utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution), | ||||
| 		c.eventRecorder, | ||||
| 		controllerName, | ||||
| 		endpointslicerec.WithTrafficDistributionEnabled(utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution)), | ||||
| 	) | ||||
|  | ||||
| 	return c | ||||
|   | ||||
| @@ -59,6 +59,16 @@ type Reconciler struct { | ||||
| 	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 | ||||
| // that logic in Reconciler | ||||
| 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 { | ||||
| 	return &Reconciler{ | ||||
| 		client:                     client, | ||||
| 		nodeLister:                 nodeLister, | ||||
| 		maxEndpointsPerSlice:       maxEndpointsPerSlice, | ||||
| 		endpointSliceTracker:       endpointSliceTracker, | ||||
| 		metricsCache:               metrics.NewCache(maxEndpointsPerSlice), | ||||
| 		topologyCache:              topologyCache, | ||||
| 		trafficDistributionEnabled: trafficDistributionEnabled, | ||||
| 		eventRecorder:              eventRecorder, | ||||
| 		controllerName:             controllerName, | ||||
| func NewReconciler(client clientset.Interface, nodeLister corelisters.NodeLister, maxEndpointsPerSlice int32, endpointSliceTracker *endpointsliceutil.EndpointSliceTracker, topologyCache *topologycache.TopologyCache, eventRecorder record.EventRecorder, controllerName string, options ...ReconcilerOption) *Reconciler { | ||||
| 	r := &Reconciler{ | ||||
| 		client:               client, | ||||
| 		nodeLister:           nodeLister, | ||||
| 		maxEndpointsPerSlice: maxEndpointsPerSlice, | ||||
| 		endpointSliceTracker: endpointSliceTracker, | ||||
| 		metricsCache:         metrics.NewCache(maxEndpointsPerSlice), | ||||
| 		topologyCache:        topologyCache, | ||||
| 		eventRecorder:        eventRecorder, | ||||
| 		controllerName:       controllerName, | ||||
| 	} | ||||
| 	for _, option := range options { | ||||
| 		option(r) | ||||
| 	} | ||||
| 	return r | ||||
| } | ||||
|  | ||||
| // placeholderSliceCompare is a conversion func for comparing two placeholder endpoint slices. | ||||
|   | ||||
| @@ -2199,7 +2199,6 @@ func newReconciler(client *fake.Clientset, nodes []*corev1.Node, maxEndpointsPer | ||||
| 		maxEndpointsPerSlice, | ||||
| 		endpointsliceutil.NewEndpointSliceTracker(), | ||||
| 		nil, | ||||
| 		false, | ||||
| 		eventRecorder, | ||||
| 		controllerName, | ||||
| 	) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Gaurav Ghildiyal
					Gaurav Ghildiyal