Skip to content

Commit 49b11b5

Browse files
committed
Implement simple endpoint slice batching
1 parent b6b494b commit 49b11b5

File tree

11 files changed

+426
-10
lines changed

11 files changed

+426
-10
lines changed

api/api-rules/violation_exceptions.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,D
597597
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointControllerConfiguration,ConcurrentEndpointSyncs
598598
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointControllerConfiguration,EndpointUpdatesBatchPeriod
599599
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,ConcurrentServiceEndpointSyncs
600+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,EndpointUpdatesBatchPeriod
600601
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,MaxEndpointsPerSlice
601602
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,ConcurrentGCSyncs
602603
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,EnableGarbageCollector

cmd/kube-controller-manager/app/discovery.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func startEndpointSliceController(ctx ControllerContext) (http.Handler, bool, er
4848
ctx.InformerFactory.Discovery().V1beta1().EndpointSlices(),
4949
ctx.ComponentConfig.EndpointSliceController.MaxEndpointsPerSlice,
5050
ctx.ClientBuilder.ClientOrDie("endpointslice-controller"),
51+
ctx.ComponentConfig.EndpointSliceController.EndpointUpdatesBatchPeriod.Duration,
5152
).Run(int(ctx.ComponentConfig.EndpointSliceController.ConcurrentServiceEndpointSyncs), ctx.Stop)
5253
return nil, true, nil
5354
}

cmd/kube-controller-manager/app/options/endpointslicecontroller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package options
1818

1919
import (
2020
"fmt"
21+
2122
"github.com/spf13/pflag"
2223

2324
endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
@@ -43,6 +44,7 @@ func (o *EndpointSliceControllerOptions) AddFlags(fs *pflag.FlagSet) {
4344

4445
fs.Int32Var(&o.ConcurrentServiceEndpointSyncs, "concurrent-service-endpoint-syncs", o.ConcurrentServiceEndpointSyncs, "The number of service endpoint syncing operations that will be done concurrently. Larger number = faster endpoint slice updating, but more CPU (and network) load. Defaults to 5.")
4546
fs.Int32Var(&o.MaxEndpointsPerSlice, "max-endpoints-per-slice", o.MaxEndpointsPerSlice, "The maximum number of endpoints that will be added to an EndpointSlice. More endpoints per slice will result in less endpoint slices, but larger resources. Defaults to 100.")
47+
fs.DurationVar(&o.EndpointUpdatesBatchPeriod.Duration, "endpointslice-updates-batch-period", o.EndpointUpdatesBatchPeriod.Duration, "The length of endpoint slice updates batching period. Processing of pod changes will be delayed by this duration to join them with potential upcoming updates and reduce the overall number of endpoints updates. Larger number = higher endpoint programming latency, but lower number of endpoints revision generated")
4648
}
4749

4850
// ApplyTo fills up EndpointSliceController config with options.
@@ -53,6 +55,7 @@ func (o *EndpointSliceControllerOptions) ApplyTo(cfg *endpointsliceconfig.Endpoi
5355

5456
cfg.ConcurrentServiceEndpointSyncs = o.ConcurrentServiceEndpointSyncs
5557
cfg.MaxEndpointsPerSlice = o.MaxEndpointsPerSlice
58+
cfg.EndpointUpdatesBatchPeriod = o.EndpointUpdatesBatchPeriod
5659

5760
return nil
5861
}

pkg/controller/endpointslice/config/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ go_library(
99
],
1010
importpath = "k8s.io/kubernetes/pkg/controller/endpointslice/config",
1111
visibility = ["//visibility:public"],
12+
deps = ["//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library"],
1213
)
1314

1415
filegroup(

pkg/controller/endpointslice/config/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ limitations under the License.
1616

1717
package config
1818

19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
1923
// EndpointSliceControllerConfiguration contains elements describing
2024
// EndpointSliceController.
2125
type EndpointSliceControllerConfiguration struct {
@@ -28,4 +32,11 @@ type EndpointSliceControllerConfiguration struct {
2832
// added to an EndpointSlice. More endpoints per slice will result in fewer
2933
// and larger endpoint slices, but larger resources.
3034
MaxEndpointsPerSlice int32
35+
36+
// EndpointUpdatesBatchPeriod can be used to batch endpoint updates.
37+
// All updates of endpoint triggered by pod change will be delayed by up to
38+
// 'EndpointUpdatesBatchPeriod'. If other pods in the same endpoint change
39+
// in that period, they will be batched to a single endpoint update.
40+
// Default 0 value means that each pod update triggers an endpoint update.
41+
EndpointUpdatesBatchPeriod metav1.Duration
3142
}

pkg/controller/endpointslice/config/v1alpha1/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/endpointslice/config/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/endpointslice/endpointslice_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func NewController(podInformer coreinformers.PodInformer,
6666
endpointSliceInformer discoveryinformers.EndpointSliceInformer,
6767
maxEndpointsPerSlice int32,
6868
client clientset.Interface,
69+
endpointUpdatesBatchPeriod time.Duration,
6970
) *Controller {
7071
broadcaster := record.NewBroadcaster()
7172
broadcaster.StartLogging(klog.Infof)
@@ -129,6 +130,7 @@ func NewController(podInformer coreinformers.PodInformer,
129130
c.eventBroadcaster = broadcaster
130131
c.eventRecorder = recorder
131132

133+
c.endpointUpdatesBatchPeriod = endpointUpdatesBatchPeriod
132134
c.serviceSelectorCache = endpointutil.NewServiceSelectorCache()
133135

134136
return c
@@ -194,6 +196,10 @@ type Controller struct {
194196
// process the queue of service and pod changes
195197
workerLoopPeriod time.Duration
196198

199+
// endpointUpdatesBatchPeriod is an artificial delay added to all service syncs triggered by pod changes.
200+
// This can be used to reduce overall number of all endpoint slice updates.
201+
endpointUpdatesBatchPeriod time.Duration
202+
197203
// serviceSelectorCache is a cache of service selectors to avoid high CPU consumption caused by frequent calls
198204
// to AsSelectorPreValidated (see #73527)
199205
serviceSelectorCache *endpointutil.ServiceSelectorCache
@@ -414,14 +420,14 @@ func (c *Controller) addPod(obj interface{}) {
414420
return
415421
}
416422
for key := range services {
417-
c.queue.Add(key)
423+
c.queue.AddAfter(key, c.endpointUpdatesBatchPeriod)
418424
}
419425
}
420426

421427
func (c *Controller) updatePod(old, cur interface{}) {
422428
services := endpointutil.GetServicesToUpdateOnPodChange(c.serviceLister, c.serviceSelectorCache, old, cur, podEndpointChanged)
423429
for key := range services {
424-
c.queue.Add(key)
430+
c.queue.AddAfter(key, c.endpointUpdatesBatchPeriod)
425431
}
426432
}
427433

0 commit comments

Comments
 (0)