Adding EndpointSlice controller

This commit is contained in:
Rob Scott
2019-07-30 15:42:01 -07:00
parent 550fb1bfc3
commit 75f6c24923
52 changed files with 3852 additions and 562 deletions

View File

@@ -11,6 +11,7 @@ go_library(
"cloudproviders.go",
"controllermanager.go",
"core.go",
"discovery.go",
"flags_providers.go",
"import_known_versions.go",
"plugins.go",
@@ -54,6 +55,7 @@ go_library(
"//pkg/controller/deployment:go_default_library",
"//pkg/controller/disruption:go_default_library",
"//pkg/controller/endpoint:go_default_library",
"//pkg/controller/endpointslice:go_default_library",
"//pkg/controller/garbagecollector:go_default_library",
"//pkg/controller/job:go_default_library",
"//pkg/controller/namespace:go_default_library",

View File

@@ -360,6 +360,7 @@ func KnownControllers() []string {
// ControllersDisabledByDefault is the set of controllers which is disabled by default
var ControllersDisabledByDefault = sets.NewString(
"bootstrapsigner",
"endpointslice",
"tokencleaner",
)
@@ -372,6 +373,7 @@ const (
func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc {
controllers := map[string]InitFunc{}
controllers["endpoint"] = startEndpointController
controllers["endpointslice"] = startEndpointSliceController
controllers["replicationcontroller"] = startReplicationController
controllers["podgc"] = startPodGCController
controllers["resourcequota"] = startResourceQuotaController

View File

@@ -0,0 +1,44 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package app implements a server that runs a set of active
// components. This includes replication controllers, service endpoints and
// nodes.
//
package app
import (
"net/http"
"k8s.io/apimachinery/pkg/runtime/schema"
endpointslicecontroller "k8s.io/kubernetes/pkg/controller/endpointslice"
)
func startEndpointSliceController(ctx ControllerContext) (http.Handler, bool, error) {
if !ctx.AvailableResources[schema.GroupVersionResource{Group: "discovery", Version: "v1alpha1", Resource: "endpointslices"}] {
return nil, false, nil
}
go endpointslicecontroller.NewController(
ctx.InformerFactory.Core().V1().Pods(),
ctx.InformerFactory.Core().V1().Services(),
ctx.InformerFactory.Core().V1().Nodes(),
ctx.InformerFactory.Discovery().V1alpha1().EndpointSlices(),
ctx.ComponentConfig.EndpointSliceController.MaxEndpointsPerSlice,
ctx.ClientBuilder.ClientOrDie("endpointslice-controller"),
).Run(int(ctx.ComponentConfig.EndpointSliceController.ConcurrentServiceEndpointSyncs), ctx.Stop)
return nil, true, nil
}

View File

@@ -15,6 +15,7 @@ go_library(
"deploymentcontroller.go",
"deprecatedcontroller.go",
"endpointcontroller.go",
"endpointslicecontroller.go",
"garbagecollectorcontroller.go",
"hpacontroller.go",
"jobcontroller.go",
@@ -41,6 +42,7 @@ go_library(
"//pkg/controller/daemon/config:go_default_library",
"//pkg/controller/deployment/config:go_default_library",
"//pkg/controller/endpoint/config:go_default_library",
"//pkg/controller/endpointslice/config:go_default_library",
"//pkg/controller/garbagecollector:go_default_library",
"//pkg/controller/garbagecollector/config:go_default_library",
"//pkg/controller/job/config:go_default_library",
@@ -100,6 +102,7 @@ go_test(
"//pkg/controller/daemon/config:go_default_library",
"//pkg/controller/deployment/config:go_default_library",
"//pkg/controller/endpoint/config:go_default_library",
"//pkg/controller/endpointslice/config:go_default_library",
"//pkg/controller/garbagecollector/config:go_default_library",
"//pkg/controller/job/config:go_default_library",
"//pkg/controller/namespace/config:go_default_library",

View File

@@ -0,0 +1,81 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package options
import (
"fmt"
"github.com/spf13/pflag"
endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
)
const (
minConcurrentServiceEndpointSyncs = 1
maxConcurrentServiceEndpointSyncs = 50
minMaxEndpointsPerSlice = 1
maxMaxEndpointsPerSlice = 1000
)
// EndpointSliceControllerOptions holds the EndpointSliceController options.
type EndpointSliceControllerOptions struct {
*endpointsliceconfig.EndpointSliceControllerConfiguration
}
// AddFlags adds flags related to EndpointSliceController for controller manager to the specified FlagSet.
func (o *EndpointSliceControllerOptions) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
}
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.")
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.")
}
// ApplyTo fills up EndpointSliceController config with options.
func (o *EndpointSliceControllerOptions) ApplyTo(cfg *endpointsliceconfig.EndpointSliceControllerConfiguration) error {
if o == nil {
return nil
}
cfg.ConcurrentServiceEndpointSyncs = o.ConcurrentServiceEndpointSyncs
cfg.MaxEndpointsPerSlice = o.MaxEndpointsPerSlice
return nil
}
// Validate checks validation of EndpointSliceControllerOptions.
func (o *EndpointSliceControllerOptions) Validate() []error {
if o == nil {
return nil
}
errs := []error{}
if o.ConcurrentServiceEndpointSyncs < minConcurrentServiceEndpointSyncs {
errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be less than %d, but got %d", minConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
} else if o.ConcurrentServiceEndpointSyncs > maxConcurrentServiceEndpointSyncs {
errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be more than %d, but got %d", maxConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
}
if o.MaxEndpointsPerSlice < minMaxEndpointsPerSlice {
errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be less than %d, but got %d", minMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
} else if o.MaxEndpointsPerSlice > maxMaxEndpointsPerSlice {
errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be more than %d, but got %d", maxMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
}
return errs
}

View File

@@ -66,6 +66,7 @@ type KubeControllerManagerOptions struct {
StatefulSetController *StatefulSetControllerOptions
DeprecatedFlags *DeprecatedControllerOptions
EndpointController *EndpointControllerOptions
EndpointSliceController *EndpointSliceControllerOptions
GarbageCollectorController *GarbageCollectorControllerOptions
HPAController *HPAControllerOptions
JobController *JobControllerOptions
@@ -124,6 +125,9 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
EndpointController: &EndpointControllerOptions{
&componentConfig.EndpointController,
},
EndpointSliceController: &EndpointSliceControllerOptions{
&componentConfig.EndpointSliceController,
},
GarbageCollectorController: &GarbageCollectorControllerOptions{
&componentConfig.GarbageCollectorController,
},
@@ -226,6 +230,7 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
s.DaemonSetController.AddFlags(fss.FlagSet("daemonset controller"))
s.DeprecatedFlags.AddFlags(fss.FlagSet("deprecated"))
s.EndpointController.AddFlags(fss.FlagSet("endpoint controller"))
s.EndpointSliceController.AddFlags(fss.FlagSet("endpointslice controller"))
s.GarbageCollectorController.AddFlags(fss.FlagSet("garbagecollector controller"))
s.HPAController.AddFlags(fss.FlagSet("horizontalpodautoscaling controller"))
s.JobController.AddFlags(fss.FlagSet("job controller"))
@@ -277,6 +282,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config) e
if err := s.EndpointController.ApplyTo(&c.ComponentConfig.EndpointController); err != nil {
return err
}
if err := s.EndpointSliceController.ApplyTo(&c.ComponentConfig.EndpointSliceController); err != nil {
return err
}
if err := s.GarbageCollectorController.ApplyTo(&c.ComponentConfig.GarbageCollectorController); err != nil {
return err
}
@@ -355,6 +363,7 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
errs = append(errs, s.StatefulSetController.Validate()...)
errs = append(errs, s.DeprecatedFlags.Validate()...)
errs = append(errs, s.EndpointController.Validate()...)
errs = append(errs, s.EndpointSliceController.Validate()...)
errs = append(errs, s.GarbageCollectorController.Validate()...)
errs = append(errs, s.HPAController.Validate()...)
errs = append(errs, s.JobController.Validate()...)

View File

@@ -35,6 +35,7 @@ import (
daemonconfig "k8s.io/kubernetes/pkg/controller/daemon/config"
deploymentconfig "k8s.io/kubernetes/pkg/controller/deployment/config"
endpointconfig "k8s.io/kubernetes/pkg/controller/endpoint/config"
endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
garbagecollectorconfig "k8s.io/kubernetes/pkg/controller/garbagecollector/config"
jobconfig "k8s.io/kubernetes/pkg/controller/job/config"
namespaceconfig "k8s.io/kubernetes/pkg/controller/namespace/config"
@@ -74,6 +75,7 @@ func TestAddFlags(t *testing.T) {
"--concurrent-deployment-syncs=10",
"--concurrent-statefulset-syncs=15",
"--concurrent-endpoint-syncs=10",
"--concurrent-service-endpoint-syncs=10",
"--concurrent-gc-syncs=30",
"--concurrent-namespace-syncs=20",
"--concurrent-replicaset-syncs=10",
@@ -111,6 +113,7 @@ func TestAddFlags(t *testing.T) {
"--leader-elect-resource-lock=configmap",
"--leader-elect-retry-period=5s",
"--master=192.168.4.20",
"--max-endpoints-per-slice=200",
"--min-resync-period=8h",
"--namespace-sync-period=10m",
"--node-cidr-mask-size=48",
@@ -236,6 +239,12 @@ func TestAddFlags(t *testing.T) {
ConcurrentEndpointSyncs: 10,
},
},
EndpointSliceController: &EndpointSliceControllerOptions{
&endpointsliceconfig.EndpointSliceControllerConfiguration{
ConcurrentServiceEndpointSyncs: 10,
MaxEndpointsPerSlice: 200,
},
},
GarbageCollectorController: &GarbageCollectorControllerOptions{
&garbagecollectorconfig.GarbageCollectorControllerConfiguration{
ConcurrentGCSyncs: 30,