Skip to content

Commit

Permalink
Pass native-routing-cidr to ENI CNI for route rules
Browse files Browse the repository at this point in the history
Signed-off-by: John Watson <johnw@planetscale.com>
  • Loading branch information
dctrwatson committed Apr 30, 2020
1 parent ebe156f commit 4b47aa7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/ipam/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ func (a *crdAllocator) buildAllocationResult(ip net.IP, ipInfo *ipamTypes.Alloca
result.Master = eni.MAC
result.CIDRs = []string{eni.VPC.PrimaryCIDR}
result.CIDRs = append(result.CIDRs, eni.VPC.CIDRs...)
// Add manually configured Native Routing CIDR
if a.conf.IPv4NativeRoutingCIDR() != nil {
result.CIDRs = append(result.CIDRs, a.conf.IPv4NativeRoutingCIDR().String())
}
if eni.Subnet.CIDR != "" {
result.GatewayIP = deriveGatewayIP(eni)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ type Configuration interface {
// SetIPv4NativeRoutingCIDR is called by the IPAM module to announce
// the native IPv4 routing CIDR if it exists
SetIPv4NativeRoutingCIDR(cidr *cidr.CIDR)

// IPv4NativeRoutingCIDR is called by the IPAM module retrieve
// the native IPv4 routing CIDR if it exists
IPv4NativeRoutingCIDR() *cidr.CIDR
}

// Owner is the interface the owner of an IPAM allocator has to implement
Expand Down
1 change: 1 addition & 0 deletions pkg/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (t *testConfiguration) HealthCheckingEnabled() bool { return t
func (t *testConfiguration) IPAMMode() string { return option.IPAMHostScopeLegacy }
func (t *testConfiguration) BlacklistConflictingRoutesEnabled() bool { return false }
func (t *testConfiguration) SetIPv4NativeRoutingCIDR(cidr *cidr.CIDR) {}
func (t *testConfiguration) IPv4NativeRoutingCIDR() *cidr.CIDR { return nil }

func (s *IPAMSuite) TestLock(c *C) {
fakeAddressing := fake.NewNodeAddressing()
Expand Down
10 changes: 8 additions & 2 deletions plugins/cilium-cni/eni.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ import (

"github.com/cilium/cilium/api/v1/models"
enirouting "github.com/cilium/cilium/pkg/aws/eni/routing"
"github.com/cilium/cilium/pkg/ip"
"github.com/cilium/cilium/pkg/mac"

"github.com/containernetworking/cni/pkg/types/current"
)

func eniAdd(ipConfig *current.IPConfig, ipam *models.IPAMAddressResponse, conf models.DaemonConfigurationStatus) error {
cidrs := make([]net.IPNet, 0, len(ipam.Cidrs))
allCIDRs := make([]*net.IPNet, 0, len(ipam.Cidrs))
for _, cidrString := range ipam.Cidrs {
_, cidr, err := net.ParseCIDR(cidrString)
if err != nil {
return fmt.Errorf("invalid CIDR '%s': %s", cidrString, err)
}

allCIDRs = append(allCIDRs, cidr)
}
// Coalesce CIDRs into minimum set needed for route rules
ipv4CIDRs, _ := ip.CoalesceCIDRs(allCIDRs)
cidrs := make([]net.IPNet, 0, len(ipv4CIDRs))
for _, cidr := range ipv4CIDRs {
cidrs = append(cidrs, *cidr)
}

Expand Down

0 comments on commit 4b47aa7

Please sign in to comment.