-
Notifications
You must be signed in to change notification settings - Fork 334
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
refactor(transparent-proxy): allow config to be initialized #10207
Merged
bartsmykla
merged 6 commits into
kumahq:master
from
bartsmykla:refactor/allow-config-to-be-initialized
May 10, 2024
Merged
refactor(transparent-proxy): allow config to be initialized #10207
bartsmykla
merged 6 commits into
kumahq:master
from
bartsmykla:refactor/allow-config-to-be-initialized
May 10, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By combining them all together at top it makes it easier to read. Signed-off-by: Bart Smykla <bartek@smykla.com>
`InitializedConfig` extends the `Config` struct by adding fields that require additional logic to retrieve their values. These values typically involve interacting with the system or external resources. An `InitializedConfig` can contain nested configuration structs. If these nested structs share field names with the `Config` struct, they should embed the corresponding field from `Config` during initialization. I.e. ```go type Redirect struct { // NamePrefix is a prefix which will be used go generate chains name NamePrefix string Inbound TrafficFlow Outbound TrafficFlow DNS DNS VNet VNet } type InitializedRedirect struct { Redirect DNS InitializedDNS } func (c Redirect) Initialize() (InitializedRedirect, error) { var err error initialized := InitializedRedirect{Redirect: c} // .DNS initialized.DNS, err = c.DNS.Initialize() ... return initialized, nil } ``` I moved obtaining DNS servers from `/etc/resolv.conf` and getting loopback network interface name to initialization methods for appropriate sub-configs. In the next iterations I plan to move iptables executables logic here. Signed-off-by: Bart Smykla <bartek@smykla.com>
As we have a package for consts let's use it everywhere Signed-off-by: Bart Smykla <bartek@smykla.com>
This structure was unnecessary as it was only used in `BuildIPTablesForRestore`, which also was using only its one method `BuildForRestore`. I moved logic of this method directly inside `BuildIPTablesForRestore`, which removes unnecessary complexity. Signed-off-by: Bart Smykla <bartek@smykla.com>
bartsmykla
added
area/kumactl
kind/cleanup
Cleanup/refactor an existing component/code
labels
May 9, 2024
bartsmykla
requested review from
slonka and
lobkovilya
and removed request for
a team
May 9, 2024 14:08
Signed-off-by: Bart Smykla <bartek@smykla.com>
michaelbeaumont
approved these changes
May 9, 2024
Signed-off-by: Bart Smykla <bartek@smykla.com>
lobkovilya
pushed a commit
that referenced
this pull request
May 15, 2024
- Introduced `InitializedConfig` structure `InitializedConfig` extends the `Config` struct by adding fields that require additional logic to retrieve their values. These values typically involve interacting with the system or external resources. An `InitializedConfig` can contain nested configuration structs. If these nested structs share field names with the `Config` struct, they should embed the corresponding field from `Config` during initialization. I.e. ```go type Redirect struct { // NamePrefix is a prefix which will be used go generate chains name NamePrefix string Inbound TrafficFlow Outbound TrafficFlow DNS DNS VNet VNet } type InitializedRedirect struct { Redirect DNS InitializedDNS } func (c Redirect) Initialize() (InitializedRedirect, error) { var err error initialized := InitializedRedirect{Redirect: c} // .DNS initialized.DNS, err = c.DNS.Initialize() ... return initialized, nil } ``` I moved obtaining DNS servers from `/etc/resolv.conf` and getting loopback network interface name to initialization methods for appropriate sub-configs. - Combined static variables in `builder_restore.go` By combining them all together at top it makes it easier to read. - Moved iptables/ip6tables consts to consts package As we have a package for consts let's use it everywhere - Got rid of unnecessary `IPTables` struct This structure was unnecessary as it was only used in `BuildIPTablesForRestore`, which also was using only its one method `BuildForRestore`. I moved logic of this method directly inside `BuildIPTablesForRestore`, which removes unnecessary complexity. Signed-off-by: Bart Smykla <bartek@smykla.com> Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
bartsmykla
added a commit
that referenced
this pull request
Jul 4, 2024
- Introduced `InitializedConfig` structure `InitializedConfig` extends the `Config` struct by adding fields that require additional logic to retrieve their values. These values typically involve interacting with the system or external resources. An `InitializedConfig` can contain nested configuration structs. If these nested structs share field names with the `Config` struct, they should embed the corresponding field from `Config` during initialization. I.e. ```go type Redirect struct { // NamePrefix is a prefix which will be used go generate chains name NamePrefix string Inbound TrafficFlow Outbound TrafficFlow DNS DNS VNet VNet } type InitializedRedirect struct { Redirect DNS InitializedDNS } func (c Redirect) Initialize() (InitializedRedirect, error) { var err error initialized := InitializedRedirect{Redirect: c} // .DNS initialized.DNS, err = c.DNS.Initialize() ... return initialized, nil } ``` I moved obtaining DNS servers from `/etc/resolv.conf` and getting loopback network interface name to initialization methods for appropriate sub-configs. - Combined static variables in `builder_restore.go` By combining them all together at top it makes it easier to read. - Moved iptables/ip6tables consts to consts package As we have a package for consts let's use it everywhere - Got rid of unnecessary `IPTables` struct This structure was unnecessary as it was only used in `BuildIPTablesForRestore`, which also was using only its one method `BuildForRestore`. I moved logic of this method directly inside `BuildIPTablesForRestore`, which removes unnecessary complexity. Signed-off-by: Bart Smykla <bartek@smykla.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Introduced
InitializedConfig
structureInitializedConfig
extends theConfig
struct by adding fields that require additional logic to retrieve their values. These values typically involve interacting with the system or external resources.An
InitializedConfig
can contain nested configuration structs. If these nested structs share field names with theConfig
struct, they should embed the corresponding field fromConfig
during initialization. I.e.I moved obtaining DNS servers from
/etc/resolv.conf
and getting loopback network interface name to initialization methods for appropriate sub-configs.Combined static variables in
builder_restore.go
By combining them all together at top it makes it easier to read.
Moved iptables/ip6tables consts to consts package
As we have a package for consts let's use it everywhere
Got rid of unnecessary
IPTables
structThis structure was unnecessary as it was only used in
BuildIPTablesForRestore
, which also was using only its one methodBuildForRestore
. I moved logic of this method directly insideBuildIPTablesForRestore
, which removes unnecessary complexity.Checklist prior to review
syscall.Mkfifo
have equivalent implementation on the other OSci/
labels to run additional/fewer testsUPGRADE.md
?