...
1
16
17 package options
18
19 import (
20 "fmt"
21
22 "github.com/spf13/pflag"
23
24 endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
25 )
26
27 const (
28 minConcurrentServiceEndpointSyncs = 1
29 maxConcurrentServiceEndpointSyncs = 50
30 minMaxEndpointsPerSlice = 1
31 maxMaxEndpointsPerSlice = 1000
32 )
33
34
35 type EndpointSliceControllerOptions struct {
36 *endpointsliceconfig.EndpointSliceControllerConfiguration
37 }
38
39
40 func (o *EndpointSliceControllerOptions) AddFlags(fs *pflag.FlagSet) {
41 if o == nil {
42 return
43 }
44
45 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.")
46 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.")
47 fs.DurationVar(&o.EndpointUpdatesBatchPeriod.Duration, "endpointslice-updates-batch-period", o.EndpointUpdatesBatchPeriod.Duration, "The length of endpoint slice updates batching period. Processing of pod changes will be delayed by this duration to join them with potential upcoming updates and reduce the overall number of endpoints updates. Larger number = higher endpoint programming latency, but lower number of endpoints revision generated")
48 }
49
50
51 func (o *EndpointSliceControllerOptions) ApplyTo(cfg *endpointsliceconfig.EndpointSliceControllerConfiguration) error {
52 if o == nil {
53 return nil
54 }
55
56 cfg.ConcurrentServiceEndpointSyncs = o.ConcurrentServiceEndpointSyncs
57 cfg.MaxEndpointsPerSlice = o.MaxEndpointsPerSlice
58 cfg.EndpointUpdatesBatchPeriod = o.EndpointUpdatesBatchPeriod
59
60 return nil
61 }
62
63
64 func (o *EndpointSliceControllerOptions) Validate() []error {
65 if o == nil {
66 return nil
67 }
68
69 errs := []error{}
70
71 if o.ConcurrentServiceEndpointSyncs < minConcurrentServiceEndpointSyncs {
72 errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be less than %d, but got %d", minConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
73 } else if o.ConcurrentServiceEndpointSyncs > maxConcurrentServiceEndpointSyncs {
74 errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be more than %d, but got %d", maxConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
75 }
76
77 if o.MaxEndpointsPerSlice < minMaxEndpointsPerSlice {
78 errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be less than %d, but got %d", minMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
79 } else if o.MaxEndpointsPerSlice > maxMaxEndpointsPerSlice {
80 errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be more than %d, but got %d", maxMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
81 }
82
83 return errs
84 }
85
View as plain text