Deep disablement for APF based on --enable-priority-and-fairness.
Avoids starting informers or the config-consuming controller when --enable-priority-and-fairness=false. For kube-apiserver, the config-producing controller runs if and only if flowcontrol API storage is enabled. Kubernetes-commit: 83f5b5c240e5cced1371bbd22e458dae43975238
This commit is contained in:
parent
3832c1300f
commit
cd9457dbfc
|
|
@ -17,16 +17,24 @@ limitations under the License.
|
||||||
package options
|
package options
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
|
"k8s.io/apiserver/pkg/features"
|
||||||
"k8s.io/apiserver/pkg/server"
|
"k8s.io/apiserver/pkg/server"
|
||||||
|
"k8s.io/apiserver/pkg/util/feature"
|
||||||
|
utilflowcontrol "k8s.io/apiserver/pkg/util/flowcontrol"
|
||||||
|
"k8s.io/client-go/informers"
|
||||||
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FeatureOptions struct {
|
type FeatureOptions struct {
|
||||||
EnableProfiling bool
|
EnableProfiling bool
|
||||||
DebugSocketPath string
|
DebugSocketPath string
|
||||||
EnableContentionProfiling bool
|
EnableContentionProfiling bool
|
||||||
|
EnablePriorityAndFairness bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFeatureOptions() *FeatureOptions {
|
func NewFeatureOptions() *FeatureOptions {
|
||||||
|
|
@ -36,6 +44,7 @@ func NewFeatureOptions() *FeatureOptions {
|
||||||
EnableProfiling: defaults.EnableProfiling,
|
EnableProfiling: defaults.EnableProfiling,
|
||||||
DebugSocketPath: defaults.DebugSocketPath,
|
DebugSocketPath: defaults.DebugSocketPath,
|
||||||
EnableContentionProfiling: defaults.EnableContentionProfiling,
|
EnableContentionProfiling: defaults.EnableContentionProfiling,
|
||||||
|
EnablePriorityAndFairness: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,9 +59,11 @@ func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) {
|
||||||
"Enable block profiling, if profiling is enabled")
|
"Enable block profiling, if profiling is enabled")
|
||||||
fs.StringVar(&o.DebugSocketPath, "debug-socket-path", o.DebugSocketPath,
|
fs.StringVar(&o.DebugSocketPath, "debug-socket-path", o.DebugSocketPath,
|
||||||
"Use an unprotected (no authn/authz) unix-domain socket for profiling with the given path")
|
"Use an unprotected (no authn/authz) unix-domain socket for profiling with the given path")
|
||||||
|
fs.BoolVar(&o.EnablePriorityAndFairness, "enable-priority-and-fairness", o.EnablePriorityAndFairness, ""+
|
||||||
|
"If true and the APIPriorityAndFairness feature gate is enabled, replace the max-in-flight handler with an enhanced one that queues and dispatches with priority and fairness")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *FeatureOptions) ApplyTo(c *server.Config) error {
|
func (o *FeatureOptions) ApplyTo(c *server.Config, clientset kubernetes.Interface, informers informers.SharedInformerFactory) error {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -61,6 +72,18 @@ func (o *FeatureOptions) ApplyTo(c *server.Config) error {
|
||||||
c.DebugSocketPath = o.DebugSocketPath
|
c.DebugSocketPath = o.DebugSocketPath
|
||||||
c.EnableContentionProfiling = o.EnableContentionProfiling
|
c.EnableContentionProfiling = o.EnableContentionProfiling
|
||||||
|
|
||||||
|
if o.EnablePriorityAndFairness && feature.DefaultFeatureGate.Enabled(features.APIPriorityAndFairness) {
|
||||||
|
if c.MaxRequestsInFlight+c.MaxMutatingRequestsInFlight <= 0 {
|
||||||
|
return fmt.Errorf("invalid configuration: MaxRequestsInFlight=%d and MaxMutatingRequestsInFlight=%d; they must add up to something positive", c.MaxRequestsInFlight, c.MaxMutatingRequestsInFlight)
|
||||||
|
|
||||||
|
}
|
||||||
|
c.FlowControl = utilflowcontrol.New(
|
||||||
|
informers,
|
||||||
|
clientset.FlowcontrolV1beta3(),
|
||||||
|
c.MaxRequestsInFlight+c.MaxMutatingRequestsInFlight,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,15 @@ 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"
|
||||||
"k8s.io/apiserver/pkg/admission"
|
"k8s.io/apiserver/pkg/admission"
|
||||||
"k8s.io/apiserver/pkg/features"
|
|
||||||
"k8s.io/apiserver/pkg/server"
|
"k8s.io/apiserver/pkg/server"
|
||||||
"k8s.io/apiserver/pkg/storage/storagebackend"
|
"k8s.io/apiserver/pkg/storage/storagebackend"
|
||||||
"k8s.io/apiserver/pkg/util/feature"
|
"k8s.io/apiserver/pkg/util/feature"
|
||||||
utilflowcontrol "k8s.io/apiserver/pkg/util/flowcontrol"
|
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/component-base/featuregate"
|
"k8s.io/component-base/featuregate"
|
||||||
"k8s.io/klog/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RecommendedOptions contains the recommended options for running an API server.
|
// RecommendedOptions contains the recommended options for running an API server.
|
||||||
|
|
@ -122,17 +117,17 @@ func (o *RecommendedOptions) ApplyTo(config *server.RecommendedConfig) error {
|
||||||
if err := o.Audit.ApplyTo(&config.Config); err != nil {
|
if err := o.Audit.ApplyTo(&config.Config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := o.Features.ApplyTo(&config.Config); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := o.CoreAPI.ApplyTo(config); err != nil {
|
if err := o.CoreAPI.ApplyTo(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
initializers, err := o.ExtraAdmissionInitializers(config)
|
kubeClient, err := kubernetes.NewForConfig(config.ClientConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
kubeClient, err := kubernetes.NewForConfig(config.ClientConfig)
|
if err := o.Features.ApplyTo(&config.Config, kubeClient, config.SharedInformerFactory); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
initializers, err := o.ExtraAdmissionInitializers(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -144,21 +139,6 @@ func (o *RecommendedOptions) ApplyTo(config *server.RecommendedConfig) error {
|
||||||
initializers...); err != nil {
|
initializers...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if feature.DefaultFeatureGate.Enabled(features.APIPriorityAndFairness) {
|
|
||||||
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.SharedInformerFactory,
|
|
||||||
kubernetes.NewForConfigOrDie(config.ClientConfig).FlowcontrolV1beta3(),
|
|
||||||
config.MaxRequestsInFlight+config.MaxMutatingRequestsInFlight,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
klog.Warningf("Neither kubeconfig is provided nor service-account is mounted, so APIPriorityAndFairness will be disabled")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,6 @@ type ServerRunOptions struct {
|
||||||
// We intentionally did not add a flag for this option. Users of the
|
// We intentionally did not add a flag for this option. Users of the
|
||||||
// apiserver library can wire it to a flag.
|
// apiserver library can wire it to a flag.
|
||||||
MaxRequestBodyBytes int64
|
MaxRequestBodyBytes int64
|
||||||
EnablePriorityAndFairness bool
|
|
||||||
|
|
||||||
// ShutdownSendRetryAfter dictates when to initiate shutdown of the HTTP
|
// ShutdownSendRetryAfter dictates when to initiate shutdown of the HTTP
|
||||||
// Server during the graceful termination of the apiserver. If true, we wait
|
// Server during the graceful termination of the apiserver. If true, we wait
|
||||||
|
|
@ -104,7 +103,6 @@ func NewServerRunOptions() *ServerRunOptions {
|
||||||
ShutdownWatchTerminationGracePeriod: defaults.ShutdownWatchTerminationGracePeriod,
|
ShutdownWatchTerminationGracePeriod: defaults.ShutdownWatchTerminationGracePeriod,
|
||||||
JSONPatchMaxCopyBytes: defaults.JSONPatchMaxCopyBytes,
|
JSONPatchMaxCopyBytes: defaults.JSONPatchMaxCopyBytes,
|
||||||
MaxRequestBodyBytes: defaults.MaxRequestBodyBytes,
|
MaxRequestBodyBytes: defaults.MaxRequestBodyBytes,
|
||||||
EnablePriorityAndFairness: true,
|
|
||||||
ShutdownSendRetryAfter: false,
|
ShutdownSendRetryAfter: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -325,9 +323,6 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
|
||||||
"handler, which picks a randomized value above this number as the connection timeout, "+
|
"handler, which picks a randomized value above this number as the connection timeout, "+
|
||||||
"to spread out load.")
|
"to spread out load.")
|
||||||
|
|
||||||
fs.BoolVar(&s.EnablePriorityAndFairness, "enable-priority-and-fairness", s.EnablePriorityAndFairness, ""+
|
|
||||||
"If true and the APIPriorityAndFairness feature gate is enabled, replace the max-in-flight handler with an enhanced one that queues and dispatches with priority and fairness")
|
|
||||||
|
|
||||||
fs.DurationVar(&s.ShutdownDelayDuration, "shutdown-delay-duration", s.ShutdownDelayDuration, ""+
|
fs.DurationVar(&s.ShutdownDelayDuration, "shutdown-delay-duration", s.ShutdownDelayDuration, ""+
|
||||||
"Time to delay the termination. During that time the server keeps serving requests normally. The endpoints /healthz and /livez "+
|
"Time to delay the termination. During that time the server keeps serving requests normally. The endpoints /healthz and /livez "+
|
||||||
"will return success, but /readyz immediately returns failure. Graceful termination starts after this delay "+
|
"will return success, but /readyz immediately returns failure. Graceful termination starts after this delay "+
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue