Skip to content

Commit 28b53fb

Browse files
authored
Make source network address translation configurable in IPv6 scenario. (#585)
Previously, source network address translation (SNAT) was always disabled via the `IPPool` configuration in the IPv6 scenario. This should be a sensible default for scenarios when globally routable IPv6 address space is used. However, if unique local addresses (ULA) are used it might be useful to still perform source network address translation on the node level. This change exposes an option so that SNAT can be enabled for IPv6.
1 parent 3f3e5ac commit 28b53fb

File tree

10 files changed

+42
-7
lines changed

10 files changed

+42
-7
lines changed

charts/internal/calico/templates/ippool/ippool.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
blockSize: 122
6464
cidr: "{{ .Values.global.podCIDR }}"
6565
ipipMode: Never
66-
natOutgoing: false
66+
natOutgoing: {{ if .Values.config.ipv6.natOutgoing }}true{{ else }}false{{ end }}
6767
nodeSelector: all()
6868
vxlanMode: Never
69-
{{- end -}}
69+
{{- end -}}

charts/internal/calico/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ config:
3131
pool: vxlan
3232
mode: "Never"
3333
autoDetectionMethod: "first-found"
34-
natOutgoing: true
34+
natOutgoing: false
3535
wireguard: false
3636
felix:
3737
ipinip:

hack/api-reference/calico.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,19 @@ string
513513
<a href="https://docs.projectcalico.org/v3.8/reference/node/configuration#ip-autodetection-methods">https://docs.projectcalico.org/v3.8/reference/node/configuration#ip-autodetection-methods</a></p>
514514
</td>
515515
</tr>
516+
<tr>
517+
<td>
518+
<code>sourceNATEnabled</code></br>
519+
<em>
520+
bool
521+
</em>
522+
</td>
523+
<td>
524+
<em>(Optional)</em>
525+
<p>SourceNATEnabled indicates whether the pod IP addresses should be masqueraded when targeting external destinations.
526+
Per default, source network address translation is disabled.</p>
527+
</td>
528+
</tr>
516529
</tbody>
517530
</table>
518531
<h3 id="calico.networking.extensions.gardener.cloud/v1alpha1.NetworkStatus">NetworkStatus

pkg/apis/calico/types_network.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type IPv6 struct {
6262
// AutoDetectionMethod is the method to use to autodetect the IPv6 address for this host. This is only used when the IPv6 address is being autodetected.
6363
// https://docs.projectcalico.org/v3.8/reference/node/configuration#ip-autodetection-methods
6464
AutoDetectionMethod *string
65+
// SourceNATEnabled indicates whether the pod IP addresses should be masqueraded when targeting external destinations.
66+
// Per default, source network address translation is disabled.
67+
SourceNATEnabled *bool
6568
}
6669

6770
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/apis/calico/v1alpha1/types_network.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ type IPv6 struct {
6969
// https://docs.projectcalico.org/v3.8/reference/node/configuration#ip-autodetection-methods
7070
// +optional
7171
AutoDetectionMethod *string `json:"autoDetectionMethod,omitempty"`
72+
// SourceNATEnabled indicates whether the pod IP addresses should be masqueraded when targeting external destinations.
73+
// Per default, source network address translation is disabled.
74+
// +optional
75+
SourceNATEnabled *bool `json:"sourceNATEnabled,omitempty"`
7276
}
7377

7478
// +genclient

pkg/apis/calico/v1alpha1/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/calico/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/calico/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/charts/charts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ var _ = Describe("Chart package test", func() {
481481
"pool": "vxlan",
482482
"mode": "Never",
483483
"autoDetectionMethod": nil,
484-
"natOutgoing": true,
484+
"natOutgoing": false,
485485
"wireguard": false,
486486
})),
487487
))
@@ -519,7 +519,7 @@ var _ = Describe("Chart package test", func() {
519519
"pool": "vxlan",
520520
"mode": "CrossSubnet",
521521
"autoDetectionMethod": "first-found",
522-
"natOutgoing": true,
522+
"natOutgoing": false,
523523
"wireguard": false,
524524
})),
525525
))
@@ -563,7 +563,7 @@ var _ = Describe("Chart package test", func() {
563563
"pool": "vxlan",
564564
"mode": "Never",
565565
"autoDetectionMethod": nil,
566-
"natOutgoing": true,
566+
"natOutgoing": false,
567567
"wireguard": false,
568568
})),
569569
))

pkg/charts/utils.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func generateChartValues(network *extensionsv1alpha1.Network, config *calicov1al
255255
Pool: calicov1alpha1.PoolVXLan,
256256
Mode: calicov1alpha1.Never,
257257
AutoDetectionMethod: nil,
258-
NATOutgoing: true,
258+
NATOutgoing: false,
259259
}
260260
c.Felix.IPInIP.Enabled = false
261261
}
@@ -392,6 +392,9 @@ func mergeCalicoValuesWithConfig(c *calicoConfig, config *calicov1alpha1.Network
392392
if config.IPv6.AutoDetectionMethod != nil {
393393
c.IPv6.AutoDetectionMethod = config.IPv6.AutoDetectionMethod
394394
}
395+
if config.IPv6.SourceNATEnabled != nil {
396+
c.IPv6.NATOutgoing = *config.IPv6.SourceNATEnabled
397+
}
395398
}
396399

397400
if config.Typha != nil {

0 commit comments

Comments
 (0)