Skip to content

Commit ec6fd2b

Browse files
Add options construct to EndpointSlice NewReconciler for the new trafficDistributionEnabled field
1 parent 606cae9 commit ec6fd2b

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

pkg/controller/endpointslice/endpointslice_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ func NewController(ctx context.Context, podInformer coreinformers.PodInformer,
173173
c.maxEndpointsPerSlice,
174174
c.endpointSliceTracker,
175175
c.topologyCache,
176-
utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution),
177176
c.eventRecorder,
178177
controllerName,
178+
endpointslicerec.WithTrafficDistributionEnabled(utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution)),
179179
)
180180

181181
return c

staging/src/k8s.io/endpointslice/reconciler.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ type Reconciler struct {
5959
controllerName string
6060
}
6161

62+
type ReconcilerOption func(*Reconciler)
63+
64+
// WithTrafficDistributionEnabled controls whether the Reconciler considers the
65+
// `trafficDistribution` field while reconciling EndpointSlices.
66+
func WithTrafficDistributionEnabled(enabled bool) ReconcilerOption {
67+
return func(r *Reconciler) {
68+
r.trafficDistributionEnabled = enabled
69+
}
70+
}
71+
6272
// endpointMeta includes the attributes we group slices on, this type helps with
6373
// that logic in Reconciler
6474
type endpointMeta struct {
@@ -327,18 +337,21 @@ func (r *Reconciler) reconcileByAddressType(logger klog.Logger, service *corev1.
327337

328338
}
329339

330-
func NewReconciler(client clientset.Interface, nodeLister corelisters.NodeLister, maxEndpointsPerSlice int32, endpointSliceTracker *endpointsliceutil.EndpointSliceTracker, topologyCache *topologycache.TopologyCache, trafficDistributionEnabled bool, eventRecorder record.EventRecorder, controllerName string) *Reconciler {
331-
return &Reconciler{
332-
client: client,
333-
nodeLister: nodeLister,
334-
maxEndpointsPerSlice: maxEndpointsPerSlice,
335-
endpointSliceTracker: endpointSliceTracker,
336-
metricsCache: metrics.NewCache(maxEndpointsPerSlice),
337-
topologyCache: topologyCache,
338-
trafficDistributionEnabled: trafficDistributionEnabled,
339-
eventRecorder: eventRecorder,
340-
controllerName: controllerName,
340+
func NewReconciler(client clientset.Interface, nodeLister corelisters.NodeLister, maxEndpointsPerSlice int32, endpointSliceTracker *endpointsliceutil.EndpointSliceTracker, topologyCache *topologycache.TopologyCache, eventRecorder record.EventRecorder, controllerName string, options ...ReconcilerOption) *Reconciler {
341+
r := &Reconciler{
342+
client: client,
343+
nodeLister: nodeLister,
344+
maxEndpointsPerSlice: maxEndpointsPerSlice,
345+
endpointSliceTracker: endpointSliceTracker,
346+
metricsCache: metrics.NewCache(maxEndpointsPerSlice),
347+
topologyCache: topologyCache,
348+
eventRecorder: eventRecorder,
349+
controllerName: controllerName,
350+
}
351+
for _, option := range options {
352+
option(r)
341353
}
354+
return r
342355
}
343356

344357
// placeholderSliceCompare is a conversion func for comparing two placeholder endpoint slices.

staging/src/k8s.io/endpointslice/reconciler_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,6 @@ func newReconciler(client *fake.Clientset, nodes []*corev1.Node, maxEndpointsPer
21992199
maxEndpointsPerSlice,
22002200
endpointsliceutil.NewEndpointSliceTracker(),
22012201
nil,
2202-
false,
22032202
eventRecorder,
22042203
controllerName,
22052204
)

0 commit comments

Comments
 (0)