Skip to content

Commit 75f6c24

Browse files
committed
Adding EndpointSlice controller
1 parent 550fb1b commit 75f6c24

Some content is hidden

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

52 files changed

+3852
-562
lines changed

api/api-rules/violation_exceptions.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,D
576576
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,DeprecatedControllerConfiguration,RegisterRetryCount
577577
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointControllerConfiguration,ConcurrentEndpointSyncs
578578
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointControllerConfiguration,EndpointUpdatesBatchPeriod
579+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,ConcurrentServiceEndpointSyncs
580+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,EndpointSliceControllerConfiguration,MaxEndpointsPerSlice
579581
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,ConcurrentGCSyncs
580582
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,EnableGarbageCollector
581583
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,GarbageCollectorControllerConfiguration,GCIgnoredResources
@@ -616,6 +618,7 @@ API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,K
616618
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,DeploymentController
617619
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,DeprecatedController
618620
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,EndpointController
621+
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,EndpointSliceController
619622
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,GarbageCollectorController
620623
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,Generic
621624
API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,KubeControllerManagerConfiguration,HPAController

cmd/kube-controller-manager/app/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go_library(
1111
"cloudproviders.go",
1212
"controllermanager.go",
1313
"core.go",
14+
"discovery.go",
1415
"flags_providers.go",
1516
"import_known_versions.go",
1617
"plugins.go",
@@ -54,6 +55,7 @@ go_library(
5455
"//pkg/controller/deployment:go_default_library",
5556
"//pkg/controller/disruption:go_default_library",
5657
"//pkg/controller/endpoint:go_default_library",
58+
"//pkg/controller/endpointslice:go_default_library",
5759
"//pkg/controller/garbagecollector:go_default_library",
5860
"//pkg/controller/job:go_default_library",
5961
"//pkg/controller/namespace:go_default_library",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ func KnownControllers() []string {
360360
// ControllersDisabledByDefault is the set of controllers which is disabled by default
361361
var ControllersDisabledByDefault = sets.NewString(
362362
"bootstrapsigner",
363+
"endpointslice",
363364
"tokencleaner",
364365
)
365366

@@ -372,6 +373,7 @@ const (
372373
func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc {
373374
controllers := map[string]InitFunc{}
374375
controllers["endpoint"] = startEndpointController
376+
controllers["endpointslice"] = startEndpointSliceController
375377
controllers["replicationcontroller"] = startReplicationController
376378
controllers["podgc"] = startPodGCController
377379
controllers["resourcequota"] = startResourceQuotaController
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2016 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 app implements a server that runs a set of active
18+
// components. This includes replication controllers, service endpoints and
19+
// nodes.
20+
//
21+
package app
22+
23+
import (
24+
"net/http"
25+
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
endpointslicecontroller "k8s.io/kubernetes/pkg/controller/endpointslice"
28+
)
29+
30+
func startEndpointSliceController(ctx ControllerContext) (http.Handler, bool, error) {
31+
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "discovery", Version: "v1alpha1", Resource: "endpointslices"}] {
32+
return nil, false, nil
33+
}
34+
35+
go endpointslicecontroller.NewController(
36+
ctx.InformerFactory.Core().V1().Pods(),
37+
ctx.InformerFactory.Core().V1().Services(),
38+
ctx.InformerFactory.Core().V1().Nodes(),
39+
ctx.InformerFactory.Discovery().V1alpha1().EndpointSlices(),
40+
ctx.ComponentConfig.EndpointSliceController.MaxEndpointsPerSlice,
41+
ctx.ClientBuilder.ClientOrDie("endpointslice-controller"),
42+
).Run(int(ctx.ComponentConfig.EndpointSliceController.ConcurrentServiceEndpointSyncs), ctx.Stop)
43+
return nil, true, nil
44+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ go_library(
1515
"deploymentcontroller.go",
1616
"deprecatedcontroller.go",
1717
"endpointcontroller.go",
18+
"endpointslicecontroller.go",
1819
"garbagecollectorcontroller.go",
1920
"hpacontroller.go",
2021
"jobcontroller.go",
@@ -41,6 +42,7 @@ go_library(
4142
"//pkg/controller/daemon/config:go_default_library",
4243
"//pkg/controller/deployment/config:go_default_library",
4344
"//pkg/controller/endpoint/config:go_default_library",
45+
"//pkg/controller/endpointslice/config:go_default_library",
4446
"//pkg/controller/garbagecollector:go_default_library",
4547
"//pkg/controller/garbagecollector/config:go_default_library",
4648
"//pkg/controller/job/config:go_default_library",
@@ -100,6 +102,7 @@ go_test(
100102
"//pkg/controller/daemon/config:go_default_library",
101103
"//pkg/controller/deployment/config:go_default_library",
102104
"//pkg/controller/endpoint/config:go_default_library",
105+
"//pkg/controller/endpointslice/config:go_default_library",
103106
"//pkg/controller/garbagecollector/config:go_default_library",
104107
"//pkg/controller/job/config:go_default_library",
105108
"//pkg/controller/namespace/config:go_default_library",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright 2019 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+
"github.com/spf13/pflag"
22+
23+
endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
24+
)
25+
26+
const (
27+
minConcurrentServiceEndpointSyncs = 1
28+
maxConcurrentServiceEndpointSyncs = 50
29+
minMaxEndpointsPerSlice = 1
30+
maxMaxEndpointsPerSlice = 1000
31+
)
32+
33+
// EndpointSliceControllerOptions holds the EndpointSliceController options.
34+
type EndpointSliceControllerOptions struct {
35+
*endpointsliceconfig.EndpointSliceControllerConfiguration
36+
}
37+
38+
// AddFlags adds flags related to EndpointSliceController for controller manager to the specified FlagSet.
39+
func (o *EndpointSliceControllerOptions) AddFlags(fs *pflag.FlagSet) {
40+
if o == nil {
41+
return
42+
}
43+
44+
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.")
45+
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.")
46+
}
47+
48+
// ApplyTo fills up EndpointSliceController config with options.
49+
func (o *EndpointSliceControllerOptions) ApplyTo(cfg *endpointsliceconfig.EndpointSliceControllerConfiguration) error {
50+
if o == nil {
51+
return nil
52+
}
53+
54+
cfg.ConcurrentServiceEndpointSyncs = o.ConcurrentServiceEndpointSyncs
55+
cfg.MaxEndpointsPerSlice = o.MaxEndpointsPerSlice
56+
57+
return nil
58+
}
59+
60+
// Validate checks validation of EndpointSliceControllerOptions.
61+
func (o *EndpointSliceControllerOptions) Validate() []error {
62+
if o == nil {
63+
return nil
64+
}
65+
66+
errs := []error{}
67+
68+
if o.ConcurrentServiceEndpointSyncs < minConcurrentServiceEndpointSyncs {
69+
errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be less than %d, but got %d", minConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
70+
} else if o.ConcurrentServiceEndpointSyncs > maxConcurrentServiceEndpointSyncs {
71+
errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be more than %d, but got %d", maxConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
72+
}
73+
74+
if o.MaxEndpointsPerSlice < minMaxEndpointsPerSlice {
75+
errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be less than %d, but got %d", minMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
76+
} else if o.MaxEndpointsPerSlice > maxMaxEndpointsPerSlice {
77+
errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be more than %d, but got %d", maxMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
78+
}
79+
80+
return errs
81+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type KubeControllerManagerOptions struct {
6666
StatefulSetController *StatefulSetControllerOptions
6767
DeprecatedFlags *DeprecatedControllerOptions
6868
EndpointController *EndpointControllerOptions
69+
EndpointSliceController *EndpointSliceControllerOptions
6970
GarbageCollectorController *GarbageCollectorControllerOptions
7071
HPAController *HPAControllerOptions
7172
JobController *JobControllerOptions
@@ -124,6 +125,9 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
124125
EndpointController: &EndpointControllerOptions{
125126
&componentConfig.EndpointController,
126127
},
128+
EndpointSliceController: &EndpointSliceControllerOptions{
129+
&componentConfig.EndpointSliceController,
130+
},
127131
GarbageCollectorController: &GarbageCollectorControllerOptions{
128132
&componentConfig.GarbageCollectorController,
129133
},
@@ -226,6 +230,7 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
226230
s.DaemonSetController.AddFlags(fss.FlagSet("daemonset controller"))
227231
s.DeprecatedFlags.AddFlags(fss.FlagSet("deprecated"))
228232
s.EndpointController.AddFlags(fss.FlagSet("endpoint controller"))
233+
s.EndpointSliceController.AddFlags(fss.FlagSet("endpointslice controller"))
229234
s.GarbageCollectorController.AddFlags(fss.FlagSet("garbagecollector controller"))
230235
s.HPAController.AddFlags(fss.FlagSet("horizontalpodautoscaling controller"))
231236
s.JobController.AddFlags(fss.FlagSet("job controller"))
@@ -277,6 +282,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config) e
277282
if err := s.EndpointController.ApplyTo(&c.ComponentConfig.EndpointController); err != nil {
278283
return err
279284
}
285+
if err := s.EndpointSliceController.ApplyTo(&c.ComponentConfig.EndpointSliceController); err != nil {
286+
return err
287+
}
280288
if err := s.GarbageCollectorController.ApplyTo(&c.ComponentConfig.GarbageCollectorController); err != nil {
281289
return err
282290
}
@@ -355,6 +363,7 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
355363
errs = append(errs, s.StatefulSetController.Validate()...)
356364
errs = append(errs, s.DeprecatedFlags.Validate()...)
357365
errs = append(errs, s.EndpointController.Validate()...)
366+
errs = append(errs, s.EndpointSliceController.Validate()...)
358367
errs = append(errs, s.GarbageCollectorController.Validate()...)
359368
errs = append(errs, s.HPAController.Validate()...)
360369
errs = append(errs, s.JobController.Validate()...)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
daemonconfig "k8s.io/kubernetes/pkg/controller/daemon/config"
3636
deploymentconfig "k8s.io/kubernetes/pkg/controller/deployment/config"
3737
endpointconfig "k8s.io/kubernetes/pkg/controller/endpoint/config"
38+
endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
3839
garbagecollectorconfig "k8s.io/kubernetes/pkg/controller/garbagecollector/config"
3940
jobconfig "k8s.io/kubernetes/pkg/controller/job/config"
4041
namespaceconfig "k8s.io/kubernetes/pkg/controller/namespace/config"
@@ -74,6 +75,7 @@ func TestAddFlags(t *testing.T) {
7475
"--concurrent-deployment-syncs=10",
7576
"--concurrent-statefulset-syncs=15",
7677
"--concurrent-endpoint-syncs=10",
78+
"--concurrent-service-endpoint-syncs=10",
7779
"--concurrent-gc-syncs=30",
7880
"--concurrent-namespace-syncs=20",
7981
"--concurrent-replicaset-syncs=10",
@@ -111,6 +113,7 @@ func TestAddFlags(t *testing.T) {
111113
"--leader-elect-resource-lock=configmap",
112114
"--leader-elect-retry-period=5s",
113115
"--master=192.168.4.20",
116+
"--max-endpoints-per-slice=200",
114117
"--min-resync-period=8h",
115118
"--namespace-sync-period=10m",
116119
"--node-cidr-mask-size=48",
@@ -236,6 +239,12 @@ func TestAddFlags(t *testing.T) {
236239
ConcurrentEndpointSyncs: 10,
237240
},
238241
},
242+
EndpointSliceController: &EndpointSliceControllerOptions{
243+
&endpointsliceconfig.EndpointSliceControllerConfiguration{
244+
ConcurrentServiceEndpointSyncs: 10,
245+
MaxEndpointsPerSlice: 200,
246+
},
247+
},
239248
GarbageCollectorController: &GarbageCollectorControllerOptions{
240249
&garbagecollectorconfig.GarbageCollectorControllerConfiguration{
241250
ConcurrentGCSyncs: 30,

hack/.golint_failures

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pkg/controller/deployment/config/v1alpha1
6666
pkg/controller/disruption
6767
pkg/controller/endpoint
6868
pkg/controller/endpoint/config/v1alpha1
69+
pkg/controller/endpointslice/config/v1alpha1
6970
pkg/controller/garbagecollector
7071
pkg/controller/garbagecollector/config/v1alpha1
7172
pkg/controller/job

pkg/controller/.import-restrictions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"k8s.io/api/certificates/v1beta1",
2828
"k8s.io/api/core/v1",
2929
"k8s.io/api/coordination/v1beta1",
30+
"k8s.io/api/discovery/v1alpha1",
3031
"k8s.io/api/extensions/v1beta1",
3132
"k8s.io/api/policy/v1beta1",
3233
"k8s.io/api/rbac/v1",
@@ -146,6 +147,7 @@
146147
"k8s.io/client-go/listers/batch/v1",
147148
"k8s.io/client-go/listers/certificates/v1beta1",
148149
"k8s.io/client-go/listers/core/v1",
150+
"k8s.io/client-go/listers/discovery/v1alpha1",
149151
"k8s.io/client-go/listers/coordination/v1beta1",
150152
"k8s.io/client-go/listers/extensions/v1beta1",
151153
"k8s.io/client-go/listers/policy/v1beta1",

0 commit comments

Comments
 (0)