mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Add config checking for inflight limits
When API Priority and Fairness is enabled, the inflight limits must add up to something positive. This rejects the configuration that prompted https://github.com/kubernetes/kubernetes/issues/102885 Update help for max inflight flags
This commit is contained in:
parent
ce8b7afc8a
commit
0762f492c5
@ -466,10 +466,11 @@ func buildGenericConfig(
|
|||||||
pluginInitializers...)
|
pluginInitializers...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lastErr = fmt.Errorf("failed to initialize admission: %v", err)
|
lastErr = fmt.Errorf("failed to initialize admission: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIPriorityAndFairness) && s.GenericServerRunOptions.EnablePriorityAndFairness {
|
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIPriorityAndFairness) && s.GenericServerRunOptions.EnablePriorityAndFairness {
|
||||||
genericConfig.FlowControl = BuildPriorityAndFairness(s, clientgoExternalClient, versionedInformers)
|
genericConfig.FlowControl, lastErr = BuildPriorityAndFairness(s, clientgoExternalClient, versionedInformers)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -491,13 +492,16 @@ func BuildAuthorizer(s *options.ServerRunOptions, EgressSelector *egressselector
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildPriorityAndFairness constructs the guts of the API Priority and Fairness filter
|
// BuildPriorityAndFairness constructs the guts of the API Priority and Fairness filter
|
||||||
func BuildPriorityAndFairness(s *options.ServerRunOptions, extclient clientgoclientset.Interface, versionedInformer clientgoinformers.SharedInformerFactory) utilflowcontrol.Interface {
|
func BuildPriorityAndFairness(s *options.ServerRunOptions, extclient clientgoclientset.Interface, versionedInformer clientgoinformers.SharedInformerFactory) (utilflowcontrol.Interface, error) {
|
||||||
|
if s.GenericServerRunOptions.MaxRequestsInFlight+s.GenericServerRunOptions.MaxMutatingRequestsInFlight <= 0 {
|
||||||
|
return nil, fmt.Errorf("invalid configuration: MaxRequestsInFlight=%d and MaxMutatingRequestsInFlight=%d; they must add up to something positive", s.GenericServerRunOptions.MaxRequestsInFlight, s.GenericServerRunOptions.MaxMutatingRequestsInFlight)
|
||||||
|
}
|
||||||
return utilflowcontrol.New(
|
return utilflowcontrol.New(
|
||||||
versionedInformer,
|
versionedInformer,
|
||||||
extclient.FlowcontrolV1beta1(),
|
extclient.FlowcontrolV1beta1(),
|
||||||
s.GenericServerRunOptions.MaxRequestsInFlight+s.GenericServerRunOptions.MaxMutatingRequestsInFlight,
|
s.GenericServerRunOptions.MaxRequestsInFlight+s.GenericServerRunOptions.MaxMutatingRequestsInFlight,
|
||||||
s.GenericServerRunOptions.RequestTimeout/4,
|
s.GenericServerRunOptions.RequestTimeout/4,
|
||||||
)
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// completedServerRunOptions is a private wrapper that enforces a call of Complete() before Run can be invoked.
|
// completedServerRunOptions is a private wrapper that enforces a call of Complete() before Run can be invoked.
|
||||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package options
|
package options
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -126,6 +128,10 @@ func (o *RecommendedOptions) ApplyTo(config *server.RecommendedConfig) error {
|
|||||||
}
|
}
|
||||||
if feature.DefaultFeatureGate.Enabled(features.APIPriorityAndFairness) {
|
if feature.DefaultFeatureGate.Enabled(features.APIPriorityAndFairness) {
|
||||||
if config.ClientConfig != nil {
|
if config.ClientConfig != nil {
|
||||||
|
if config.MaxRequestsInFlight+config.MaxMutatingRequestsInFlight <= 0 {
|
||||||
|
return fmt.Errorf("invalid configuration: MaxRequestsInFlight=%d and MaxMutatingRequestsInFlight=%d; they must add up to something positive", config.MaxRequestsInFlight, config.MaxMutatingRequestsInFlight)
|
||||||
|
|
||||||
|
}
|
||||||
config.FlowControl = utilflowcontrol.New(
|
config.FlowControl = utilflowcontrol.New(
|
||||||
config.SharedInformerFactory,
|
config.SharedInformerFactory,
|
||||||
kubernetes.NewForConfigOrDie(config.ClientConfig).FlowcontrolV1beta1(),
|
kubernetes.NewForConfigOrDie(config.ClientConfig).FlowcontrolV1beta1(),
|
||||||
|
@ -204,12 +204,16 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
|
|||||||
"DEPRECATED: the namespace from which the Kubernetes master services should be injected into pods.")
|
"DEPRECATED: the namespace from which the Kubernetes master services should be injected into pods.")
|
||||||
|
|
||||||
fs.IntVar(&s.MaxRequestsInFlight, "max-requests-inflight", s.MaxRequestsInFlight, ""+
|
fs.IntVar(&s.MaxRequestsInFlight, "max-requests-inflight", s.MaxRequestsInFlight, ""+
|
||||||
"The maximum number of non-mutating requests in flight at a given time. When the server exceeds this, "+
|
"This and --max-mutating-requests-inflight are summed to determine the server's total concurrency limit "+
|
||||||
"it rejects requests. Zero for no limit.")
|
"(which must be positive) if --enable-priority-and-fairness is true. "+
|
||||||
|
"Otherwise, this flag limits the maximum number of non-mutating requests in flight, "+
|
||||||
|
"or a zero value disables the limit completely.")
|
||||||
|
|
||||||
fs.IntVar(&s.MaxMutatingRequestsInFlight, "max-mutating-requests-inflight", s.MaxMutatingRequestsInFlight, ""+
|
fs.IntVar(&s.MaxMutatingRequestsInFlight, "max-mutating-requests-inflight", s.MaxMutatingRequestsInFlight, ""+
|
||||||
"The maximum number of mutating requests in flight at a given time. When the server exceeds this, "+
|
"This and --max-requests-inflight are summed to determine the server's total concurrency limit "+
|
||||||
"it rejects requests. Zero for no limit.")
|
"(which must be positive) if --enable-priority-and-fairness is true. "+
|
||||||
|
"Otherwise, this flag limits the maximum number of mutating requests in flight, "+
|
||||||
|
"or a zero value disables the limit completely.")
|
||||||
|
|
||||||
fs.DurationVar(&s.RequestTimeout, "request-timeout", s.RequestTimeout, ""+
|
fs.DurationVar(&s.RequestTimeout, "request-timeout", s.RequestTimeout, ""+
|
||||||
"An optional field indicating the duration a handler must keep a request open before timing "+
|
"An optional field indicating the duration a handler must keep a request open before timing "+
|
||||||
|
Loading…
Reference in New Issue
Block a user