-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[v3.31] Fix rendering of NatPortRange in nftables mode #11741
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,3 +109,74 @@ var _ = infrastructure.DatastoreDescribe("NATOutgoing rule rendering test", []ap | |
| } | ||
| }) | ||
| }) | ||
|
|
||
| var _ = infrastructure.DatastoreDescribe("NATPortRange rendering test", []apiconfig.DatastoreType{apiconfig.EtcdV3, apiconfig.Kubernetes}, func(getInfra infrastructure.InfraFactory) { | ||
| var ( | ||
| infra infrastructure.DatastoreInfra | ||
| tc infrastructure.TopologyContainers | ||
| client client.Interface | ||
| dumpedDiags bool | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| var err error | ||
| infra = getInfra() | ||
|
|
||
| dumpedDiags = false | ||
| opts := infrastructure.DefaultTopologyOptions() | ||
| opts.IPIPMode = api.IPIPModeNever | ||
| opts.EnableIPv6 = true | ||
|
|
||
| opts.ExtraEnvVars = map[string]string{ | ||
| "FELIX_NATPortRange": "32768:65535", | ||
| } | ||
| tc, client = infrastructure.StartSingleNodeTopology(opts, infra) | ||
|
|
||
| ctx := context.Background() | ||
| ippool := api.NewIPPool() | ||
| ippool.Name = "nat-pool" | ||
| ippool.Spec.CIDR = "10.244.255.0/24" | ||
| ippool.Spec.NATOutgoing = true | ||
| ippool, err = client.IPPools().Create(ctx, ippool, options.SetOptions{}) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
|
|
||
| // Utility function to dump diags if the test failed. Should be called in the inner-most | ||
| // AfterEach() to dump diags before the test is torn down. Only the first call for a given | ||
| // test has any effect. | ||
| dumpDiags := func() { | ||
| if !CurrentGinkgoTestDescription().Failed || dumpedDiags { | ||
| return | ||
| } | ||
| if NFTMode() { | ||
| logNFTDiags(tc.Felixes[0]) | ||
| } else { | ||
| iptSave, err := tc.Felixes[0].ExecOutput("iptables-save", "-c") | ||
| if err == nil { | ||
| log.Info("iptables-save:\n" + iptSave) | ||
| } | ||
| } | ||
| dumpedDiags = true | ||
| infra.DumpErrorData() | ||
| } | ||
|
|
||
| AfterEach(func() { | ||
| dumpDiags() | ||
| tc.Stop() | ||
| infra.Stop() | ||
| }) | ||
|
|
||
| It("should have expected rendering", func() { | ||
| if NFTMode() { | ||
| Eventually(func() string { | ||
| output, _ := tc.Felixes[0].ExecOutput("nft", "list", "chain", "ip", "calico", "nat-cali-nat-outgoing") | ||
| return output | ||
| }, 5*time.Second, 100*time.Millisecond).Should(ContainSubstring("32768-65535")) | ||
|
Comment on lines
+170
to
+174
|
||
| } else { | ||
| Eventually(func() string { | ||
| output, _ := tc.Felixes[0].ExecOutput("iptables-save", "-t", "nat") | ||
| return output | ||
| }, 5*time.Second, 100*time.Millisecond).Should(ContainSubstring("32768-65535")) | ||
| } | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,9 @@ var _ = DescribeTable("Actions", | |
| Entry("SNATAction", environment.Features{}, SNATAction{ToAddr: "10.0.0.1"}, "--jump SNAT --to-source 10.0.0.1"), | ||
| Entry("SNATAction fully random", environment.Features{SNATFullyRandom: true}, SNATAction{ToAddr: "10.0.0.1"}, "--jump SNAT --to-source 10.0.0.1 --random-fully"), | ||
| Entry("MasqAction", environment.Features{}, MasqAction{}, "--jump MASQUERADE"), | ||
| Entry("MasqAction", environment.Features{}, MasqAction{ToPorts: "32768-65535"}, "--jump MASQUERADE --to-ports 32768-65535"), | ||
| Entry("MasqAction", environment.Features{MASQFullyRandom: true}, MasqAction{}, "--jump MASQUERADE --random-fully"), | ||
| Entry("MasqAction", environment.Features{MASQFullyRandom: true}, MasqAction{ToPorts: "32768-65535"}, "--jump MASQUERADE --to-ports 32768-65535 --random-fully"), | ||
|
Comment on lines
39
to
+42
|
||
| Entry("ClearMarkAction", environment.Features{}, ClearMarkAction{Mark: 0x1000}, "--jump MARK --set-mark 0/0x1000"), | ||
| Entry("SetMarkAction", environment.Features{}, SetMarkAction{Mark: 0x1000}, "--jump MARK --set-mark 0x1000/0x1000"), | ||
| Entry("SetMaskedMarkAction", environment.Features{}, SetMaskedMarkAction{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,7 +37,9 @@ var _ = DescribeTable("Actions", | |||||||||||||
| Entry("SNATAction", environment.Features{}, SNATAction{ToAddr: "10.0.0.1"}, "snat to 10.0.0.1"), | ||||||||||||||
| Entry("SNATAction fully random", environment.Features{SNATFullyRandom: true}, SNATAction{ToAddr: "10.0.0.1"}, "snat to 10.0.0.1 fully-random"), | ||||||||||||||
| Entry("MasqAction", environment.Features{}, MasqAction{}, "masquerade"), | ||||||||||||||
| Entry("MasqAction", environment.Features{}, MasqAction{ToPorts: "32768-65535"}, "masquerade to :32768-65535"), | ||||||||||||||
| Entry("MasqAction", environment.Features{MASQFullyRandom: true}, MasqAction{}, "masquerade fully-random"), | ||||||||||||||
| Entry("MasqAction", environment.Features{MASQFullyRandom: true}, MasqAction{ToPorts: "32768-65535"}, "masquerade to :32768-65535 fully-random"), | ||||||||||||||
|
Comment on lines
+40
to
+42
|
||||||||||||||
| Entry("MasqAction", environment.Features{}, MasqAction{ToPorts: "32768-65535"}, "masquerade to :32768-65535"), | |
| Entry("MasqAction", environment.Features{MASQFullyRandom: true}, MasqAction{}, "masquerade fully-random"), | |
| Entry("MasqAction", environment.Features{MASQFullyRandom: true}, MasqAction{ToPorts: "32768-65535"}, "masquerade to :32768-65535 fully-random"), | |
| Entry("MasqAction with ports", environment.Features{}, MasqAction{ToPorts: "32768-65535"}, "masquerade to :32768-65535"), | |
| Entry("MasqAction fully random", environment.Features{MASQFullyRandom: true}, MasqAction{}, "masquerade fully-random"), | |
| Entry("MasqAction fully random with ports", environment.Features{MASQFullyRandom: true}, MasqAction{ToPorts: "32768-65535"}, "masquerade to :32768-65535 fully-random"), |
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.
Correct but it seems conventional in this file.
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 new FV test starts topology containers (
StartSingleNodeTopology) and a datastore infra but never stops them. Please add anAfterEach(like the earlier NATOutgoing test in this file) to calltc.Stop()andinfra.Stop()so the test suite doesn't leak containers/resources and become flaky.