Skip to content

Conversation

Prakhar-Shankar
Copy link
Contributor

Problem:
Earlier the program was adding "/32" to every destination IP be it CIDR or IPv6.

Solution:
Introduced normalizeIPOrCIDR() to validate and normalize IPs:

  • Plain IPv4 - /32
  • Plain IPv6 - /128
  • Valid CIDR - kept as-is
  • Explicit errors on invalid IP/CIDR inputs.

fixes #717

Note - I have also added a test file to check everything is working fine.

Checklist:

  • Fixes DESTINATION_IPS in network experiments don't support CIDR blocks #717
  • PR messages has document related information
  • Labelled this PR & related issue with breaking-changes tag
  • PR messages has breaking changes related information
  • Labelled this PR & related issue with requires-upgrade tag
  • PR messages has upgrade related information
  • Commit has unit tests
  • Commit has integration tests
  • E2E run Required for the changes

Signed-off-by: Prakhar-Shankar <prakharshankar247@gmail.com>
Signed-off-by: Prakhar-Shankar <prakharshankar247@gmail.com>
@neelanjan00 neelanjan00 requested a review from Copilot September 27, 2025 19:04
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for CIDR blocks and IPv6 addresses in the pod network partition functionality. Previously, the system was incorrectly appending "/32" to all destination IPs regardless of their format.

  • Introduces normalizeIPOrCIDR() function to properly handle IPv4, IPv6, and CIDR formats
  • Replaces the previous IP processing logic with proper validation and normalization
  • Adds comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
network-policy.go Implements new IP/CIDR normalization logic and refactors setExceptIPs method
network-policy_cidr_test.go Adds unit tests for CIDR handling and IP normalization functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}
bad := []string{"", "foo", "10.0.0.0/33", "2001:db8::/129"}
for _, in := range bad {
if _, err := normalizeIPOrCIDR(in); err == nil && in != "" {
Copy link
Preview

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

The condition err == nil && in != "" is incorrect. For the empty string case, you want to expect no error since line 209 returns "", nil for empty strings. The condition should be err == nil to properly test that invalid inputs like "foo", "10.0.0.0/33", etc. return errors.

Suggested change
if _, err := normalizeIPOrCIDR(in); err == nil && in != "" {
if _, err := normalizeIPOrCIDR(in); err == nil {

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the test file, now it shows no error for empty string.

return nil
}

// It supports both CIDR block and IPv6 now
Copy link
Preview

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

This comment is incomplete and doesn't clearly describe what the function does. It should be expanded to: "normalizeIPOrCIDR validates and normalizes IP addresses or CIDR blocks, adding appropriate subnet masks (/32 for IPv4, /128 for IPv6) to plain IP addresses."

Suggested change
// It supports both CIDR block and IPv6 now
// normalizeIPOrCIDR validates and normalizes IP addresses or CIDR blocks,
// adding appropriate subnet masks (/32 for IPv4, /128 for IPv6) to plain IP addresses.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added these comments.

@neelanjan00
Copy link
Member

Hey @Prakhar-Shankar thanks for the PR 🙏, can you please address the Copilot comments?

Signed-off-by: Prakhar-Shankar <prakharshankar247@gmail.com>
@Prakhar-Shankar
Copy link
Contributor Author

Prakhar-Shankar commented Sep 29, 2025

Hey @Prakhar-Shankar thanks for the PR 🙏, can you please address the Copilot comments?

Thanks for reviewing, I have changed the test file so that it won't take empty string as an error. I have also added the recommended comments.

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.

DESTINATION_IPS in network experiments don't support CIDR blocks
2 participants