From ec9a874f9b5d4fd43f35d84ee4e83a7ace4fff13 Mon Sep 17 00:00:00 2001 From: Mike Nguyen Date: Thu, 20 Feb 2025 16:18:47 +0000 Subject: [PATCH] refactor: modify logic to comply with vetting Signed-off-by: Mike Nguyen --- pkg/standalone/run.go | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/pkg/standalone/run.go b/pkg/standalone/run.go index 669541ea1..8082e71e6 100644 --- a/pkg/standalone/run.go +++ b/pkg/standalone/run.go @@ -229,20 +229,27 @@ func (config *RunConfig) Validate() error { config.MaxConcurrency = -1 } - if q, err := resource.ParseQuantity(config.MaxRequestBodySize); err != nil { + qBody, err := resource.ParseQuantity(config.MaxRequestBodySize) + if err != nil { return fmt.Errorf("invalid max request body size: %w", err) - } else if q.Value() < 0 { + } + + if qBody.Value() < 0 { config.MaxRequestBodySize = "-1" } else { - config.MaxRequestBodySize = q.String() + config.MaxRequestBodySize = qBody.String() } - if q, err := resource.ParseQuantity(config.HTTPReadBufferSize); err != nil { + qBuffer, err := resource.ParseQuantity(config.HTTPReadBufferSize) + + if err != nil { return fmt.Errorf("invalid http read buffer size: %w", err) - } else if q.Value() < 0 { + } + + if qBuffer.Value() < 0 { config.HTTPReadBufferSize = "-1" } else { - config.HTTPReadBufferSize = q.String() + config.HTTPReadBufferSize = qBuffer.String() } err = config.validatePlacementHostAddr() @@ -277,20 +284,27 @@ func (config *RunConfig) ValidateK8s() error { config.MaxConcurrency = -1 } - if q, err := resource.ParseQuantity(config.MaxRequestBodySize); err != nil { + qBody, err := resource.ParseQuantity(config.MaxRequestBodySize) + if err != nil { return fmt.Errorf("invalid max request body size: %w", err) - } else if q.Value() <= 0 { + } + + if qBody.Value() < 0 { config.MaxRequestBodySize = "-1" } else { - config.MaxRequestBodySize = q.String() + config.MaxRequestBodySize = qBody.String() } - if q, err := resource.ParseQuantity(config.HTTPReadBufferSize); err != nil { + qBuffer, err := resource.ParseQuantity(config.HTTPReadBufferSize) + + if err != nil { return fmt.Errorf("invalid http read buffer size: %w", err) - } else if q.Value() <= 0 { + } + + if qBuffer.Value() < 0 { config.HTTPReadBufferSize = "-1" } else { - config.HTTPReadBufferSize = q.String() + config.HTTPReadBufferSize = qBuffer.String() } return nil