k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kube-controller-manager/app/options/endpointslicemirroringcontroller.go (about) 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 "k8s.io/kubernetes/cmd/kube-controller-manager/names" 25 endpointslicemirroringconfig "k8s.io/kubernetes/pkg/controller/endpointslicemirroring/config" 26 ) 27 28 const ( 29 mirroringMinConcurrentServiceEndpointSyncs = 1 30 mirroringMaxConcurrentServiceEndpointSyncs = 50 31 mirroringMinMaxEndpointsPerSubset = 1 32 mirroringMaxMaxEndpointsPerSubset = 1000 33 ) 34 35 // EndpointSliceMirroringControllerOptions holds the 36 // EndpointSliceMirroringController options. 37 type EndpointSliceMirroringControllerOptions struct { 38 *endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration 39 } 40 41 // AddFlags adds flags related to EndpointSliceMirroringController for 42 // controller manager to the specified FlagSet. 43 func (o *EndpointSliceMirroringControllerOptions) AddFlags(fs *pflag.FlagSet) { 44 if o == nil { 45 return 46 } 47 48 fs.Int32Var(&o.MirroringConcurrentServiceEndpointSyncs, "mirroring-concurrent-service-endpoint-syncs", o.MirroringConcurrentServiceEndpointSyncs, fmt.Sprintf("The number of service endpoint syncing operations that will be done concurrently by the %s. Larger number = faster endpoint slice updating, but more CPU (and network) load. Defaults to 5.", names.EndpointSliceMirroringController)) 49 fs.Int32Var(&o.MirroringMaxEndpointsPerSubset, "mirroring-max-endpoints-per-subset", o.MirroringMaxEndpointsPerSubset, fmt.Sprintf("The maximum number of endpoints that will be added to an EndpointSlice by the %s. More endpoints per slice will result in less endpoint slices, but larger resources. Defaults to 100.", names.EndpointSliceMirroringController)) 50 fs.DurationVar(&o.MirroringEndpointUpdatesBatchPeriod.Duration, "mirroring-endpointslice-updates-batch-period", o.MirroringEndpointUpdatesBatchPeriod.Duration, fmt.Sprintf("The length of EndpointSlice updates batching period for %s. 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", names.EndpointSliceMirroringController)) 51 } 52 53 // ApplyTo fills up EndpointSliceMirroringController config with options. 54 func (o *EndpointSliceMirroringControllerOptions) ApplyTo(cfg *endpointslicemirroringconfig.EndpointSliceMirroringControllerConfiguration) error { 55 if o == nil { 56 return nil 57 } 58 59 cfg.MirroringConcurrentServiceEndpointSyncs = o.MirroringConcurrentServiceEndpointSyncs 60 cfg.MirroringMaxEndpointsPerSubset = o.MirroringMaxEndpointsPerSubset 61 cfg.MirroringEndpointUpdatesBatchPeriod = o.MirroringEndpointUpdatesBatchPeriod 62 63 return nil 64 } 65 66 // Validate checks validation of EndpointSliceMirroringControllerOptions. 67 func (o *EndpointSliceMirroringControllerOptions) Validate() []error { 68 if o == nil { 69 return nil 70 } 71 72 errs := []error{} 73 74 if o.MirroringConcurrentServiceEndpointSyncs < mirroringMinConcurrentServiceEndpointSyncs { 75 errs = append(errs, fmt.Errorf("mirroring-concurrent-service-endpoint-syncs must not be less than %d, but got %d", mirroringMinConcurrentServiceEndpointSyncs, o.MirroringConcurrentServiceEndpointSyncs)) 76 } else if o.MirroringConcurrentServiceEndpointSyncs > mirroringMaxConcurrentServiceEndpointSyncs { 77 errs = append(errs, fmt.Errorf("mirroring-concurrent-service-endpoint-syncs must not be more than %d, but got %d", mirroringMaxConcurrentServiceEndpointSyncs, o.MirroringConcurrentServiceEndpointSyncs)) 78 } 79 80 if o.MirroringMaxEndpointsPerSubset < mirroringMinMaxEndpointsPerSubset { 81 errs = append(errs, fmt.Errorf("mirroring-max-endpoints-per-subset must not be less than %d, but got %d", mirroringMinMaxEndpointsPerSubset, o.MirroringMaxEndpointsPerSubset)) 82 } else if o.MirroringMaxEndpointsPerSubset > mirroringMaxMaxEndpointsPerSubset { 83 errs = append(errs, fmt.Errorf("mirroring-max-endpoints-per-subset must not be more than %d, but got %d", mirroringMaxMaxEndpointsPerSubset, o.MirroringMaxEndpointsPerSubset)) 84 } 85 86 return errs 87 }