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

feat(transparent-proxy): allow configure transparent proxy from config file #11089

Merged
merged 29 commits into from
Aug 21, 2024

Conversation

bartsmykla
Copy link
Contributor

@bartsmykla bartsmykla commented Aug 12, 2024

This PR implements MADR: Streamlining Transparent Proxy Configuration (Phase 1): Enable Configuration via Config Files and Environment Variables

Note

Since this PR includes several changes that were necessary to introduce the described functionality, I recommend reviewing it commit by commit

Checklist prior to review

@bartsmykla bartsmykla added the ci/run-full-matrix PR: Runs all possible e2e test combination (expensive use carefully) label Aug 12, 2024
@bartsmykla bartsmykla force-pushed the feat/allow-configure-tproxy-from-file branch 3 times, most recently from 8b6daf7 to d2f2743 Compare August 13, 2024 11:56
The name `Comments` is more appropriate than `Comment`.

Signed-off-by: Bart Smykla <[email protected]>
This feature prepares for upcoming changes that use this function to
load transparent proxy config files.

Signed-off-by: Bart Smykla <[email protected]>
This change ensures consistency with the rest of the transparent proxy
config structures.

Signed-off-by: Bart Smykla <[email protected]>
This change removes unnecessary parsing and assigns the value directly
during flag parsing by the Cobra library.

Signed-off-by: Bart Smykla <[email protected]>
This will be used for parsing config files

Signed-off-by: Bart Smykla <[email protected]>
This will be used for parsing config files

Signed-off-by: Bart Smykla <[email protected]>
These abstractions allow setting values during Cobra flag parsing and
will be used for config file parsing in upcoming commits.

Signed-off-by: Bart Smykla <[email protected]>
Introduced a `Loader` struct with additional methods to support loading
configurations from various sources (file, raw content, or `io.Reader`)

Signed-off-by: Bart Smykla <[email protected]>
The `*Ports.Set` method is also invoked in `*Ports.UnmarshalJSON`, which
can lead to situations where config is parsed from JSON/YAML and then
modified by a CLI flag, causing values to merge instead of overwrite.
To ensure consistency, the slice should be cleared before setting new
values.

Signed-off-by: Bart Smykla <[email protected]>
The expected order of precedence was not being preserved, with configs
provided via `--transparent-proxy-config-file` or `--transparent-proxy-config` flags incorrectly taking the highest
priority. The correct order of precedence, from lowest to highest, is:

1. Config File (via `--transparent-proxy-config` or
   `--transparent-proxy-config-file` flags)
2. Environment Variables
3. CLI Flags

Signed-off-by: Bart Smykla <[email protected]>
Manually handle the `--help` flag since `DisableFlagParsing` is enabled,
requiring custom flag parsing to maintain the correct order of
precedence. To avoid unnecessary logic execution when `--help` is
invoked, moved the parsing of config-related flags into the `RunE`
method and removed the `PreRunE` method.

Signed-off-by: Bart Smykla <[email protected]>
@bartsmykla bartsmykla force-pushed the feat/allow-configure-tproxy-from-file branch from d2f2743 to fbfbeec Compare August 13, 2024 11:57
The transparent proxy does not rely on any of the features which are
being initialized in `PersistentPreRunE` method in the `kumactl` root
command. Since it handles its own flag parsing, processing the parent
flags like `--config-file` is unnecessary and would add unnecessary
complexity

Signed-off-by: Bart Smykla <[email protected]>
Since we’ve confirmed that the `--config-file` flag from the root
`kumactl` command isn’t parsed by `kumactl install transparent-proxy`,
we can safely use the same name for our flags

Signed-off-by: Bart Smykla <[email protected]>
Signed-off-by: Bart Smykla <[email protected]>
Signed-off-by: Bart Smykla <[email protected]>
To ensure durations are marshaled as readable strings (e.g., "2s")
instead of nanoseconds ("2000000000") in the kuma-init container, we've
updated sleepBetweenTries to use a custom duration type

Signed-off-by: Bart Smykla <[email protected]>
Added `omitempty` where necessary and the property names starting with
lower case where necessary

Signed-off-by: Bart Smykla <[email protected]>
Renamed `Owner` to `KumaDPUser` for consistency with the CLI flag
(`--kuma-dp-user`) and to improve clarity.

Signed-off-by: Bart Smykla <[email protected]>
@bartsmykla bartsmykla requested a review from slonka August 20, 2024 10:14
@bartsmykla bartsmykla marked this pull request as ready for review August 20, 2024 10:14
@bartsmykla bartsmykla requested a review from a team as a code owner August 20, 2024 10:14
@bartsmykla bartsmykla requested review from lobkovilya and removed request for a team August 20, 2024 10:14
pkg/config/loader.go Outdated Show resolved Hide resolved
@Icarus9913
Copy link
Contributor

Could you please add a precedence explanation for the flags, ENV, config-files in the install_transparent_proxy.go command Long message?

@bartsmykla
Copy link
Contributor Author

Could you please add a precedence explanation for the flags, ENV, config-files in the install_transparent_proxy.go command Long message?

Unfortunately it's currently not trivial to do because of the library we are using to parse this stuff. We'll have to update our docs at the beginning. Maybe I'll have some time later to figure this out

@bartsmykla bartsmykla enabled auto-merge (squash) August 21, 2024 10:52
@bartsmykla bartsmykla merged commit be80d0d into master Aug 21, 2024
35 checks passed
@bartsmykla bartsmykla deleted the feat/allow-configure-tproxy-from-file branch August 21, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/run-full-matrix PR: Runs all possible e2e test combination (expensive use carefully)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants