Skip to content
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

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

howardjohn
Copy link
Member

@howardjohn howardjohn commented Oct 30, 2023

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)

Please provide a description of this PR:

@howardjohn howardjohn added the release-notes-none Indicates a PR that does not require release notes. label Oct 30, 2023
@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Oct 30, 2023
@istio-testing
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@istio-testing istio-testing added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 30, 2023
@howardjohn howardjohn force-pushed the iptables/better-flags branch from c79c15b to 062a322 Compare October 30, 2023 16:23
@howardjohn howardjohn marked this pull request as ready for review October 30, 2023 16:24
@howardjohn howardjohn requested review from a team as code owners October 30, 2023 16:24
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Oct 30, 2023
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)
@howardjohn howardjohn force-pushed the iptables/better-flags branch from 062a322 to d798c4f Compare October 30, 2023 16:41
DefaultIptablesProbePort = "15002"
DefaultProbeTimeout = 5 * time.Second
DefaultIptablesProbePort = "15002"
DefaultIptablesProbePortUint = 15002
Copy link
Contributor

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?

Copy link
Contributor

@jacob-delgado jacob-delgado left a comment

Choose a reason for hiding this comment

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

Good cleanup.

@istio-testing istio-testing merged commit 97ffbee into istio:master Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes-none Indicates a PR that does not require release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants