fix(cfg): allow partial DpfServiceConfig overrides in site config - #4604
fix(cfg): allow partial DpfServiceConfig overrides in site config#4604shayan1995 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Summary by CodeRabbit
Walkthrough
ChangesDPF service default filling
Estimated code review effort: 2 (Simple) | ~15 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/api-core/src/cfg/file.rs`:
- Around line 1624-1625: The serde defaulting in DpfServiceConfig and the loader
path around DpfDeploymentConfig::extra_services currently allow partial
extra-service overrides to replace built-in definitions with empty fields. Scope
partial deserialization to mandatory-service overrides or, preferably, merge
each partial extra_services entry with its matching DpfExtraService default in
the loader; add a table-driven regression test covering partial extra-service
overrides, updating both crates/api-core/src/cfg/file.rs:1624-1625 and
crates/api-core/src/cfg/load.rs:121-147 as needed.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 088da268-d818-4ce4-a899-826e7e931762
📒 Files selected for processing (2)
crates/api-core/src/cfg/file.rscrates/api-core/src/cfg/load.rs
When setup.sh sets NICO_DPF_*_CHART_VERSION, _dpf_inject_service_overrides inserts e.g. [dpf.services.dhcp_server] with only helm_version into the site config TOML. This caused nico-api to crash with 'missing field name' because: 1. DpfServiceConfig had no serde default — all fields were required. 2. The #[serde(default = "default_dhcp_server_service")] on DpfMandatoryServicesConfig.dhcp_server fires only when the key is completely absent, not when it is partially specified. 3. The compiled-in service defaults (name, helm_repo_url, etc.) live in Rust code, not in any TOML file that Figment can deep-merge. Fix: add #[serde(default)] at the DpfServiceConfig struct level so partial configs deserialise without error (missing fields become empty strings), then call fill_from_defaults() for each mandatory service immediately after Figment extraction. This restores any empty field from the service's compiled-in default, so a site-config partial override of only helm_version produces a fully-populated config with the correct name, helm_repo_url, etc. Signed-off-by: Shayan Namaghi <snamaghi@nvidia.com>
034e79a to
9e62a8c
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Closing — PR #4563 fixed the same root cause through a cleaner mechanism. It replaced the per-field |
Root cause
PR #4511 fixed the YAML-level parse error (TOML appended at file level) so that
[dpf.services.*]sections now land insidenicoApiSiteConfigcorrectly. However nico-api still crashes whenNICO_DPF_*_CHART_VERSIONoverrides are set:Three conditions combine to produce this:
DpfServiceConfighad no#[serde(default)]— every field was required by serde.#[serde(default = "default_dhcp_server_service")]onDpfMandatoryServicesConfig.dhcp_serveronly fires when the key is completely absent, not when it is partially specified.name,helm_repo_url, etc.) live only in Rust code, not in any TOML file that Figment can deep-merge. So when the site config providesdhcp_server = {helm_version: "2.1.0"}, Figment sees only that one field and serde fails onname.Fix
Two changes:
crates/api-core/src/cfg/file.rs— add#[serde(default)]at theDpfServiceConfigstruct level so a partial config (e.g. onlyhelm_version) deserialises without error (missing string fields become""). AddDpfServiceConfig::fill_from_defaults()to restore any empty field from a reference config.crates/api-core/src/cfg/load.rs— callfill_from_defaults()for each mandatory service immediately after Figment extraction, using the compiled-in service default as the reference. This restoresname,helm_repo_url, etc. from the Rust defaults, so a site-config partial override of onlyhelm_versionproduces a fully-populated config.The same fill is applied to per-deployment service overrides (bf3, bf4_generic, bf4_astra).
Related
Follow-up to #4511.
Type of Change
Testing
Verified with
NICO_DPF_DHCP_SERVER_CHART_VERSION=2.1.0-testin the site config — nico-api starts cleanly anddhcp_server.nameis populated from the compiled default.