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

Fix empty message when host legacy routing is true #21314

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

vincentmli
Copy link
Contributor

@vincentmli vincentmli commented Sep 14, 2022

when missing tunnel and socketLB service check and when legacy host routing
set to true, the msg is empty with log

"level=warning msg=" Falling back to iptables-based masquerading." subsys=daemon"

this is confusing to users and not sure why falling back to iptables-based masquerading

before the fix:

run cilium agent in kernel 4.19 with

1 BPF masq enabled
2 Host legacy routing enabled
3 Tunnel enabled
4 FullHostReachableServices false

Cilium agent logs:
"level=warning msg=" Falling back to iptables-based masquerading." subsys=daemon"

the msg is empty because none of the switch cases matches, this could mis-lead users to
think BPF masquerade is not supported on kernel 4.19.

then when:

1 BPF masq enabled
2 Host legacy routing enabled
3 Tunnel disabled
4 Nodeport enabled

cilium agent keeps BPF masquerade enabled on kernel 4.19 without falling back to iptables-based masquerading

after the fix:

cilum agent log should log correct message + "Falling back to iptables-based masquerading."

Signed-off-by: Vincent Li v.li@f5.com

Please ensure your pull request adheres to the following guidelines:

  • For first time contributors, read Submitting a pull request
  • All code is covered by unit and/or runtime tests where feasible.
  • All commits contain a well written commit description including a title,
    description and a Fixes: #XXX line if the commit addresses a particular
    GitHub issue.
  • All commits are signed off. See the section Developer’s Certificate of Origin
  • Provide a title or release-note blurb suitable for the release notes.
  • Thanks for contributing!

Fixes: #21237

fix empty message when tunnel and socketLB service missing in switch case

@vincentmli vincentmli requested a review from a team as a code owner September 14, 2022 19:25
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Sep 14, 2022
@sayboras sayboras added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label Sep 15, 2022
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Sep 15, 2022
daemon/cmd/daemon.go Outdated Show resolved Hide resolved
@vincentmli vincentmli force-pushed the vli-bpfmasq branch 3 times, most recently from 6c0f5a8 to c6c79c6 Compare September 15, 2022 16:41
daemon/cmd/daemon.go Show resolved Hide resolved
daemon/cmd/daemon.go Outdated Show resolved Hide resolved
daemon/cmd/daemon.go Outdated Show resolved Hide resolved
@vincentmli vincentmli force-pushed the vli-bpfmasq branch 2 times, most recently from a935320 to b0db792 Compare September 15, 2022 17:48
Copy link
Member

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

The code looks good to me!

The commit description needs to be updated to reflect latest changes. Could you please also separate refactoring from fix, i.e. in 2 commits?

@vincentmli
Copy link
Contributor Author

sure will do

daemon/cmd/daemon.go Outdated Show resolved Hide resolved
daemon/cmd/daemon.go Outdated Show resolved Hide resolved
…ty msg

when missing tunnel and socketLB service check and  when legacy host routing
set to true, the msg is empty with log

"level=warning msg=" Falling back to iptables-based masquerading." subsys=daemon"

this is confusing to users and not sure why falling back to iptables-based masquerading

before the fix:

run cilium agent in kernel 4.19 with

1 BPF masq enabled
2 Host legacy routing enabled
3 Tunnel enabled
4 FullHostReachableServices false

Cilium agent logs:
 "level=warning msg=" Falling back to iptables-based masquerading." subsys=daemon"

the msg is empty because none of the switch cases matches, this could mis-lead users to
think BPF masquerade is not supported on kernel 4.19.

then when:

1 BPF masq enabled
2 Host legacy routing enabled
3 Tunnel disabled
4 Nodeport enabled

cilium agent keeps BPF masquerade enabled on kernel 4.19 without falling back to iptables-based masquerading

after the fix:

cilum agent log should log correct message + "Falling back to iptables-based masquerading."

