Skip to content

Commit 8915697

Browse files
committed
fix veth move validation logic
1 parent b3b4b47 commit 8915697

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

network/transparent_vlan_endpointclient_linux.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ func (client *TransparentVlanEndpointClient) createNetworkNamespace(vmNS int) er
183183
return errors.Wrap(errNamespaceCreation, "vnet and vm namespace are the same")
184184
}
185185

186-
// Called from PopulateVM, Namespace: VM and namespace represented by fd
187-
func (client *TransparentVlanEndpointClient) setLinkNetNSAndConfirm(name string, fd uintptr) error {
186+
// Called from PopulateVM, Namespace: VM and namespace represented by fd (which is named nsName)
187+
func (client *TransparentVlanEndpointClient) setLinkNetNSAndConfirm(name string, fd uintptr, nsName string) error {
188188
logger.Info("Move link to NS", zap.String("ifName", name), zap.Any("NSFileDescriptor", fd))
189189
err := client.netlink.SetLinkNetNs(name, fd)
190190
if err != nil {
@@ -194,9 +194,9 @@ func (client *TransparentVlanEndpointClient) setLinkNetNSAndConfirm(name string,
194194
// confirm veth was moved successfully
195195
err = RunWithRetries(func() error {
196196
// retry checking in the namespace if the interface is not detected
197-
return ExecuteInNS(client.nsClient, client.vnetNSName, func() error {
198-
_, ifDetectedErr := client.netioshim.GetNetworkInterfaceByName(client.vlanIfName)
199-
return errors.Wrap(ifDetectedErr, "failed to get vlan veth in namespace")
197+
return ExecuteInNS(client.nsClient, nsName, func() error {
198+
_, ifDetectedErr := client.netioshim.GetNetworkInterfaceByName(name)
199+
return errors.Wrap(ifDetectedErr, "failed to confirm veth moved in namespace")
200200
})
201201
}, numRetries, sleepInMs)
202202
if err != nil {
@@ -295,7 +295,7 @@ func (client *TransparentVlanEndpointClient) PopulateVM(epInfo *EndpointInfo) er
295295
}
296296
// vlan veth was created successfully, so move the vlan veth you created
297297
logger.Info("Move vlan link to vnet NS", zap.String("vlanIfName", client.vlanIfName), zap.Any("vnetNSFileDescriptor", uintptr(client.vnetNSFileDescriptor)))
298-
deleteNSIfNotNilErr = client.setLinkNetNSAndConfirm(client.vlanIfName, uintptr(client.vnetNSFileDescriptor))
298+
deleteNSIfNotNilErr = client.setLinkNetNSAndConfirm(client.vlanIfName, uintptr(client.vnetNSFileDescriptor), client.vnetNSName)
299299
if deleteNSIfNotNilErr != nil {
300300
return errors.Wrap(deleteNSIfNotNilErr, "failed to move or detect vlan veth inside vnet namespace")
301301
}
@@ -359,7 +359,7 @@ func (client *TransparentVlanEndpointClient) PopulateVM(epInfo *EndpointInfo) er
359359
return errors.Wrap(err, "failed to disable RA on container veth, deleting")
360360
}
361361

362-
if err = client.setLinkNetNSAndConfirm(client.vnetVethName, uintptr(client.vnetNSFileDescriptor)); err != nil {
362+
if err = client.setLinkNetNSAndConfirm(client.vnetVethName, uintptr(client.vnetNSFileDescriptor), client.vnetNSName); err != nil {
363363
if delErr := client.netlink.DeleteLink(client.vnetVethName); delErr != nil {
364364
logger.Error("Deleting vnet veth failed on addendpoint failure with", zap.Error(delErr))
365365
}

network/transparent_vlan_endpointclient_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func TestTransparentVlanAddEndpoints(t *testing.T) {
189189
for _, tt := range tests {
190190
tt := tt
191191
t.Run(tt.name, func(t *testing.T) {
192-
err := tt.client.setLinkNetNSAndConfirm(tt.client.vlanIfName, 1)
192+
err := tt.client.setLinkNetNSAndConfirm(tt.client.vlanIfName, 1, tt.client.vnetNSName)
193193
if tt.wantErr {
194194
require.Error(t, err)
195195
require.Contains(t, err.Error(), tt.wantErrMsg, "Expected:%v actual:%v", tt.wantErrMsg, err.Error())

0 commit comments

Comments
 (0)