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

Use symmetric return path for non-VPC traffic - alternate solution #1475

Merged
merged 6 commits into from
Jun 2, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Type: String

Default: `eni`

Specifies the veth prefix used to generate the host-side veth device name for the CNI. The prefix can be at most 4 characters long.
Specifies the veth prefix used to generate the host-side veth device name for the CNI. The prefix can be at most 4 characters long. The prefixes `eth`, `vlan` and `lo` are reserved by the CNI plugin and cannot be specified. We recommend using prefix name not shared by any other network interfaces on the worker node instance.

---

Expand Down
39 changes: 6 additions & 33 deletions cmd/routed-eni-cni-plugin/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,40 +217,13 @@ func setupNS(hostVethName string, contVethName string, netnsPath string, addr *n
if deviceNumber > 0 {
// To be backwards compatible, we will have to keep this off-by one setting
tableNumber := deviceNumber + 1
if useExternalSNAT {
// add rule: 1536: from <podIP> use table <table>
err = addContainerRule(netLink, false, addr, tableNumber)
if err != nil {
log.Errorf("Failed to add fromContainer rule for %s err: %v", addr.String(), err)
return errors.Wrap(err, "add NS network: failed to add fromContainer rule")
}
log.Infof("Added rule priority %d from %s table %d", fromContainerRulePriority, addr.String(), tableNumber)
} else {
// add rule: 1536: list of from <podIP> to <vpcCIDR> use table <table>
for _, cidr := range vpcCIDRs {
podRule := netLink.NewRule()
_, podRule.Dst, _ = net.ParseCIDR(cidr)
podRule.Src = addr
podRule.Table = tableNumber
podRule.Priority = fromContainerRulePriority

err = netLink.RuleAdd(podRule)
if isRuleExistsError(err) {
log.Warnf("Rule already exists [%v]", podRule)
} else {
if err != nil {
log.Errorf("Failed to add pod IP rule [%v]: %v", podRule, err)
return errors.Wrapf(err, "setupNS: failed to add pod rule [%v]", podRule)
}
}
var toDst string

if podRule.Dst != nil {
toDst = podRule.Dst.String()
}
log.Infof("Successfully added pod rule[%v] to %s", podRule, toDst)
}
// add rule: 1536: from <podIP> use table <table>
err = addContainerRule(netLink, false, addr, tableNumber)
if err != nil {
log.Errorf("Failed to add fromContainer rule for %s err: %v", addr.String(), err)
return errors.Wrap(err, "add NS network: failed to add fromContainer rule")
}
log.Infof("Added rule priority %d from %s table %d", fromContainerRulePriority, addr.String(), tableNumber)
}
return nil
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (c *IPAMContext) nodeInit() error {
return err
}

if err = c.configureIPRulesForPods(vpcCIDRs); err != nil {
if err = c.configureIPRulesForPods(); err != nil {
return err
}
// Spawning updateCIDRsRulesOnChange go-routine
Expand Down Expand Up @@ -458,7 +458,7 @@ func (c *IPAMContext) nodeInit() error {
return nil
}

func (c *IPAMContext) configureIPRulesForPods(pbVPCcidrs []string) error {
func (c *IPAMContext) configureIPRulesForPods() error {
rules, err := c.networkClient.GetRuleList()
if err != nil {
log.Errorf("During ipamd init: failed to retrieve IP rule list %v", err)
Expand All @@ -471,7 +471,7 @@ func (c *IPAMContext) configureIPRulesForPods(pbVPCcidrs []string) error {
// Update ip rules in case there is a change in VPC CIDRs, AWS_VPC_K8S_CNI_EXTERNALSNAT setting
srcIPNet := net.IPNet{IP: net.ParseIP(info.IP), Mask: net.IPv4Mask(255, 255, 255, 255)}

err = c.networkClient.UpdateRuleListBySrc(rules, srcIPNet, pbVPCcidrs, !c.networkClient.UseExternalSNAT())
err = c.networkClient.UpdateRuleListBySrc(rules, srcIPNet)
if err != nil {
log.Warnf("UpdateRuleListBySrc in nodeInit() failed for IP %s: %v", info.IP, err)
}
Expand All @@ -489,7 +489,11 @@ func (c *IPAMContext) updateCIDRsRulesOnChange(oldVPCCIDRs []string) []string {
old := sets.NewString(oldVPCCIDRs...)
new := sets.NewString(newVPCCIDRs...)
if !old.Equal(new) {
_ = c.configureIPRulesForPods(newVPCCIDRs)
primaryIP := c.awsClient.GetLocalIPv4()
err = c.networkClient.UpdateHostIptablesRules(newVPCCIDRs, c.awsClient.GetPrimaryENImac(), &primaryIP)
if err != nil {
log.Warnf("unable to update host iptables rules for VPC CIDRs due to error: %v", err)
}
}
return newVPCCIDRs
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/ipamd/ipamd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ func TestNodeInit(t *testing.T) {
var rules []netlink.Rule
m.network.EXPECT().GetRuleList().Return(rules, nil)

m.network.EXPECT().UseExternalSNAT().Return(false)
m.network.EXPECT().UpdateRuleListBySrc(gomock.Any(), gomock.Any(), gomock.Any(), true)
m.network.EXPECT().UpdateRuleListBySrc(gomock.Any(), gomock.Any())

fakeNode := v1.Node{
TypeMeta: metav1.TypeMeta{Kind: "Node"},
Expand Down
22 changes: 18 additions & 4 deletions pkg/networkutils/mocks/network_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading