Skip to content

Commit

Permalink
daemon: Do not require native routing CIDR if ipmasq-agent is enabled
Browse files Browse the repository at this point in the history
Cilium's built-in [ipmasq-agent replacement](https://docs.cilium.io/en/v1.14/network/concepts/masquerading/#ebpf-based)
acts as a replacement for the native routing CIDR. Therefore, it does
not make sense to require the native routing CIDR if the ipmasq-agent is
enabled, since the two flags are basically mutually exclusive. The
previous commit already prepared the implementation to not set the
IPV4_SNAT_EXCLUSION_DST_CIDR in the datapath if the native routing CIDR
is absent.

In addition, this commit also slightly restructures and aligns the if
condition with the error message, to make it a bit easier to read.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
  • Loading branch information
gandro authored and christarazi committed Aug 29, 2023
1 parent 8abc0c2 commit 98964b1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
57 changes: 40 additions & 17 deletions pkg/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3784,29 +3784,52 @@ func (c *DaemonConfig) checkMapSizeLimits() error {
}

func (c *DaemonConfig) checkIPv4NativeRoutingCIDR() error {
if c.GetIPv4NativeRoutingCIDR() == nil && c.EnableIPv4Masquerade && !c.TunnelingEnabled() &&
c.IPAMMode() != ipamOption.IPAMENI && c.EnableIPv4 && c.IPAMMode() != ipamOption.IPAMAlibabaCloud {
return fmt.Errorf(
"native routing cidr must be configured with option --%s "+
"in combination with --%s --%s=%s --%s=%s --%s=true",
IPv4NativeRoutingCIDR, EnableIPv4Masquerade, RoutingMode, RoutingModeNative,
IPAM, c.IPAMMode(), EnableIPv4Name)
if c.GetIPv4NativeRoutingCIDR() != nil {
return nil
}
if !c.EnableIPv4 || !c.EnableIPv4Masquerade {
return nil
}
if c.EnableIPMasqAgent {
return nil
}
if c.TunnelingEnabled() {
return nil
}
if c.IPAMMode() == ipamOption.IPAMENI || c.IPAMMode() == ipamOption.IPAMAlibabaCloud {
return nil
}

return nil
return fmt.Errorf(
"native routing cidr must be configured with option --%s "+
"in combination with --%s=true --%s=true --%s=false --%s=%s --%s=%s",
IPv4NativeRoutingCIDR,
EnableIPv4Name, EnableIPv4Masquerade,
EnableIPMasqAgent,
RoutingMode, RoutingModeNative,
IPAM, c.IPAMMode())
}

func (c *DaemonConfig) checkIPv6NativeRoutingCIDR() error {
if c.GetIPv6NativeRoutingCIDR() == nil && c.EnableIPv6Masquerade && !c.TunnelingEnabled() &&
c.EnableIPv6 {
return fmt.Errorf(
"native routing cidr must be configured with option --%s "+
"in combination with --%s --%s=%s --%s=true",
IPv6NativeRoutingCIDR, EnableIPv6Masquerade, RoutingMode, RoutingModeNative,
EnableIPv6Name)
if c.GetIPv6NativeRoutingCIDR() != nil {
return nil
}

return nil
if !c.EnableIPv6 || !c.EnableIPv6Masquerade {
return nil
}
if c.EnableIPMasqAgent {
return nil
}
if c.TunnelingEnabled() {
return nil
}
return fmt.Errorf(
"native routing cidr must be configured with option --%s "+
"in combination with --%s=true --%s=true --%s=false --%s=%s",
IPv6NativeRoutingCIDR,
EnableIPv6Name, EnableIPv6Masquerade,
EnableIPMasqAgent,
RoutingMode, RoutingModeNative)
}

func (c *DaemonConfig) checkIPAMDelegatedPlugin() error {
Expand Down
23 changes: 23 additions & 0 deletions pkg/option/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,18 @@ func TestCheckIPv4NativeRoutingCIDR(t *testing.T) {
},
wantErr: true,
},
{
name: "without native routing cidr and tunnel disabled, but ipmasq-agent",
d: &DaemonConfig{
EnableIPv4Masquerade: true,
EnableIPv6Masquerade: true,
RoutingMode: RoutingModeNative,
IPAM: ipamOption.IPAMKubernetes,
EnableIPv4: true,
EnableIPMasqAgent: true,
},
wantErr: false,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -633,6 +645,17 @@ func TestCheckIPv6NativeRoutingCIDR(t *testing.T) {
},
wantErr: true,
},
{
name: "without native routing cidr and tunnel disabled, but ipmasq-agent",
d: &DaemonConfig{
EnableIPv4Masquerade: true,
EnableIPv6Masquerade: true,
RoutingMode: RoutingModeNative,
EnableIPv6: true,
EnableIPMasqAgent: true,
},
wantErr: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 98964b1

Please sign in to comment.