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 to avoid adding FoU devices for pods that don't use its egress #265

Merged
merged 6 commits into from
Jan 17, 2024

Conversation

terassyi
Copy link
Contributor

@terassyi terassyi commented Nov 29, 2023

This PR is related: #253

Background

From coil v2.5, coild runs EgressWatcher to watch Egress resources.

When Egress resources are modified(or created, deleted), EgressWatcher reflects its configuration to pods that use its Egress.

What

When reflecting the change to the pod, EgressWatcher picks the wrong network namespace and creates a device for the wrong pod.

Why

EgressWatcher gets the network namespace associated with the target pod by the pods' IP addresses.

if c.IPv4.Equal(podIPv4) || c.IPv6.Equal(podIPv6) {

In this code, either c.IPv4.Equal(podIPv4) or c.IPv6.Equal(podIPv6) return true in almost case.
In the case of IPv4(or IPv6) single stack, this condition always returns true, and netNsPath is updated in every loop.
As a result, the wrong network namespace is picked.

@terassyi terassyi self-assigned this Nov 29, 2023
Signed-off-by: terasihma <[email protected]>
Signed-off-by: terasihma <[email protected]>
@terassyi terassyi force-pushed the avoid-adding-fou-devices-for-pods-not-using-egress branch from ed7889f to 7a7eb1b Compare December 18, 2023 04:28
@terassyi terassyi marked this pull request as ready for review December 18, 2023 04:36
@terassyi terassyi requested review from yokaze and masa213f December 18, 2023 04:37
v2/pkg/nodenet/pod.go Outdated Show resolved Hide resolved
Copy link
Contributor

@masa213f masa213f left a comment

Choose a reason for hiding this comment

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

As I commented elsewhere, please revise the test of podNetwrok.Update().
The test passes even after making the following changes.

diff --git a/v2/pkg/nodenet/pod.go b/v2/pkg/nodenet/pod.go
index adc5ef4..2fb7a06 100644
--- a/v2/pkg/nodenet/pod.go
+++ b/v2/pkg/nodenet/pod.go
@@ -424,7 +424,7 @@ func (pn *podNetwork) Update(podIPv4, podIPv6 net.IP, hook SetupHook) error {
        for _, c := range podConfigs {
                // When both c.IPvX and podIPvX are nil, net.IP.Equal() returns always true.
                // Avoiding comparing nil to nil, confirm c.IPvX is not nil.
-               if (c.IPv4 != nil && c.IPv4.Equal(podIPv4)) || (c.IPv6 != nil && c.IPv6.Equal(podIPv6)) {
+               if true {
                        netNsPath, err = getNetNsPath(c.HostVethName)
                        if err != nil {
                                return err

Signed-off-by: terasihma <[email protected]>
@terassyi terassyi requested review from yokaze and masa213f January 11, 2024 09:11
v2/Makefile Outdated Show resolved Hide resolved
Comment on lines 97 to 132
if isDualStack(&conf) {
if len(result.Interfaces) != 2 {
t.Error(`len(result.Interfaces) != 2`)
}
if !result.IPs[0].Address.IP.Equal(conf.IPv4) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv4)
}
if result.IPs[0].Address.IP.To4() == nil {
t.Error(`!result.IPs[0] version != "4"`)
}
if !result.IPs[1].Address.IP.Equal(conf.IPv6) {
t.Errorf(`!result.IPs[1].Address.IP.Equal("%s")`, conf.IPv6)
}
if result.IPs[1].Address.IP.To4() != nil {
t.Error(`!result.IPs[1] version != "6"`)
}
} else {
if len(result.Interfaces) != 2 {
t.Error(`len(result.Interfaces) != 2`)
}
if conf.IPv4 != nil {
if !result.IPs[0].Address.IP.Equal(conf.IPv4) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv4)
}
if result.IPs[0].Address.IP.To4() == nil {
t.Error(`!result.IPs[0] version != "4"`)
}
} else {
if !result.IPs[0].Address.IP.Equal(conf.IPv6) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv6)
}
if result.IPs[0].Address.IP.To4() != nil {
t.Error(`!result.IPs[1] version != "6"`)
}
}
}
Copy link
Contributor

