Enabling the EndpointSliceMirroring controller, adding related config

This commit is contained in:
Rob Scott
2020-06-26 16:17:22 -07:00
parent 85d5a15841
commit e701cb0205
24 changed files with 283 additions and 3 deletions

View File

@@ -56,6 +56,7 @@ go_library(
"//pkg/controller/disruption:go_default_library",
"//pkg/controller/endpoint:go_default_library",
"//pkg/controller/endpointslice:go_default_library",
"//pkg/controller/endpointslicemirroring:go_default_library",
"//pkg/controller/garbagecollector:go_default_library",
"//pkg/controller/job:go_default_library",
"//pkg/controller/namespace:go_default_library",

View File

@@ -387,6 +387,7 @@ func NewControllerInitializers(loopMode ControllerLoopMode) map[string]InitFunc
controllers := map[string]InitFunc{}
controllers["endpoint"] = startEndpointController
controllers["endpointslice"] = startEndpointSliceController
controllers["endpointslicemirroring"] = startEndpointSliceMirroringController
controllers["replicationcontroller"] = startReplicationController
controllers["podgc"] = startPodGCController
controllers["resourcequota"] = startResourceQuotaController

View File

@@ -97,8 +97,10 @@ type controllerInitFunc func(ControllerContext) (http.Handler, bool, error)
func TestController_DiscoveryError(t *testing.T) {
controllerInitFuncMap := map[string]controllerInitFunc{
"ResourceQuotaController": startResourceQuotaController,
"GarbageCollectorController": startGarbageCollectorController,
"ResourceQuotaController": startResourceQuotaController,
"GarbageCollectorController": startGarbageCollectorController,
"EndpointSliceController": startEndpointSliceController,
"EndpointSliceMirroringController": startEndpointSliceMirroringController,
}
tcs := map[string]struct {

View File

@@ -27,12 +27,13 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/klog/v2"
endpointslicecontroller "k8s.io/kubernetes/pkg/controller/endpointslice"
endpointslicemirroringcontroller "k8s.io/kubernetes/pkg/controller/endpointslicemirroring"
"k8s.io/kubernetes/pkg/features"
)
func startEndpointSliceController(ctx ControllerContext) (http.Handler, bool, error) {
if !utilfeature.DefaultFeatureGate.Enabled(features.EndpointSlice) {
klog.V(4).Infof("Not starting endpointslice-controller since EndpointSlice feature gate is disabled")
klog.V(2).Infof("Not starting endpointslice-controller since EndpointSlice feature gate is disabled")
return nil, false, nil
}
@@ -52,3 +53,25 @@ func startEndpointSliceController(ctx ControllerContext) (http.Handler, bool, er
).Run(int(ctx.ComponentConfig.EndpointSliceController.ConcurrentServiceEndpointSyncs), ctx.Stop)
return nil, true, nil
}
func startEndpointSliceMirroringController(ctx ControllerContext) (http.Handler, bool, error) {
if !utilfeature.DefaultFeatureGate.Enabled(features.EndpointSlice) {
klog.V(2).Infof("Not starting endpointslicemirroring-controller since EndpointSlice feature gate is disabled")
return nil, false, nil
}
if !ctx.AvailableResources[discoveryv1beta1.SchemeGroupVersion.WithResource("endpointslices")] {
klog.Warningf("Not starting endpointslicemirroring-controller since discovery.k8s.io/v1beta1 resources are not available")
return nil, false, nil
}
go endpointslicemirroringcontroller.NewController(
ctx.InformerFactory.Core().V1().Endpoints(),
ctx.InformerFactory.Discovery().V1beta1().EndpointSlices(),
ctx.InformerFactory.Core().V1().Services(),
ctx.ComponentConfig.EndpointSliceMirroringController.MirroringMaxEndpointsPerSubset,
ctx.ClientBuilder.ClientOrDie("endpointslicemirroring-controller"),
ctx.ComponentConfig.EndpointSliceMirroringController.MirroringEndpointUpdatesBatchPeriod.Duration,
).Run(int(ctx.ComponentConfig.EndpointSliceMirroringController.MirroringConcurrentServiceEndpointSyncs), ctx.Stop)
return nil, true, nil
}

View File

@@ -16,6 +16,7 @@ go_library(
"deprecatedcontroller.go",
"endpointcontroller.go",
"endpointslicecontroller.go",
"endpointslicemirroringcontroller.go",
"garbagecollectorcontroller.go",
"hpacontroller.go",
"jobcontroller.go",
@@ -43,6 +44,7 @@ go_library(
"//pkg/controller/deployment/config:go_default_library",
"//pkg/controller/endpoint/config:go_default_library",
"//pkg/controller/endpointslice/config:go_default_library",
"//pkg/controller/endpointslicemirroring/config:go_default_library",
"//pkg/controller/garbagecollector:go_default_library",
"//pkg/controller/garbagecollector/config:go_default_library",
"//pkg/controller/job/config:go_default_library",
@@ -104,6 +106,7 @@ go_test(
"//pkg/controller/deployment/config:go_default_library",
"//pkg/controller/endpoint/config:go_default_library",
"//pkg/controller/endpointslice/config:go_default_library",
"//pkg/controller/endpointslicemirroring/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,86 @@
/*
Copyright 2020 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"
endpointslicemirroringconfig "k8s.io/kubernetes/pkg/controller/endpointslicemirroring/config"
)
const (
mirroringMinConcurrentServiceEndpointSyncs = 1
mirroringMaxConcurrentServiceEndpointSyncs = 50
mirroringMinMaxEndpointsPerSubset = 1
mirroringMaxMaxEndpointsPerSubset = 1000
)
// EndpointSliceMirroringControllerOptions holds the
// EndpointSliceMirroringController options.
type EndpointSliceMirroringControllerOptions struct {
*endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration
}
// AddFlags adds flags related to EndpointSliceMirroringController for
// controller manager to the specified FlagSet.
func (o *EndpointSliceMirroringControllerOptions) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
}
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.")
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.")
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")
}
// ApplyTo fills up EndpointSliceMirroringController config with options.
func (o *EndpointSliceMirroringControllerOptions) ApplyTo(cfg *endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration) error {
if o == nil {
return nil
}
cfg.MirroringConcurrentServiceEndpointSyncs = o.MirroringConcurrentServiceEndpointSyncs
cfg.MirroringMaxEndpointsPerSubset = o.MirroringMaxEndpointsPerSubset
cfg.MirroringEndpointUpdatesBatchPeriod = o.MirroringEndpointUpdatesBatchPeriod
return nil
}
// Validate checks validation of EndpointSliceMirroringControllerOptions.
func (o *EndpointSliceMirroringControllerOptions) Validate() []error {
if o == nil {
return nil
}
errs := []error{}
if o.MirroringConcurrentServiceEndpointSyncs < mirroringMinConcurrentServiceEndpointSyncs {
errs = append(errs, fmt.Errorf("mirroring-concurrent-service-endpoint-syncs must not be less than %d, but got %d", mirroringMinConcurrentServiceEndpointSyncs, o.MirroringConcurrentServiceEndpointSyncs))
} else if o.MirroringConcurrentServiceEndpointSyncs > mirroringMaxConcurrentServiceEndpointSyncs {
errs = append(errs, fmt.Errorf("mirroring-concurrent-service-endpoint-syncs must not be more than %d, but got %d", mirroringMaxConcurrentServiceEndpointSyncs, o.MirroringConcurrentServiceEndpointSyncs))
}
if o.MirroringMaxEndpointsPerSubset < mirroringMinMaxEndpointsPerSubset {
errs = append(errs, fmt.Errorf("mirroring-max-endpoints-per-subset must not be less than %d, but got %d", mirroringMinMaxEndpointsPerSubset, o.MirroringMaxEndpointsPerSubset))
} else if o.MirroringMaxEndpointsPerSubset > mirroringMaxMaxEndpointsPerSubset {
errs = append(errs, fmt.Errorf("mirroring-max-endpoints-per-subset must not be more than %d, but got %d", mirroringMaxMaxEndpointsPerSubset, o.MirroringMaxEndpointsPerSubset))
}
return errs
}

View File

@@ -66,6 +66,7 @@ type KubeControllerManagerOptions struct {
DeprecatedFlags *DeprecatedControllerOptions
EndpointController *EndpointControllerOptions
EndpointSliceController *EndpointSliceControllerOptions
EndpointSliceMirroringController *EndpointSliceMirroringControllerOptions
GarbageCollectorController *GarbageCollectorControllerOptions
HPAController *HPAControllerOptions
JobController *JobControllerOptions
@@ -129,6 +130,9 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
EndpointSliceController: &EndpointSliceControllerOptions{
&componentConfig.EndpointSliceController,
},
EndpointSliceMirroringController: &EndpointSliceMirroringControllerOptions{
&componentConfig.EndpointSliceMirroringController,
},
GarbageCollectorController: &GarbageCollectorControllerOptions{
&componentConfig.GarbageCollectorController,
},
@@ -233,6 +237,7 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
s.DeprecatedFlags.AddFlags(fss.FlagSet("deprecated"))
s.EndpointController.AddFlags(fss.FlagSet("endpoint controller"))
s.EndpointSliceController.AddFlags(fss.FlagSet("endpointslice controller"))
s.EndpointSliceMirroringController.AddFlags(fss.FlagSet("endpointslicemirroring controller"))
s.GarbageCollectorController.AddFlags(fss.FlagSet("garbagecollector controller"))
s.HPAController.AddFlags(fss.FlagSet("horizontalpodautoscaling controller"))
s.JobController.AddFlags(fss.FlagSet("job controller"))
@@ -288,6 +293,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config) e
if err := s.EndpointSliceController.ApplyTo(&c.ComponentConfig.EndpointSliceController); err != nil {
return err
}
if err := s.EndpointSliceMirroringController.ApplyTo(&c.ComponentConfig.EndpointSliceMirroringController); err != nil {
return err
}
if err := s.GarbageCollectorController.ApplyTo(&c.ComponentConfig.GarbageCollectorController); err != nil {
return err
}
@@ -367,6 +375,7 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
errs = append(errs, s.DeprecatedFlags.Validate()...)
errs = append(errs, s.EndpointController.Validate()...)
errs = append(errs, s.EndpointSliceController.Validate()...)
errs = append(errs, s.EndpointSliceMirroringController.Validate()...)
errs = append(errs, s.GarbageCollectorController.Validate()...)
errs = append(errs, s.HPAController.Validate()...)
errs = append(errs, s.JobController.Validate()...)

View File

@@ -38,6 +38,7 @@ import (
deploymentconfig "k8s.io/kubernetes/pkg/controller/deployment/config"
endpointconfig "k8s.io/kubernetes/pkg/controller/endpoint/config"
endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
endpointslicemirroringconfig "k8s.io/kubernetes/pkg/controller/endpointslicemirroring/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"
@@ -110,6 +111,8 @@ var args = []string{
"--master=192.168.4.20",
"--max-endpoints-per-slice=200",
"--min-resync-period=8h",
"--mirroring-concurrent-service-endpoint-syncs=2",
"--mirroring-max-endpoints-per-subset=1000",
"--namespace-sync-period=10m",
"--node-cidr-mask-size=48",
"--node-cidr-mask-size-ipv4=48",
@@ -250,6 +253,12 @@ func TestAddFlags(t *testing.T) {
MaxEndpointsPerSlice: 200,
},
},
EndpointSliceMirroringController: &EndpointSliceMirroringControllerOptions{
&endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration{
MirroringConcurrentServiceEndpointSyncs: 2,
MirroringMaxEndpointsPerSubset: 1000,
},
},
GarbageCollectorController: &GarbageCollectorControllerOptions{
&garbagecollectorconfig.GarbageCollectorControllerConfiguration{
ConcurrentGCSyncs: 30,
@@ -481,6 +490,10 @@ func TestApplyTo(t *testing.T) {
ConcurrentServiceEndpointSyncs: 10,
MaxEndpointsPerSlice: 200,
},
EndpointSliceMirroringController: endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration{
MirroringConcurrentServiceEndpointSyncs: 2,
MirroringMaxEndpointsPerSubset: 1000,
},
GarbageCollectorController: garbagecollectorconfig.GarbageCollectorControllerConfiguration{
ConcurrentGCSyncs: 30,
GCIgnoredResources: []garbagecollectorconfig.GroupResource{