Skip to content

ECOPROJECT-4393 | fix: populate existing network configuration when editing environment#571

Merged
openshift-merge-bot[bot] merged 1 commit intokubev2v:masterfrom
rh-gvincent:ECOPROJECT-4393
Apr 16, 2026
Merged

ECOPROJECT-4393 | fix: populate existing network configuration when editing environment#571
openshift-merge-bot[bot] merged 1 commit intokubev2v:masterfrom
rh-gvincent:ECOPROJECT-4393

Conversation

@rh-gvincent
Copy link
Copy Markdown
Collaborator

@rh-gvincent rh-gvincent commented Apr 15, 2026

Environment edit form was not loading existing vmNetwork configuration, causing it to default to DHCP and lose static network settings.

Add getNetworkConfig helper to extract network configuration from Source objects and update DiscoverySourceSetupModal to properly load existing values when editing an environment.

Summary by CodeRabbit

  • New Features

    • Added comprehensive network configuration handling for discovery sources, including static IP address, subnet mask, gateway, and DNS support.
  • Tests

    • Added test suite for network configuration validation.
    • Updated proxy configuration tests to reflect field naming changes.
  • Chores

    • Refactored proxy configuration field names for consistency across the application.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

Warning

Rate limit exceeded

@rh-gvincent has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 58 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 11 minutes and 58 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d916b68-f8f6-46ec-b7f7-28e373ffe260

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca671d and cc2f053.

📒 Files selected for processing (5)
  • src/ui/environment/helpers/__tests__/networkConfig.test.ts
  • src/ui/environment/helpers/__tests__/proxyConfig.test.ts
  • src/ui/environment/helpers/networkConfig.ts
  • src/ui/environment/helpers/proxyConfig.ts
  • src/ui/environment/views/DiscoverySourceSetupModal.tsx
📝 Walkthrough

Walkthrough

This PR introduces network configuration support via a new getNetworkConfig helper and refactors proxy configuration field naming. It updates the ProxyConfig interface (renaming httpUrl/httpsUrl to httpProxy/httpsProxy and isProxyEnabled to enableProxy), adds comprehensive test coverage, and integrates both helpers into the DiscoverySourceSetupModal component for loading network and proxy settings.

Changes

Cohort / File(s) Summary
Network Configuration
src/ui/environment/helpers/networkConfig.ts, src/ui/environment/helpers/__tests__/networkConfig.test.ts
New NetworkConfig interface and getNetworkConfig helper function that extracts IPv4 static network configuration from Source objects, defaulting to DHCP mode with empty strings for missing fields. Test suite validates static mode detection and DHCP fallback behavior across various undefined scenarios.
Proxy Configuration Updates
src/ui/environment/helpers/proxyConfig.ts, src/ui/environment/helpers/__tests__/proxyConfig.test.ts
ProxyConfig interface fields renamed: httpUrlhttpProxy, httpsUrlhttpsProxy, and isProxyEnabledenableProxy. getProxyConfig function updated to assign values using new field names. Test expectations adjusted to reflect the new interface shape and property names.
Modal Integration
src/ui/environment/views/DiscoverySourceSetupModal.tsx
Updated to use getNetworkConfig and getProxyConfig helpers when loading existing sources. State setters now map to renamed proxy fields (httpProxy, httpsProxy, enableProxy) and new network fields (networkConfigType, ipAddress, subnetMask, defaultGateway, dns). initialValues now derived from helper outputs via spread composition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #545: Modifies proxy handling in DiscoverySourceSetupModal with centralized getProxyConfig helper and overlapping test updates.
  • #168: Updates proxy field handling in DiscoverySourceSetupModal with the same field name changes (httpProxy, httpsProxy, enableProxy).
  • #144: Adds handling for static network fields (networkConfigType, ipAddress, subnetMask, defaultGateway, dns) through create/update APIs and UI flows.

Suggested labels

lgtm, approved

Suggested reviewers

  • machacekondra
  • ammont82
  • tupyy

Poem

🐰 Whiskers twitch with glee so bright,
Network configs now working right!
Proxy names all freshly dressed,
httpProxy, httpsProxy—simply blessed!
From DHCP to static we now can choose,
A helper's gift we cannot lose! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: fixing the population of existing network configuration in the environment editor, which is the primary objective across all file modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/ui/environment/views/DiscoverySourceSetupModal.tsx (1)

402-413: Move edit-form hydration mapping out of the view layer.

This block performs business/data-mapping logic in a views component. Prefer moving this transformation into the environment VM (or a dedicated hook) and keep the view focused on render + state wiring.