@masa213f masa213f Jan 12, 2024

Choose a reason for hiding this comment

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

  1. Please check the length of result.IPs.

  2. Error messages are wrong, aren't they?

Suggested change
if isDualStack(&conf) {
if len(result.Interfaces) != 2 {
t.Error(`len(result.Interfaces) != 2`)
}
if !result.IPs[0].Address.IP.Equal(conf.IPv4) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv4)
}
if result.IPs[0].Address.IP.To4() == nil {
t.Error(`!result.IPs[0] version != "4"`)
}
if !result.IPs[1].Address.IP.Equal(conf.IPv6) {
t.Errorf(`!result.IPs[1].Address.IP.Equal("%s")`, conf.IPv6)
}
if result.IPs[1].Address.IP.To4() != nil {
t.Error(`!result.IPs[1] version != "6"`)
}
} else {
if len(result.Interfaces) != 2 {
t.Error(`len(result.Interfaces) != 2`)
}
if conf.IPv4 != nil {
if !result.IPs[0].Address.IP.Equal(conf.IPv4) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv4)
}
if result.IPs[0].Address.IP.To4() == nil {
t.Error(`!result.IPs[0] version != "4"`)
}
} else {
if !result.IPs[0].Address.IP.Equal(conf.IPv6) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv6)
}
if result.IPs[0].Address.IP.To4() != nil {
t.Error(`!result.IPs[1] version != "6"`)
}
}
}
if isDualStack(&conf) {
if len(result.Interfaces) != 2 {
t.Error(`len(result.Interfaces) != 2`)
}
if !result.IPs[0].Address.IP.Equal(conf.IPv4) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv4)
}
if result.IPs[0].Address.IP.To4() == nil {
t.Error(`result.IPs[0] version != "4"`)
}
if !result.IPs[1].Address.IP.Equal(conf.IPv6) {
t.Errorf(`!result.IPs[1].Address.IP.Equal("%s")`, conf.IPv6)
}
if result.IPs[1].Address.IP.To4() != nil {
t.Error(`result.IPs[1] version != "6"`)
}
} else {
if len(result.Interfaces) != 2 {
t.Error(`len(result.Interfaces) != 2`)
}
if conf.IPv4 != nil {
if !result.IPs[0].Address.IP.Equal(conf.IPv4) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv4)
}
if result.IPs[0].Address.IP.To4() == nil {
t.Error(`result.IPs[0] version != "4"`)
}
} else {
if !result.IPs[0].Address.IP.Equal(conf.IPv6) {
t.Errorf(`!result.IPs[0].Address.IP.Equal("%s")`, conf.IPv6)
}
if result.IPs[0].Address.IP.To4() != nil {
t.Error(`result.IPs[1] version != "6"`)
}
}
}

Comment on lines 412 to 418
if err == nil {
t.Fatal("pn.Check must return error because pod2 network doesn't exist")
} else {
if err != errNotFound {
t.Fatal("given error must be errNotFound")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think one if statement is enough.

Suggested change
if err == nil {
t.Fatal("pn.Check must return error because pod2 network doesn't exist")
} else {
if err != errNotFound {
t.Fatal("given error must be errNotFound")
}
}
if err != errNotFound {
t.Fatal("pn.Check must return errNotFound because pod2 network doesn't exist")
}

@terassyi terassyi requested a review from masa213f January 17, 2024 06:05
Copy link
Contributor

@masa213f masa213f left a comment

Choose a reason for hiding this comment

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

LGTM

@terassyi terassyi merged commit dd40b9f into main Jan 17, 2024
7 checks passed
@terassyi terassyi deleted the avoid-adding-fou-devices-for-pods-not-using-egress branch January 17, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants