mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	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.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
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user