-
Notifications
You must be signed in to change notification settings - Fork 369
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
Extract iptables binary staging to iptablesutils #5095
Extract iptables binary staging to iptablesutils #5095
Conversation
83cd0eb
to
be3872c
Compare
Hi Tom, I came back to this and I started doing but I realized kubelet needs both the iptables binaries (which isn't a problem) and an iptables mode (which is either If we move the iptables binary staging, to a new component we need to gather this information from the iptables component to the kubelet component. We can set this field in the 1- Add some code between the calls of Option 1 is probably the cleanest so I implemented it.. Do you have any preference? |
9557c99
to
9f2ed63
Compare
After looking at the kubelet component, I think the only reason the component needs to know the iptables mode is because it currently extracts the iptables binaries. So if we put that in its own component, I don't see any reason why the kubelet component would need to know about the iptables mode anymore. I'd do something along those lines: type IPTablesSetup struct {
IPTablesMode string
// ...
}
func (i *IPTablesSetup) Init(context.Context) error { /* Gather iptables mode, extract binaries */ }
func (i *IPTablesSetup) Start(context.Context) error { /* No-op, probably? */ }
func (i *IPTablesSetup) Stop() error { /* No-op, probably? */ } The
Fortunately, as far as I can see, we won't need any of the above here. However, there's already precedence for the second approach in k0s. |
6b106f2
to
126d771
Compare
You're right, fixed. |
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.
I've left some proposals. I'd have approved this PR already, but since it's auto-merge, I just commented. Just ping me if you want me to approve this.
pkg/component/iptables/iptables.go
Outdated
@@ -32,6 +38,81 @@ const ( | |||
ModeLegacy = "legacy" | |||
) | |||
|
|||
type IPTables struct { | |||
IPTablesMode string | |||
K0sVars *config.CfgVars |
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.
If there was a BinDir
struct field instead of the K0sVars
struct field here, it would be immediately obvious that this component only needs the k0s bin dir from the config, nothing else.
pkg/component/iptables/iptables.go
Outdated
// ExtractIPTablesBinaries extracts the iptables binaries from the k0s binary and makes the symlinks | ||
// to the backend detected by DetectHostIPTablesMode. | ||
// ExtractIPTablesBinaries only works on linux, if called in another OS it will return an error. | ||
func ExtractIPTablesBinaries(k0sBinDir string, iptablesMode string) (error, string) { |
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.
This function could become private now.
pkg/component/iptables/iptables.go
Outdated
} | ||
|
||
func (i *IPTables) Init(_ context.Context) error { | ||
logrus.WithField("component", constant.IptablesBinariesComponentName).Info("Staging iptables binaries") |
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.
I'd just declare the logger once log := logrus.WithField("component", "iptables")
and then use it in lines 47 and 54. I'd also drop constant.IptablesBinariesComponentName
from constants.go and inline it here. It's only required once here. The component constants mainly exist to support the --disable-components
flag. I'd keep the struct name and the component name in sync.
pkg/component/iptables/iptables.go
Outdated
@@ -32,6 +38,81 @@ const ( | |||
ModeLegacy = "legacy" | |||
) | |||
|
|||
type IPTables struct { |
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.
We could also name this Component
to make it clear that this is the component: iptables.Component
reads a bit nicer than iptables.IPTables
IMO.
CPLB potentially will need to create some iptables rules for its userspace proxy, hence this code should be in a separate component. Signed-off-by: Juan-Luis de Sousa-Valadas Castaño <[email protected]>
126d771
to
ec6053a
Compare
These are good suggestions so I modified the code accordingly. I also squashed both commits into one because it doesn't really add value to have two. |
Successfully created backport PR for |
Description
CPLB potentially will need to create some iptables rules for its userspace proxy, hence this code should be in iptablesutils rather than pkg/worker/kubelet.
Fixes # (issue)
Type of change
How Has This Been Tested?
Checklist: