OCPBUGS-63543: fix: update redfish url validation#1504
Conversation
update validation for redfish url to give better error message when port number is not provided changed from using regex to using url.Parse to avoid any unforseen cases and support ipv6 added unit tests to cover changes Signed-off-by: ehila <ehila@redhat.com>
WalkthroughThe changes refactor address parsing in fencing configuration from regex-based extraction to URL parsing via Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
pkg/tnf/pkg/pcs/fencing.go (1)
129-149: Solid refactor to URL parsing with proper default port inference.The migration from regex to
url.Parseimproves robustness and adds native IPv6 support. The default port inference correctly distinguishes between HTTPS (443) and HTTP (80) schemes, and appropriately errors when the port cannot be determined.For slightly more robust scheme matching, consider using
strings.HasSuffixinstead ofstrings.Contains:if redfishPort == "" { switch { - case strings.Contains(parsedUrl.Scheme, "https"): + case strings.HasSuffix(parsedUrl.Scheme, "https"): redfishPort = "443" - case strings.Contains(parsedUrl.Scheme, "http"): + case strings.HasSuffix(parsedUrl.Scheme, "http"): redfishPort = "80" default:This prevents potential false matches with schemes like "myhttps" or "httpspecial", though given the Redfish context this is unlikely to occur.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (2)
pkg/tnf/pkg/pcs/fencing.go(3 hunks)pkg/tnf/pkg/pcs/fencing_test.go(2 hunks)
🔇 Additional comments (5)
pkg/tnf/pkg/pcs/fencing_test.go (3)
68-117: Excellent test coverage for default port inference.These test cases properly validate the default port behavior for HTTPS (443) and HTTP (80) when no explicit port is provided in the Redfish URL.
118-142: Strong IPv6 test coverage.This test case properly validates IPv6 address handling, ensuring the brackets are correctly stripped from the hostname while maintaining the full IPv6 address in the
Ipfield.
180-191: Good negative test case.This test appropriately validates that addresses without a proper scheme (missing "redfish+http" or "redfish+https" prefix) produce an error, as the port cannot be inferred.
pkg/tnf/pkg/pcs/fencing.go (2)
6-6: Appropriate import addition.The
net/urlimport is correctly added to support URL parsing functionality.
174-176: Correct mapping of parsed URL components.The extracted URL components (hostname, port, path) are properly mapped to the fencing device options. The use of
Hostname()correctly strips IPv6 brackets for theIpfield.
|
Nice 👍🏼 Are we fine with not looking for "redfish" substring in the path anymore? |
So that part still happens just above this line of code, https://github.com/openshift/cluster-etcd-operator/pull/1504/files#diff-026cdeecf29c80e2bda9316cc9f2d8c1433a3a05af902af1b20c2d13154dab54R122 so if we want to check for redfish that will trigger the failure there, otherwise here we just do the parsing. WDYT? |
oh sorry, I missed that check outside of the diff. So it was duplicate before (once in that mentioned check, once in the regex) 😁 /retest |
|
Oh no worries, as long as we don't care to enforce the schema pattern then we're good, personally I think we shouldn't since most people won't think to include it and we only pass along the IP address. /retest-required |
|
@eggfoobar: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. I understand the commands that are listed here. |
|
@eggfoobar: This pull request references Jira Issue OCPBUGS-63543, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
|
/jira refresh |
|
@eggfoobar: This pull request references Jira Issue OCPBUGS-63543, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
No GitHub users were found matching the public email listed for the QA contact in Jira (dhensel@redhat.com), skipping review request. DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
|
/approve |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: eggfoobar, fonta-rh, tjungblu The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/verified by unit tests |
|
@eggfoobar: This PR has been marked as verified by DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
|
@eggfoobar: Jira Issue Verification Checks: Jira Issue OCPBUGS-63543 Jira Issue OCPBUGS-63543 has been moved to the MODIFIED state and will move to the VERIFIED state when the change is available in an accepted nightly payload. 🕓 DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
|
/cherry-pick release-4.20 |
|
@eggfoobar: new pull request created: #1506 DetailsIn response to this:
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. |
|
Fix included in accepted release 4.21.0-0.nightly-2025-10-30-060549 |
update validation for redfish url to give better error message when port number is not provided
changed from using regex to using url.Parse to avoid any unforseen cases and support ipv6
added unit tests to cover changes