Skip to content

Commit

Permalink
Merge pull request nephio-project#121 from Nordix/feat-large-requests
Browse files Browse the repository at this point in the history
Make max request size configurable.
  • Loading branch information
nephio-prow[bot] authored Oct 24, 2024
2 parents dca2f6d + c6f2991 commit b78d785
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/cmd/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ const (

// PorchServerOptions contains state for master/api server
type PorchServerOptions struct {
RecommendedOptions *genericoptions.RecommendedOptions
LocalStandaloneDebugging bool // Enables local standalone running/debugging of the apiserver.
CacheDirectory string
CoreAPIKubeconfigPath string
FunctionRunnerAddress string
DefaultImagePrefix string
RepoSyncFrequency time.Duration
UseGitCaBundle bool
DisableValidatingAdmissionPolicy bool
RecommendedOptions *genericoptions.RecommendedOptions
LocalStandaloneDebugging bool // Enables local standalone running/debugging of the apiserver.
CacheDirectory string
CoreAPIKubeconfigPath string
FunctionRunnerAddress string
DefaultImagePrefix string
RepoSyncFrequency time.Duration
UseGitCaBundle bool
DisableValidatingAdmissionPolicy bool
MaxRequestBodySize int64

SharedInformerFactory informers.SharedInformerFactory
StdOut io.Writer
Expand Down Expand Up @@ -172,11 +173,9 @@ func (o *PorchServerOptions) Config() (*apiserver.Config, error) {
o.SharedInformerFactory = informerFactory
return []admission.PluginInitializer{}, nil
}

if o.DisableValidatingAdmissionPolicy {
o.RecommendedOptions.Admission.DisablePlugins = []string{"ValidatingAdmissionPolicy"}
}

serverConfig := genericapiserver.NewRecommendedConfig(apiserver.Codecs)

serverConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(sampleopenapi.GetOpenAPIDefinitions, openapi.NewDefinitionNamer(apiserver.Scheme))
Expand All @@ -186,6 +185,7 @@ func (o *PorchServerOptions) Config() (*apiserver.Config, error) {
serverConfig.OpenAPIV3Config = genericapiserver.DefaultOpenAPIV3Config(sampleopenapi.GetOpenAPIDefinitions, openapi.NewDefinitionNamer(apiserver.Scheme))
serverConfig.OpenAPIConfig.Info.Title = OpenAPITitle
serverConfig.OpenAPIConfig.Info.Version = OpenAPIVersion
serverConfig.MaxRequestBodyBytes = o.MaxRequestBodySize

if err := o.RecommendedOptions.ApplyTo(serverConfig); err != nil {
return nil, err
Expand Down Expand Up @@ -245,6 +245,7 @@ func (o *PorchServerOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.FunctionRunnerAddress, "function-runner", "", "Address of the function runner gRPC service.")
fs.StringVar(&o.DefaultImagePrefix, "default-image-prefix", "gcr.io/kpt-fn/", "Default prefix for unqualified function names")
fs.StringVar(&o.CacheDirectory, "cache-directory", "", "Directory where Porch server stores repository and package caches.")
fs.Int64Var(&o.MaxRequestBodySize, "max-request-body-size", 6*1024*1024, "Maximum size of the request body in bytes.")
fs.BoolVar(&o.UseGitCaBundle, "use-git-cabundle", false, "Determine whether to use a user-defined CaBundle for TLS towards git.")
fs.BoolVar(&o.DisableValidatingAdmissionPolicy, "disable-validating-admissions-policy", true, "Determine whether to (dis|en)able the Validating Admission Policy, which requires k8s version >= v1.30")
fs.DurationVar(&o.RepoSyncFrequency, "repo-sync-frequency", 60*time.Second, "Frequency in seconds at which registered repositories will be synced.")
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2856,3 +2856,43 @@ func (t *PorchSuite) TestPackageRevisionFieldSelectors(ctx context.Context) {
}
}
}

func (t *PorchSuite) TestLargePackageRevision(ctx context.Context) {
const (
repository = "large-pkg-rev"
)

t.RegisterMainGitRepositoryF(ctx, repository)
pr := porchapi.PackageRevision{
TypeMeta: metav1.TypeMeta{
Kind: porchapi.PackageRevisionGVR.Resource,
APIVersion: porchapi.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: t.Namespace,
},
Spec: porchapi.PackageRevisionSpec{
PackageName: "new-package",
WorkspaceName: "workspace",
RepositoryName: repository,
Tasks: []porchapi.Task{
{
Type: porchapi.TaskTypeInit,
Init: &porchapi.PackageInitTaskSpec{
Description: "this is a test",
},
},
},
},
}

t.CreateE(ctx, &pr)

var prr porchapi.PackageRevisionResources

t.GetE(ctx, client.ObjectKey{Name: pr.Name, Namespace: pr.Namespace}, &prr)

prr.Spec.Resources["largefile.txt"] = strings.Repeat("a", 4*1024*1024)

t.UpdateE(ctx, &prr)
}

0 comments on commit b78d785

Please sign in to comment.