-
Notifications
You must be signed in to change notification settings - Fork 165
refactor: flow control config #1581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: flow control config #1581
Conversation
Hi @LukeAVanDrie. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
/ok-to-test |
Introduces a consistent `ValidateAndApplyDefaults` method to the configuration structs in the `flowcontrol/controller` and `flowcontrol/registry` packages. This change refactors the configuration handling to follow a unified pattern: - Configuration structs now have a `ValidateAndApplyDefaults` method that returns a new, validated config object without mutating the original. - Constructors for `FlowController` and `FlowRegistry` now assume they receive a valid configuration, simplifying their logic and pushing the responsibility of validation to the caller. - The `deepCopy` logic is corrected to ensure test assertions for immutability pass reliably. This improves the clarity and robustness of configuration management within the flow control module, creating a consistent foundation for future wiring work.
Introduces a new top-level `Config` for the Flow Control layer. This config bundles the configurations for the `controller` and `registry` packages, providing a single, unified point of entry fo validation and default application. This simplifies the management and initialization of the flow control system by centralizing its configuration.
185cc02
to
4fad1a9
Compare
|
||
// ValidateAndApplyDefaults checks the configuration for validity and populates any empty fields with system defaults. | ||
// It delegates validation to the underlying controller and registry configurations. | ||
// It returns a new, validated `Config` object and does not mutate the receiver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kfswain Let's continue our discussion from the previous controller PR here regarding the config defaulting pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// It returns a new, validated
Config
object and does not mutate the receiver.
My preference is to keep functions pure. It's easier to test and has no side effects. You could argue that this is better expressed as ValidateAndApplyDefaults(cfg Config) (*Config, error)
. You can also argue that my existing implementation should mutate the receiver.
Or even that validation and defaulting should be split.
I am not strongly opinionated here. We should just decide on a consistent pattern.
The previous commit introduced a unified and validated configuration for the flow control system, requiring callers to pass a pre-validated cofig to the controller and registry respectively. This change updates the controller tests to provide a valid configuration instead of relying on the now-removed defaulting logic in the constructor.
} | ||
|
||
// --- Defaulting --- | ||
if c.ExpiryCleanupInterval == 0 { | ||
c.ExpiryCleanupInterval = defaultExpiryCleanupInterval | ||
if cfg.ExpiryCleanupInterval == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: in k8s, object defaulting is done before validation, consider having a similar sequence here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, would we default invalid values (e.g., a negative duration) to the default silently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we run validation after defaulting, we protect against that, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah; I am just thinking about UX. Say we wire this up to the text-based config. A user specified an invalid byte limit for queue capacity (e.g., outside of a min-max range of 10mb to 1gb -- not something we enforce yet, but meant as an illustrative example). Is it better to default an invalid value (e.g., 5 mb) to the min (possibly logging a warning) or just fail immediately?
Either way is safe. It's just a matter of failing fast and loud vs silently (or transparently) correcting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever I connect this to the config surface, I can revisit this based on your feedback. Either approach sgtm. For now, there is no way to specify non-default values anyways.
for _, opt := range opts { | ||
opt(newCfg) | ||
} | ||
return newCfg.ValidateAndApplyDefaults() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we calling this here again if it was called by the top level ValidateAndApplyDefaults
in the flowcontrol/config pkg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newConfig
is a test-only helper for generating a valid, defaulted config for the registry tests. I can move this into registry_test.go
as that is the only place it is called. It's purpose is to set the test-only variadic options for overriding the policy/queue factories.
It is also likely that once I update the flow control plugin factories to follow the scheduler pattern, instantiation will be done outside the registry and these will no longer be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is also not a new function by the way. I just un-exported it and moved it toward the bottom of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, missed the test-only comment.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahg-g, LukeAVanDrie The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR refactors the configuration handling within the
pkg/epp/flowcontrol
package and its sub-packages (controller
,registry
) to improve robustness, consistency, and clarity.The core of the refactoring replaces the
newConfig
factory function pattern with a publicValidateAndApplyDefaults
method on the configuration structs. This change:FlowController
andFlowRegistry
, as they now expect a pre-validated configuration.flowcontrol.Config
to provide a single, unified entry point for the entire module's configuration (simplifies wiring this layer into the rest of EPP).Overall, these changes lead to a more maintainable and less error-prone configuration system.
Which issue(s) this PR fixes:
Tracks #674
Does this PR introduce a user-facing change?:
cc @rahulgurnani