-
Notifications
You must be signed in to change notification settings - Fork 198
Adds support for iptables ingress packet loss #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Testing: Create a docker network for your testdocker network create iperf Create an iperf serverTo listen to multicast docker run --rm -it --network=iperf --name server sk278/iperf -s -u -B 226.94.1.1 -i 1 Run an iperf clientdocker run --rm -it --network=iperf --name client sk278/iperf -c 226.94.1.1 -u -T 32 -t 3 -i 1 Watch the output on your serverNo packet loss...
Start pumba to apply loss on your serverpumba --iptables-image rancher/mirrored-kube-vip-kube-vip-iptables:v0.8.9 -d 1m -p udp --dport 5001 loss --probability 0.2 server Start you client againdocker run --rm -it --network=iperf --name client sk278/iperf -c 226.94.1.1 -u -T 32 -t 3 -i 1 Magic
|
I may need some help with these failing tests and why they are failing... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall Feedback
This PR is well-structured and addresses the use case described in issue #263 well. The implementation follows the general patterns established in the project. However, there are several issues that need to be addressed before merging:
Critical Issues
- Command Construction Bug: There's a significant bug in the command construction logic that will prevent IP and port filtering from working correctly:
// In pkg/container/docker_client.go
// # drop traffic to a specific source address
for _, ip := range srcIPs {
cmd := append(cmdPrefix, "-s", ip.String())
cmd = append(cmdPrefix, cmdSuffix...) // BUG: Should be appending to 'cmd', not 'cmdPrefix'
commands = append(commands, cmd)
}
This issue appears in all four filter loops (srcIPs, dstIPs, sports, dports). It's overwriting the filter command with cmdPrefix, essentially losing the IP/port filter.
Fix by changing to:
for _, ip := range srcIPs {
cmd := append(cmdPrefix, "-s", ip.String())
cmd = append(cmd, cmdSuffix...) // Use 'cmd' instead of 'cmdPrefix'
commands = append(commands, cmd)
}
Code Style and Consistency Issues
-
Documentation: Please add more explanatory comments for the public functions, similar to those in the netem package.
-
Error Message Formatting: Standardize on using errors.Wrap/Wrapf pattern consistently:
// Instead of: return errors.New("invalid loss mode: must be either random or nth") // Prefer: return errors.Errorf("invalid loss mode: %s, must be either random or nth", mode)
-
Logging Consistency: Align logging levels with netem package. Some operations use debug level in iptables where netem uses info level for similar operations.
-
Function Naming: Rename
ipTablesContainerIPFilter
to match the pattern in netem (netemContainerWithIPFilter
). -
Parameter Ordering: Ensure parameter ordering in interface methods follows the established patterns.
Other Issues
-
MockClient Interface: The
StopIPTablesContainer
mock function signature doesn't match the actual interface, which could cause test failures. Please fix the mock implementation. -
Parameter Validation: Add validation that the
every
parameter is greater than 0 when using 'nth' mode.
This is good work overall, but these issues should be addressed before merging. Please make the necessary changes and request a re-review.
In Each of the four for loops (srcIPs, dstIPs, sports, dports) has the same issue: The second append call should use // Current:
cmd := append(cmdPrefix, "-s", ip.String())
cmd = append(cmdPrefix, cmdSuffix...) // WRONG: using cmdPrefix again
// Should be:
cmd := append(cmdPrefix, "-s", ip.String())
cmd = append(cmd, cmdSuffix...) // RIGHT: continue building on cmd This bug will cause all filters to be ignored, as each command ends up being just cmdPrefix followed by cmdSuffix without the actual filter parameters. |
In The mock is missing the container parameter which will cause test failures: // Current:
// StopIPTablesContainer provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8, _a9
func (_m *MockClient) StopIPTablesContainer(_a0 context.Context, _a1 *Container, _a2, _a3 []string, _a4, _a5 []*net.IPNet, _a6 []string, _a7 []string, _a8 string, _a9 bool, _a10 bool) error {
// ...
} Please ensure all mock implementations match their interface definitions. |
I use Mockery tool to generate mock for interfaces. Check the |
And thank you for this PR! |
Thank you for the thorough review! Good finds on the Some comments and requests for additional info inline below:
Anywhere specific? I copied the
I updated this in
Can you provide a pointer where you noticed this? Similar to
Not sure what you mean by this comment?
Used the mock generator to do this, hopefully this is now fixed. |
Sorry but it took me some time to figure out what went wrong with the test case but now it successfully runs on my dev system. I've also updated the |
Thank you for addressing the critical command construction bug and other issues from my previous review. I noticed one remaining validation issue: In pkg/chaos/iptables/loss.go, the validation for the 'every' parameter in 'nth' mode allows a value of 0: if every < 0 {
return nil, errors.Errorf("invalid loss every value: must be >= 0")
} For 'nth' mode, an 'every' value of 0 would cause division by zero issues or illogical behavior. Please update the validation to require 'every > 0' specifically when in 'nth' mode: if mode == "nth" && every <= 0 {
return nil, errors.Errorf("invalid loss every value for nth mode: must be > 0")
} Please also add unit tests to verify this validation behavior. Otherwise, the PR looks good to merge after this fix is applied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing most of the issues from my previous review. One remaining validation problem with the 'every' parameter in 'nth' mode needs to be fixed before merging. See my detailed comment for the suggested solution.
Hi @eelcocramer, Thanks for your work on this PR! We're getting close - I just wanted to point out a version compatibility issue that's causing CI to fail. The current error is related to the generated mock files and Go versions:
I noticed the PR's You have two options to resolve this:
Either approach is fine with me - you can choose what works best. If you decide to upgrade to Go 1.24, it might be cleaner to do that in a separate PR first, before merging this one. Let me know if you have any questions! |
I've updated the repository workflow permissions to allow contributors to run the workflows on their PRs. You should now be able to re-run failed workflows without my approval. Feel free to make the suggested changes and verify your fixes work by running the GitHub Actions workflows. |
an invalid parameter, i.e. `-dport` and `-sport` instead of `--dport` and `--sport`.
Hm, I don't think I'm able to run these workflow yet. |
@eelcocramer please run linter with |
Anything to satisfy the linter ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please restore the Dockerfile
- these settings helps to build multi-arch image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Great, thanks a lot! |
iptables
input rules to generate packet lossCloses #263