diff --git a/pkg/services/apiserver/standalone/options/options.go b/pkg/services/apiserver/standalone/options/options.go index fb7f69d5d9d..1288550aea1 100644 --- a/pkg/services/apiserver/standalone/options/options.go +++ b/pkg/services/apiserver/standalone/options/options.go @@ -1,6 +1,8 @@ package options import ( + "fmt" + "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/apiserver/options" "github.com/spf13/pflag" @@ -41,6 +43,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { o.MetricsOptions.AddFlags(fs) o.ProfilingOptions.AddFlags(fs) o.ServerRunOptions.AddUniversalFlags(fs) + o.internalFlags(fs) } func (o *Options) Validate() []error { @@ -68,6 +71,10 @@ func (o *Options) Validate() []error { return errs } + if errs := o.internalFlagsValidate(); len(errs) != 0 { + return errs + } + // NOTE: we don't call validate on the top level recommended options as it doesn't like skipping etcd-servers // the function is left here for troubleshooting any other config issues // errors = append(errors, o.RecommendedOptions.Validate()...) @@ -189,3 +196,21 @@ func (o *Options) ApplyTo(serverConfig *genericapiserver.RecommendedConfig) erro return nil } + +func (o *Options) internalFlags(fs *pflag.FlagSet) { + // We also want to be able to set the MaxRequestSize by using flags. This is + // usually not exposed by k8s. The value is already set to the upstream default + // at this stage, so we can use it as the default. + // Reference: https://github.com/kubernetes/kubernetes/blob/v1.31.1/staging/src/k8s.io/apiserver/pkg/server/config.go#L453 + fs.Int64Var(&o.ServerRunOptions.MaxRequestBodyBytes, "max-request-body-bytes", + o.ServerRunOptions.MaxRequestBodyBytes, ""+ + "Specifies the maximum allowable size for a request payload sent to the API server in bytes."+ + "The default is 3MB.") +} + +func (o *Options) internalFlagsValidate() []error { + if o.ServerRunOptions.MaxRequestBodyBytes < 0 { + return []error{fmt.Errorf("--max-request-body-bytes can not be a negative value")} + } + return nil +}