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

Pass native-routing-cidr to ENI CNI for route rules #10887

Merged
merged 1 commit into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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