As per coding guidelines, Views in src/ui/*/views/ must render only with no business logic, calling vm hook at top.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ui/environment/views/DiscoverySourceSetupModal.tsx` around lines 402 -
413, The view DiscoverySourceSetupModal is doing business/data-mapping (calling
getNetworkConfig and building the initialValues object, then calling
setNetworkConfigType/setIpAddress/setSubnetMask/setDefaultGateway/setDns/setInitialValues);
move that hydration out of the view into the environment VM or a dedicated hook
(e.g., add a method on the Environment VM like hydrateDiscoverySourceForm(src)
or create a hook useDiscoverySourceFormValues(src) that returns {
networkConfigType, ipAddress, subnetMask, defaultGateway, dns, initialValues }
where initialValues composes sshKey, environmentName, ...proxyConfig and
...networkConfig); then in the view call the VM method/hook at the top and use
its returned values to set state (invoke setNetworkConfigType, setIpAddress,
etc. and setInitialValues) so the component contains only render/state wiring.
src/ui/environment/helpers/__tests__/proxyConfig.test.ts (1)

65-80: Add a regression test for whitespace-only proxy values.

Since enableProxy is inferred, add coverage for httpUrl: " " / httpsUrl: " " / noProxy: " " so behavior is explicit and protected.

🧪 Suggested test case
+    it("should keep proxy disabled when values are whitespace-only", () => {
+      const source: Partial<Source> = {
+        infra: {
+          proxy: {
+            httpUrl: "   ",
+            httpsUrl: "   ",
+            noProxy: "   ",
+          },
+        },
+      };
+
+      const config = getProxyConfig(source as Source);
+      expect(config.enableProxy).toBe(false);
+    });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ui/environment/helpers/__tests__/proxyConfig.test.ts` around lines 65 -
80, Add a regression test that supplies whitespace-only strings for
infra.proxy.httpUrl, httpsUrl, and noProxy and assert that getProxyConfig treats
them as empty (trimmed) values so enableProxy is false; specifically, update or
add a test around getProxyConfig with httpUrl: "   ", httpsUrl: "   ", noProxy:
"   " and expect config.enableProxy toBe(false) and config.noProxy toBe("") or
null per your normalization. If necessary, update getProxyConfig to trim proxy
fields (httpUrl, httpsUrl, noProxy) before computing enableProxy and before
returning the config so whitespace-only values are treated as unset.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/ui/environment/helpers/proxyConfig.ts`:
- Line 30: The enableProxy calculation currently uses raw string truthiness
(enableProxy: Boolean(httpProxy || httpsProxy || noProxy)); change it to
consider trimmed values so whitespace-only strings are treated as empty: derive
trimmedHttp = httpProxy?.trim(), trimmedHttps = httpsProxy?.trim(), trimmedNo =
noProxy?.trim() (or call .trim() inline) and set enableProxy to
Boolean(trimmedHttp || trimmedHttps || trimmedNo) so the form won't mark proxy
enabled for whitespace-only input; update any nearby references in
proxyConfig.ts that rely on the original variables accordingly.

---

Nitpick comments:
In `@src/ui/environment/helpers/__tests__/proxyConfig.test.ts`:
- Around line 65-80: Add a regression test that supplies whitespace-only strings
for infra.proxy.httpUrl, httpsUrl, and noProxy and assert that getProxyConfig
treats them as empty (trimmed) values so enableProxy is false; specifically,
update or add a test around getProxyConfig with httpUrl: "   ", httpsUrl: "   ",
noProxy: "   " and expect config.enableProxy toBe(false) and config.noProxy
toBe("") or null per your normalization. If necessary, update getProxyConfig to
trim proxy fields (httpUrl, httpsUrl, noProxy) before computing enableProxy and
before returning the config so whitespace-only values are treated as unset.

In `@src/ui/environment/views/DiscoverySourceSetupModal.tsx`:
- Around line 402-413: The view DiscoverySourceSetupModal is doing
business/data-mapping (calling getNetworkConfig and building the initialValues
object, then calling
setNetworkConfigType/setIpAddress/setSubnetMask/setDefaultGateway/setDns/setInitialValues);
move that hydration out of the view into the environment VM or a dedicated hook
(e.g., add a method on the Environment VM like hydrateDiscoverySourceForm(src)
or create a hook useDiscoverySourceFormValues(src) that returns {
networkConfigType, ipAddress, subnetMask, defaultGateway, dns, initialValues }
where initialValues composes sshKey, environmentName, ...proxyConfig and
...networkConfig); then in the view call the VM method/hook at the top and use
its returned values to set state (invoke setNetworkConfigType, setIpAddress,
etc. and setInitialValues) so the component contains only render/state wiring.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 53bfbb62-dddb-4b88-9874-79dfd943be3c

📥 Commits

Reviewing files that changed from the base of the PR and between f02a040 and 5ca671d.

📒 Files selected for processing (5)
  • src/ui/environment/helpers/__tests__/networkConfig.test.ts
  • src/ui/environment/helpers/__tests__/proxyConfig.test.ts
  • src/ui/environment/helpers/networkConfig.ts
  • src/ui/environment/helpers/proxyConfig.ts
  • src/ui/environment/views/DiscoverySourceSetupModal.tsx

Comment thread src/ui/environment/helpers/proxyConfig.ts Outdated
…diting environment

Environment edit form was not loading existing vmNetwork configuration, causing it to default to DHCP and lose static network settings.

Add getNetworkConfig helper to extract network configuration from Source objects and update DiscoverySourceSetupModal to properly load existing values when editing an environment.

Signed-off-by: Guillaume Vincent <gvincent@redhat.com>
@ammont82
Copy link
Copy Markdown
Collaborator

/lgtm

@rh-gvincent
Copy link
Copy Markdown
Collaborator Author

/approve

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 15, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rh-gvincent

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

The pull request process is described here

Details 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

@rh-gvincent
Copy link
Copy Markdown
Collaborator Author

/retest

@openshift-merge-bot openshift-merge-bot bot merged commit f8d9db7 into kubev2v:master Apr 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants