-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
iptables: refactor to avoid global variables #47644
Conversation
Skipping CI for Draft Pull Request. |
c79c15b
to
062a322
Compare
Currently, we have a complete mess of configuration for the iptables commands. This is driven a few issues: * It was designed to be *byte for byte* compatible with the original Bash script years ago, so it has a ton of weird bash-isms. * It is designed exclusively as a command line, but now its used beyond that (in CNI, etc) * Uses lots of globals, and each config item ends up in 3-4 places. This PR refactors this to simplify the configuration surface. The actual goal of this is to make it safe to run the iptables setup multiple times in a long running fashion; due to global variable usage this was extremely hard to do so safely previously. As part of this, a new package `pkg/flag` is introduced. This replaces our minimal usage of viper with ~3 lines of code to allow setting a flag's default value from an environment variable. There should be no behavioral differences, except some of the `--help` output is more clear (defaults shown)
062a322
to
d798c4f
Compare
DefaultIptablesProbePort = "15002" | ||
DefaultProbeTimeout = 5 * time.Second | ||
DefaultIptablesProbePort = "15002" | ||
DefaultIptablesProbePortUint = 15002 |
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.
Any reason to not use strconv.ParseUint
instead of having 2 constants?
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.
Good cleanup.
Currently, we have a complete mess of configuration for the iptables commands. This is driven a few issues:
This PR refactors this to simplify the configuration surface. The actual goal of this is to make it safe to run the iptables setup multiple times in a long running fashion; due to global variable usage this was extremely hard to do so safely previously.
As part of this, a new package
pkg/flag
is introduced. This replaces our minimal usage of viper with ~3 lines of code to allow setting a flag's default value from an environment variable.There should be no behavioral differences, except some of the
--help
output is more clear (defaults shown)Please provide a description of this PR: