...

Source file src/k8s.io/kubernetes/cmd/kube-controller-manager/app/options/endpointslicecontroller.go

Documentation: k8s.io/kubernetes/cmd/kube-controller-manager/app/options

     1  /*
     2  Copyright 2019 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  	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  // EndpointSliceControllerOptions holds the EndpointSliceController options.
    35  type EndpointSliceControllerOptions struct {
    36  	*endpointsliceconfig.EndpointSliceControllerConfiguration
    37  }
    38  
    39  // AddFlags adds flags related to EndpointSliceController for controller manager to the specified FlagSet.
    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  // ApplyTo fills up EndpointSliceController config with options.
    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  // Validate checks validation of EndpointSliceControllerOptions.
    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