Skip to content

Conversation

@LukeAVanDrie
Copy link
Contributor

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
This PR refactors the configuration loading architecture to standardize how the system instantiates plugins and injects mandatory architectural components (like ProfileHandlers and Pickers).

Reasoning:
Currently, configuration loading is split into "Phase 1" and "Phase 2" with ad-hoc mutation logic scattered between them. This refactor clearly scopes these phases and unifies the complex instantiation logic into a linear pipeline.

Key Changes:

  1. Clear Phase Scoping:
    • Renames LoadConfigPhaseOne to LoadRawConfig (pure parsing/struct validation).
    • Refactors LoadConfigPhaseTwo into InstantiateAndConfigure. This function now encapsulates the entire system construction workflow: Instantiate Plugins -> Apply System Defaults -> Deep Validate -> Build Scheduler.
  2. Standardized Default Injection: Replaces bespoke logic for injecting MaxScorePicker and SingleProfileHandler with a unified registerDefaultPlugin pattern. This allows us to guarantee architectural integrity using generic code.
  3. Observability: Improves error wrapping throughout the loading process and logs the "Effective Configuration" (including injected defaults) so operators know exactly what the system is running.
  4. Test Suite Overhaul: Completely rewrites configloader_test.go to use table-driven tests, proper parallelism, and stricter validation of post-instantiation state.

Architectural Benefit:
This establishes the pattern required for promoting other hardcoded components (like the Saturation Detector) to plugins in the future. It moves the system from an imperative loading script to a declarative architectural assurance model.

Which issue(s) this PR fixes:
Tracks #1793 -- This makes future changes easier for modeling saturation control as a EPP default plugin rather than a standalone component (we require similar handling to WeightedScorer and default Picker).

Does this PR introduce a user-facing change?:

NONE

Refactors the configuration loader to clarify the two-stage loading
process and standardize default injection.

This change:
- Merges the loading lifecycle into a linear pipeline: Load Raw ->
  Instantiate -> Apply System Defaults -> Validate -> Build.
- Introduces a `registerDefaultPlugin` helper to standardize how
  mandatory components (like MaxScorePicker and SingleProfileHandler)
  are injected when omitted by the user.
- Improves error wrapping context throughout the loading process.
Rewrites `configloader_test.go` to use table-driven tests and improves
overall test hygiene.

Key improvements:
- Separates tests for "Raw Loading" (Phase 1) and "Instantiation"
  (Phase 2) to mirror the new production architecture.
- Adds comprehensive test data constants in `testdata.go` to prevent
  drift between YAML and Go struct definitions.
- Adds deep validation callbacks to verify post-instantiation state,
  ensuring defaults are injected correctly.
Updates the EPP runner to use the refactored loader functions.

The flow is updated to:
1. `loader.LoadRawConfig` to parse bytes and retrieve feature gates.
2. Initialize the plugin handle.
3. `loader.InstantiateAndConfigure` to build the final configuration.
@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Dec 5, 2025
@netlify
Copy link

netlify bot commented Dec 5, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 2c7ada7
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/693232b69164fd0008cd7793
😎 Deploy Preview https://deploy-preview-1953--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LukeAVanDrie
Once this PR has been reviewed and has the lgtm label, please assign kfswain for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @LukeAVanDrie. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 5, 2025
@ahg-g
Copy link
Contributor

ahg-g commented Dec 6, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 6, 2025
Copy link
Contributor

@ahg-g ahg-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there really a major change here other than deduping the saturation detection config defaulting (it was done in two places, now it is one place, which is good)?

r.registerInTreePlugins()

rawConfig, featureGates, err := loader.LoadConfigPhaseOne(configBytes, logger)
rawConfig, featureGates, err := loader.LoadRawConfig(configBytes, logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is still run as phase one and phase two, see calling function names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, I am scoping this change to config/loader package. Will clean this up in runner.go in a separate pass. For now, I just want these names to be semantically clearer. I have a draft for those runner.go changes, I can share the relevant snippet if you would like.

cfg *configapi.EndpointPickerConfig,
handle plugins.Handle,
name string,
pluginType string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can pass the type only and default the name to the type

@ahg-g
Copy link
Contributor

ahg-g commented Dec 6, 2025

Not against it, nice cleanup, but want to confirm my read of the PR which mostly affirms the existing design with clearer naming of the phases

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 6, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

if err != nil {
return nil, nil, err
}
logger.V(1).Info("Loaded raw configuration", "config", rawConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we use logger utils consts instead of numbers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants