Skip to content

Commit 4efed03

Browse files
authored
Merge pull request kubernetes#91637 from robscott/endpointslice-mirroring
Adding new EndpointSlice Mirroring Controller
2 parents 26f0227 + fa59370 commit 4efed03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5168
-72
lines changed

api/api-rules/violation_exceptions.list

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,E
488488
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,ConcurrentServiceEndpointSyncs
489489
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,EndpointUpdatesBatchPeriod
490490
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,MaxEndpointsPerSlice
491+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceMirroringControllerConfiguration,MirroringConcurrentServiceEndpointSyncs
492+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceMirroringControllerConfiguration,MirroringEndpointUpdatesBatchPeriod
493+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceMirroringControllerConfiguration,MirroringMaxEndpointsPerSubset
491494
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,ConcurrentGCSyncs
492495
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,EnableGarbageCollector
493496
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,GCIgnoredResources
@@ -529,6 +532,7 @@ API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,K
529532
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,DeprecatedController
530533
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,EndpointController
531534
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,EndpointSliceController
535+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,EndpointSliceMirroringController
532536
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,GarbageCollectorController
533537
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,Generic
534538
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,HPAController

cmd/cloud-controller-manager/.import-restrictions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ rules:
3939
- k8s.io/kubernetes/pkg/controller/endpoint/config/v1alpha1
4040
- k8s.io/kubernetes/pkg/controller/endpointslice/config
4141
- k8s.io/kubernetes/pkg/controller/endpointslice/config/v1alpha1
42+
- k8s.io/kubernetes/pkg/controller/endpointslicemirroring/config
43+
- k8s.io/kubernetes/pkg/controller/endpointslicemirroring/config/v1alpha1
4244
- k8s.io/kubernetes/pkg/controller/garbagecollector/config
4345
- k8s.io/kubernetes/pkg/controller/garbagecollector/config/v1alpha1
4446
- k8s.io/kubernetes/pkg/controller/job/config

