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

Fix deletion of hostVeth rule for pods using security group #1377

Merged
merged 1 commit into from
Feb 5, 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
16 changes: 15 additions & 1 deletion cmd/routed-eni-cni-plugin/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,28 @@ func (os *linuxNetwork) SetupPodENINetwork(hostVethName string, contVethName str
vlanTableID := vlanID + 100
vlanLink := buildVlanLink(vlanID, parentIfIndex, eniMAC)

// 1. clean up if vlan already exists (necessary when trunk ENI changes).
// 1a. clean up if vlan already exists (necessary when trunk ENI changes).
if oldVlan, err := os.netLink.LinkByName(vlanLink.Name); err == nil {
if err = os.netLink.LinkDel(oldVlan); err != nil {
return errors.Wrapf(err, "SetupPodENINetwork: failed to delete old vlan %s", vlanLink.Name)
}
log.Debugf("Cleaned up old vlan: %s", vlanLink.Name)
}

// 1b. clean up any previous hostVeth ip rule
oldVlanRule := os.netLink.NewRule()
oldVlanRule.IifName = hostVethName
oldVlanRule.Priority = vlanRulePriority
// loop is required to clean up all existing rules created on the host (when pod with same name are recreated multiple times)
for {
if err := os.netLink.RuleDel(oldVlanRule); err != nil {
if !containsNoSuchRule(err) {
return errors.Wrapf(err, "SetupPodENINetwork: failed to delete hostveth rule for %s", hostVeth.Attrs().Name)
}
break
}
}

// 2. add new vlan link
err = os.netLink.LinkAdd(vlanLink)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cmd/routed-eni-cni-plugin/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,15 @@ func (m *testMocks) mockSetupPodENINetworkWithFailureAt(t *testing.T, addr *net.
m.netlink.EXPECT().LinkByName(testVlanName).Return(nil,
errors.New("link not found"))

actualRule := &netlink.Rule{}
m.netlink.EXPECT().NewRule().Return(actualRule)

oldVethRule := &netlink.Rule{
IifName: testHostVethName,
Priority: vlanRulePriority,
}
m.netlink.EXPECT().RuleDel(gomock.Eq(oldVethRule)).Return(syscall.ENOENT)

vlanLink := buildVlanLink(1, 2, "eniMacAddress")
// add the link
m.netlink.EXPECT().LinkAdd(gomock.Eq(vlanLink)).Return(nil)
Expand Down Expand Up @@ -544,7 +553,6 @@ func (m *testMocks) mockSetupPodENINetworkWithFailureAt(t *testing.T, addr *net.
}
m.netlink.EXPECT().RouteReplace(gomock.Eq(&route)).Return(nil)

actualRule := &netlink.Rule{}
m.netlink.EXPECT().NewRule().Return(actualRule)

// add two ip rules based on iff interfaces
Expand Down