Signed-off-by: Vincent Li <v.li@f5.com>
@pchaigno

This comment was marked as outdated.

Copy link
Member

@jibi jibi left a comment

Choose a reason for hiding this comment

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

Not sure if it would be more idiomatic to make msg an error and then log it with log.WithError(err).Warn("Falling back to iptables-based masquerading.")?

@vincentmli
Copy link
Contributor Author

log.WithError(err).Warn("Falling back to iptables-based masquerading.")

you mean something like this?

diff --git a/daemon/cmd/daemon.go b/daemon/cmd/daemon.go
index e2f967d9a0..8f74241d0a 100644
--- a/daemon/cmd/daemon.go
+++ b/daemon/cmd/daemon.go
@@ -923,25 +923,25 @@ func NewDaemon(ctx context.Context, cleaner *daemonCleanup,
        // happen after invoking initKubeProxyReplacementOptions().
        if option.Config.EnableIPv4Masquerade && option.Config.EnableBPFMasquerade {
 
-               var msg string
+               var err error
                switch {
                case !option.Config.EnableNodePort:
-                       msg = fmt.Sprintf("BPF masquerade requires NodePort (--%s=\"true\").",
+                       err = fmt.Sprintf("BPF masquerade requires NodePort (--%s=\"true\").",
                                option.EnableNodePort)
                case !option.Config.EnableRemoteNodeIdentity:
-                       msg = fmt.Sprintf("BPF masquerade requires remote node identities (--%s=\"true\").",
+                       err = fmt.Sprintf("BPF masquerade requires remote node identities (--%s=\"true\").",
                                option.EnableRemoteNodeIdentity)
                case option.Config.EgressMasqueradeInterfaces != "":
-                       msg = fmt.Sprintf("BPF masquerade does not allow to specify devices via --%s (use --%s instead).",
+                       err = fmt.Sprintf("BPF masquerade does not allow to specify devices via --%s (use --%s instead).",
                                option.EgressMasqueradeInterfaces, option.Devices)
                case option.Config.TunnelingEnabled() && !hasFullHostReachableServices():
-                       msg = "BPF masquerade requires full host reachable services enabled in tunnel mode."
+                       err = "BPF masquerade requires full host reachable services enabled in tunnel mode."
                }
                // ipt.InstallRules() (called by Reinitialize()) happens later than
                // this  statement, so it's OK to fallback to iptables-based MASQ.
-               if len(msg) > 0 {
+               if err != nil {
                        option.Config.EnableBPFMasquerade = false
-                       log.Warn(msg + " Falling back to iptables-based masquerading.")
+                       log.WithError(err).Warn("Falling back to iptables-based masquerading.")
                        // Too bad, if we need to revert to iptables-based MASQ, we also cannot
                        // use BPF host routing since we need the upper stack.
                        if !option.Config.EnableHostLegacyRouting {

@jibi
Copy link
Member

jibi commented Sep 16, 2022

you mean something like this?

yup, but using fmt.Errorf() instead of fmt.Sprintf(), as that will return an object of type error (also no need for the .s at the end of all the error messages then)

@vincentmli
Copy link
Contributor Author

like err = fmt.Errorf("BPF masquerade requires NodePort (--%s=\"true\")" ?

the code is doing if and switch case check, no need to check
it twice.

Signed-off-by: Vincent Li <v.li@f5.com>
@jibi
Copy link
Member

jibi commented Sep 16, 2022

/test

Copy link
Member

@jibi jibi left a comment

Choose a reason for hiding this comment

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

Double approval ✔️ ✔️
Thanks for going through the refactoring and nits 🙏

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Sep 16, 2022
@pchaigno pchaigno merged commit b4e919e into cilium:master Sep 16, 2022
@vincentmli vincentmli deleted the vli-bpfmasq branch September 17, 2022 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eBPF based maquerading not supported on kernel 4.19?
5 participants