Skip to content

fix: do not emit empty loadBalancing block on every DNSPolicy#558

Open
shubhamkumar9199 wants to merge 1 commit into
Kuadrant:mainfrom
shubhamkumar9199:fix-dnspolicy-loadbalancing-always-emitted
Open

fix: do not emit empty loadBalancing block on every DNSPolicy#558
shubhamkumar9199 wants to merge 1 commit into
Kuadrant:mainfrom
shubhamkumar9199:fix-dnspolicy-loadbalancing-always-emitted

Conversation

@shubhamkumar9199

@shubhamkumar9199 shubhamkumar9199 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

hasLoadBalancing was computed from loadBalancing.weight != null, but weight defaults to 120, so the condition was always true. As a result every DNSPolicy created via the form serialized a spec.loadBalancing block (with just weight: 120 and no geo) even when the user never opened the Load Balancing section.

Gate on loadBalancing.geo instead, which is the field the form validation already requires for load balancing and which is populated both when the user fills the section and when an existing policy is loaded for editing.

Type of change

  • [fix] Bug fix
  • [feat] New feature
  • [refactor] Refactor (no functional changes)
  • [test] Test updates
  • [chore] Dependency / config update

Test plan

  • yarn lint passes (no changes after running)
  • yarn build passes
  • yarn i18n passes (no changes after running — commit updated locale files if needed)
  • Tested manually in OpenShift Console
  • Tested in both light and dark themes
  • Tested in all-namespaces and single namespace mode

Checklist

  • All user-facing strings use t() and are added to locales/en/plugin__kuadrant-console-plugin.json
  • CSS classes are prefixed with kuadrant- — no bare .pf-* or .co-* selectors, no hex colors
  • No console.log statements left in
  • Commits include Signed-off-by line (git commit -s)

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue in DNS Policy creation where incomplete load balancing configurations could be saved when the user had not fully configured the load balancing settings. The form now ensures that load balancing options are only included when the geographical distribution option is properly configured.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

In KuadrantDNSPolicyCreatePage.tsx, the createDNSPolicy() helper's guard for emitting the spec.loadBalancing block is narrowed from a three-part OR condition (geo, defaultGeo !== '', weight != null) to a single Boolean(loadBalancing.geo) check, with inline comments added to document the intent.

Changes

DNS Policy Load-Balancing Emission Guard

Layer / File(s) Summary
Narrow loadBalancing emission guard to geo only
src/components/KuadrantDNSPolicyCreatePage.tsx
The condition controlling whether spec.loadBalancing is included in the created policy object is changed to Boolean(loadBalancing.geo), replacing the prior OR across geo, defaultGeo !== '', and weight != null. Inline comments are added to document that geo is used as the sole gate to prevent emitting an incomplete section.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Possibly related PRs

  • Kuadrant/kuadrant-console-plugin#515: Modifies the same spec.loadBalancing conditional construction in KuadrantDNSPolicyCreatePage.tsx, specifically around how weight presence is evaluated — directly overlapping with the spec-generation path touched by this PR.

Suggested reviewers

  • didierofrivia
  • R-Lawton

Poem

🐇 A single check for geo is all we need,
No more three-way guards to plant the seed.
If geo is truthy, the block shall appear,
Otherwise no half-baked spec to fear.
Cleaner policies, hopping along — hooray! 🌍

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarises the bug fix: preventing an empty loadBalancing block from being emitted for every DNSPolicy.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shubhamkumar9199 shubhamkumar9199 force-pushed the fix-dnspolicy-loadbalancing-always-emitted branch from 65ae394 to 307d13b Compare June 21, 2026 20:58
hasLoadBalancing was computed from `loadBalancing.weight != null`, but
weight defaults to 120, so the condition was always true. As a result
every DNSPolicy created via the form serialized a `spec.loadBalancing`
block (with just `weight: 120` and no geo) even when the user never
opened the Load Balancing section.

Gate on `loadBalancing.geo` instead, which is the field the form
validation already requires for load balancing and which is populated
both when the user fills the section and when an existing policy is
loaded for editing.

Signed-off-by: shubhamsharma9199 <shubham.24bcs10320@sst.scaler.com>
@shubhamkumar9199 shubhamkumar9199 force-pushed the fix-dnspolicy-loadbalancing-always-emitted branch from 307d13b to 51ec31f Compare June 30, 2026 18:10

@emmaaroche emmaaroche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please create an issue for PRs being opened if there isn't one already.

Found what I feel is a UX issue during testing where the weight now shows as placeholder only and the user must manually type 120 for it to serialize.

Placeholder text can be confusing as it looks filled in but isn't actually a value. Better approach might be to keep weight pre-filled at 120 (actual value, not placeholder), but only serialize the loadBalancing block when geo is filled. This way:

  • Weight 120 is visible as the sensible default
  • No confusion about whether field is filled or not
  • Geo is required for load balancing anyway, so gating serialization on geo makes sense

So the implementation would be to initialize weight state to 120 (actual value, not placeholder), keep the hasLoadBalancing gate on geo (as this PR does), and when geo is filled serialize the entire block including weight. WDYT?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants