endpointslicecontroller.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package options
  14. import (
  15. "fmt"
  16. "github.com/spf13/pflag"
  17. endpointsliceconfig "k8s.io/kubernetes/pkg/controller/endpointslice/config"
  18. )
  19. const (
  20. minConcurrentServiceEndpointSyncs = 1
  21. maxConcurrentServiceEndpointSyncs = 50
  22. minMaxEndpointsPerSlice = 1
  23. maxMaxEndpointsPerSlice = 1000
  24. )
  25. // EndpointSliceControllerOptions holds the EndpointSliceController options.
  26. type EndpointSliceControllerOptions struct {
  27. *endpointsliceconfig.EndpointSliceControllerConfiguration
  28. }
  29. // AddFlags adds flags related to EndpointSliceController for controller manager to the specified FlagSet.
  30. func (o *EndpointSliceControllerOptions) AddFlags(fs *pflag.FlagSet) {
  31. if o == nil {
  32. return
  33. }
  34. 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.")
  35. 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.")
  36. }
  37. // ApplyTo fills up EndpointSliceController config with options.
  38. func (o *EndpointSliceControllerOptions) ApplyTo(cfg *endpointsliceconfig.EndpointSliceControllerConfiguration) error {
  39. if o == nil {
  40. return nil
  41. }
  42. cfg.ConcurrentServiceEndpointSyncs = o.ConcurrentServiceEndpointSyncs
  43. cfg.MaxEndpointsPerSlice = o.MaxEndpointsPerSlice
  44. return nil
  45. }
  46. // Validate checks validation of EndpointSliceControllerOptions.
  47. func (o *EndpointSliceControllerOptions) Validate() []error {
  48. if o == nil {
  49. return nil
  50. }
  51. errs := []error{}
  52. if o.ConcurrentServiceEndpointSyncs < minConcurrentServiceEndpointSyncs {
  53. errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be less than %d, but got %d", minConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
  54. } else if o.ConcurrentServiceEndpointSyncs > maxConcurrentServiceEndpointSyncs {
  55. errs = append(errs, fmt.Errorf("concurrent-service-endpoint-syncs must not be more than %d, but got %d", maxConcurrentServiceEndpointSyncs, o.ConcurrentServiceEndpointSyncs))
  56. }
  57. if o.MaxEndpointsPerSlice < minMaxEndpointsPerSlice {
  58. errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be less than %d, but got %d", minMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
  59. } else if o.MaxEndpointsPerSlice > maxMaxEndpointsPerSlice {
  60. errs = append(errs, fmt.Errorf("max-endpoints-per-slice must not be more than %d, but got %d", maxMaxEndpointsPerSlice, o.MaxEndpointsPerSlice))
  61. }
  62. return errs
  63. }