cmd/kube-controller-manager/app/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ go_library(
5656
"//pkg/controller/disruption:go_default_library",
5757
"//pkg/controller/endpoint:go_default_library",
5858
"//pkg/controller/endpointslice:go_default_library",
59+
"//pkg/controller/endpointslicemirroring:go_default_library",
5960
"//pkg/controller/garbagecollector:go_default_library",
6061
"//pkg/controller/job:go_default_library",
6162
"//pkg/controller/namespace:go_default_library",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc
387387
controllers := map[string]InitFunc{}
388388
controllers["endpoint"] = startEndpointController
389389
controllers["endpointslice"] = startEndpointSliceController
390+
controllers["endpointslicemirroring"] = startEndpointSliceMirroringController
390391
controllers["replicationcontroller"] = startReplicationController
391392
controllers["podgc"] = startPodGCController
392393
controllers["resourcequota"] = startResourceQuotaController

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ type controllerInitFunc func(ControllerContext) (http.Handler, bool, error)
9797

9898
func TestController_DiscoveryError(t *testing.T) {
9999
controllerInitFuncMap := map[string]controllerInitFunc{
100-
"ResourceQuotaController": startResourceQuotaController,
101-
"GarbageCollectorController": startGarbageCollectorController,
100+
"ResourceQuotaController": startResourceQuotaController,
101+
"GarbageCollectorController": startGarbageCollectorController,
102+
"EndpointSliceController": startEndpointSliceController,
103+
"EndpointSliceMirroringController": startEndpointSliceMirroringController,
102104
}
103105

104106
tcs := map[string]struct {

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ import (
2727
utilfeature "k8s.io/apiserver/pkg/util/feature"
2828
"k8s.io/klog/v2"
2929
endpointslicecontroller "k8s.io/kubernetes/pkg/controller/endpointslice"
30+
endpointslicemirroringcontroller "k8s.io/kubernetes/pkg/controller/endpointslicemirroring"
3031
"k8s.io/kubernetes/pkg/features"
3132
)
3233

3334
func startEndpointSliceController(ctx ControllerContext) (http.Handler, bool, error) {
3435
if !utilfeature.DefaultFeatureGate.Enabled(features.EndpointSlice) {
35-
klog.V(4).Infof("Not starting endpointslice-controller since EndpointSlice feature gate is disabled")
36+
klog.V(2).Infof("Not starting endpointslice-controller since EndpointSlice feature gate is disabled")
3637
return nil, false, nil
3738
}
3839

@@ -52,3 +53,25 @@ func startEndpointSliceController(ctx ControllerContext) (http.Handler, bool, er
5253
).Run(int(ctx.ComponentConfig.EndpointSliceController.ConcurrentServiceEndpointSyncs), ctx.Stop)
5354
return nil, true, nil
5455
}
56+
57+
func startEndpointSliceMirroringController(ctx ControllerContext) (http.Handler, bool, error) {
58+
if !utilfeature.DefaultFeatureGate.Enabled(features.EndpointSlice) {
59+
klog.V(2).Infof("Not starting endpointslicemirroring-controller since EndpointSlice feature gate is disabled")
60+
return nil, false, nil
61+
}
62+
63+
if !ctx.AvailableResources[discoveryv1beta1.SchemeGroupVersion.WithResource("endpointslices")] {
64+
klog.Warningf("Not starting endpointslicemirroring-controller since discovery.k8s.io/v1beta1 resources are not available")
65+
return nil, false, nil
66+
}
67+
68+
go endpointslicemirroringcontroller.NewController(
69+
ctx.InformerFactory.Core().V1().Endpoints(),
70+
ctx.InformerFactory.Discovery().V1beta1().EndpointSlices(),
71+
ctx.InformerFactory.Core().V1().Services(),
72+
ctx.ComponentConfig.EndpointSliceMirroringController.MirroringMaxEndpointsPerSubset,
73+
ctx.ClientBuilder.ClientOrDie("endpointslicemirroring-controller"),
74+
ctx.ComponentConfig.EndpointSliceMirroringController.MirroringEndpointUpdatesBatchPeriod.Duration,
75+
).Run(int(ctx.ComponentConfig.EndpointSliceMirroringController.MirroringConcurrentServiceEndpointSyncs), ctx.Stop)
76+
return nil, true, nil
77+
}

cmd/kube-controller-manager/app/options/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"deprecatedcontroller.go",
1717
"endpointcontroller.go",
1818
"endpointslicecontroller.go",
19+
"endpointslicemirroringcontroller.go",
1920
"garbagecollectorcontroller.go",
2021
"hpacontroller.go",
2122
"jobcontroller.go",
@@ -43,6 +44,7 @@ go_library(
4344
"//pkg/controller/deployment/config:go_default_library",
4445
"//pkg/controller/endpoint/config:go_default_library",
4546
"//pkg/controller/endpointslice/config:go_default_library",
47+
"//pkg/controller/endpointslicemirroring/config:go_default_library",
4648
"//pkg/controller/garbagecollector:go_default_library",
4749
"//pkg/controller/garbagecollector/config:go_default_library",
4850
"//pkg/controller/job/config:go_default_library",
@@ -105,6 +107,7 @@ go_test(
105107
"//pkg/controller/deployment/config:go_default_library",
106108
"//pkg/controller/endpoint/config:go_default_library",
107109
"//pkg/controller/endpointslice/config:go_default_library",
110+
"//pkg/controller/endpointslicemirroring/config:go_default_library",
108111
"//pkg/controller/garbagecollector/config:go_default_library",
109112
"//pkg/controller/job/config:go_default_library",
110113
"//pkg/controller/namespace/config:go_default_library",
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package options
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/spf13/pflag"
23+
24+
endpointslicemirroringconfig "k8s.io/kubernetes/pkg/controller/endpointslicemirroring/config"
25+
)
26+
27+
const (
28+
mirroringMinConcurrentServiceEndpointSyncs = 1
29+
mirroringMaxConcurrentServiceEndpointSyncs = 50
30+
mirroringMinMaxEndpointsPerSubset = 1
31+
mirroringMaxMaxEndpointsPerSubset = 1000
32+
)
33+
34+
// EndpointSliceMirroringControllerOptions holds the
35+
// EndpointSliceMirroringController options.
36+
type EndpointSliceMirroringControllerOptions struct {
37+
*endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration
38+
}
39+
40+
// AddFlags adds flags related to EndpointSliceMirroringController for
41+
// controller manager to the specified FlagSet.
42+
func (o *EndpointSliceMirroringControllerOptions) AddFlags(fs *pflag.FlagSet) {
43+
if o == nil {
44+
return
45+
}
46+
47+
fs.Int32Var(&o.MirroringConcurrentServiceEndpointSyncs, "mirroring-concurrent-service-endpoint-syncs", o.MirroringConcurrentServiceEndpointSyncs, "The number of service endpoint syncing operations that will be done concurrently by the EndpointSliceMirroring controller. Larger number = faster endpoint slice updating, but more CPU (and network) load. Defaults to 5.")
48+
fs.Int32Var(&o.MirroringMaxEndpointsPerSubset, "mirroring-max-endpoints-per-subset", o.MirroringMaxEndpointsPerSubset, "The maximum number of endpoints that will be added to an EndpointSlice by the EndpointSliceMirroring controller. More endpoints per slice will result in less endpoint slices, but larger resources. Defaults to 100.")
49+
fs.DurationVar(&o.MirroringEndpointUpdatesBatchPeriod.Duration, "mirroring-endpointslice-updates-batch-period", o.MirroringEndpointUpdatesBatchPeriod.Duration, "The length of EndpointSlice updates batching period for EndpointSliceMirroring controller. Processing of EndpointSlice changes will be delayed by this duration to join them with potential upcoming updates and reduce the overall number of EndpointSlice updates. Larger number = higher endpoint programming latency, but lower number of endpoints revision generated")
50+
}
51+
52+
// ApplyTo fills up EndpointSliceMirroringController config with options.
53+
func (o *EndpointSliceMirroringControllerOptions) ApplyTo(cfg *endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration) error {
54+
if o == nil {
55+
return nil
56+
}
57+
58+
cfg.MirroringConcurrentServiceEndpointSyncs = o.MirroringConcurrentServiceEndpointSyncs
59+
cfg.MirroringMaxEndpointsPerSubset = o.MirroringMaxEndpointsPerSubset
60+
cfg.MirroringEndpointUpdatesBatchPeriod = o.MirroringEndpointUpdatesBatchPeriod
61+
62+
return nil
63+
}
64+
65+
// Validate checks validation of EndpointSliceMirroringControllerOptions.
66+
func (o *EndpointSliceMirroringControllerOptions) Validate() []error {
67+
if o == nil {
68+
return nil
69+
}
70+
71+
errs := []error{}
72+
73+
if o.MirroringConcurrentServiceEndpointSyncs < mirroringMinConcurrentServiceEndpointSyncs {
74+
errs = append(errs, fmt.Errorf("mirroring-concurrent-service-endpoint-syncs must not be less than %d, but got %d", mirroringMinConcurrentServiceEndpointSyncs, o.MirroringConcurrentServiceEndpointSyncs))
75+
} else if o.MirroringConcurrentServiceEndpointSyncs > mirroringMaxConcurrentServiceEndpointSyncs {
76+
errs = append(errs, fmt.Errorf("mirroring-concurrent-service-endpoint-syncs must not be more than %d, but got %d", mirroringMaxConcurrentServiceEndpointSyncs, o.MirroringConcurrentServiceEndpointSyncs))
77+
}
78+
79+
if o.MirroringMaxEndpointsPerSubset < mirroringMinMaxEndpointsPerSubset {
80+
errs = append(errs, fmt.Errorf("mirroring-max-endpoints-per-subset must not be less than %d, but got %d", mirroringMinMaxEndpointsPerSubset, o.MirroringMaxEndpointsPerSubset))
81+
} else if o.MirroringMaxEndpointsPerSubset > mirroringMaxMaxEndpointsPerSubset {
82+
errs = append(errs, fmt.Errorf("mirroring-max-endpoints-per-subset must not be more than %d, but got %d", mirroringMaxMaxEndpointsPerSubset, o.MirroringMaxEndpointsPerSubset))
83+
}
84+
85+
return errs
86+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type KubeControllerManagerOptions struct {
6767
DeprecatedFlags *DeprecatedControllerOptions
6868
EndpointController *EndpointControllerOptions
6969
EndpointSliceController *EndpointSliceControllerOptions
70+
EndpointSliceMirroringController *EndpointSliceMirroringControllerOptions
7071
GarbageCollectorController *GarbageCollectorControllerOptions
7172
HPAController *HPAControllerOptions
7273
JobController *JobControllerOptions
@@ -131,6 +132,9 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
131132
EndpointSliceController: &EndpointSliceControllerOptions{
132133
&componentConfig.EndpointSliceController,
133134
},
135+
EndpointSliceMirroringController: &EndpointSliceMirroringControllerOptions{
136+
&componentConfig.EndpointSliceMirroringController,
137+
},
134138
GarbageCollectorController: &GarbageCollectorControllerOptions{
135139
&componentConfig.GarbageCollectorController,
136140
},
@@ -236,6 +240,7 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
236240
s.DeprecatedFlags.AddFlags(fss.FlagSet("deprecated"))
237241
s.EndpointController.AddFlags(fss.FlagSet("endpoint controller"))
238242
s.EndpointSliceController.AddFlags(fss.FlagSet("endpointslice controller"))
243+
s.EndpointSliceMirroringController.AddFlags(fss.FlagSet("endpointslicemirroring controller"))
239244
s.GarbageCollectorController.AddFlags(fss.FlagSet("garbagecollector controller"))
240245
s.HPAController.AddFlags(fss.FlagSet("horizontalpodautoscaling controller"))
241246
s.JobController.AddFlags(fss.FlagSet("job controller"))
@@ -292,6 +297,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config) e
292297
if err := s.EndpointSliceController.ApplyTo(&c.ComponentConfig.EndpointSliceController); err != nil {
293298
return err
294299
}
300+
if err := s.EndpointSliceMirroringController.ApplyTo(&c.ComponentConfig.EndpointSliceMirroringController); err != nil {
301+
return err
302+
}
295303
if err := s.GarbageCollectorController.ApplyTo(&c.ComponentConfig.GarbageCollectorController); err != nil {
296304
return err
297305
}
@@ -371,6 +379,7 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
371379
errs = append(errs, s.DeprecatedFlags.Validate()...)
372380
errs = append(errs, s.EndpointController.Validate()...)
373381
errs = append(errs, s.EndpointSliceController.Validate()...)
382+
errs = append(errs, s.EndpointSliceMirroringController.Validate()...)
374383
errs = append(errs, s.GarbageCollectorController.Validate()...)
375384
errs = append(errs, s.HPAController.Validate()...)
376385
errs = append(errs, s.JobController.Validate()...)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
deploymentconfig "k8s.io/kubernetes/pkg/controller/deployment/config"
4040
endpointconfig "k8s.io/kubernetes/pkg/controller/endpoint/config"
4141
endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
42+
endpointslicemirroringconfig "k8s.io/kubernetes/pkg/controller/endpointslicemirroring/config"
4243
garbagecollectorconfig "k8s.io/kubernetes/pkg/controller/garbagecollector/config"
4344
jobconfig "k8s.io/kubernetes/pkg/controller/job/config"
4445
namespaceconfig "k8s.io/kubernetes/pkg/controller/namespace/config"
@@ -111,6 +112,8 @@ var args = []string{
111112
"--master=192.168.4.20",
112113
"--max-endpoints-per-slice=200",
113114
"--min-resync-period=8h",
115+
"--mirroring-concurrent-service-endpoint-syncs=2",
116+
"--mirroring-max-endpoints-per-subset=1000",
114117
"--namespace-sync-period=10m",
115118
"--node-cidr-mask-size=48",
116119
"--node-cidr-mask-size-ipv4=48",
@@ -251,6 +254,12 @@ func TestAddFlags(t *testing.T) {
251254
MaxEndpointsPerSlice: 200,
252255
},
253256
},
257+
EndpointSliceMirroringController: &EndpointSliceMirroringControllerOptions{
258+
&endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration{
259+
MirroringConcurrentServiceEndpointSyncs: 2,
260+
MirroringMaxEndpointsPerSubset: 1000,
261+
},
262+
},
254263
GarbageCollectorController: &GarbageCollectorControllerOptions{
255264
&garbagecollectorconfig.GarbageCollectorControllerConfiguration{
256265
ConcurrentGCSyncs: 30,
@@ -483,6 +492,10 @@ func TestApplyTo(t *testing.T) {
483492
ConcurrentServiceEndpointSyncs: 10,
484493
MaxEndpointsPerSlice: 200,
485494
},
495+
EndpointSliceMirroringController: endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration{
496+
MirroringConcurrentServiceEndpointSyncs: 2,
497+
MirroringMaxEndpointsPerSubset: 1000,
498+
},
486499
GarbageCollectorController: garbagecollectorconfig.GarbageCollectorControllerConfiguration{
487500
ConcurrentGCSyncs: 30,
488501
GCIgnoredResources: []garbagecollectorconfig.GroupResource{

0 commit comments

Comments
 (0)