-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hotunplug, unpluggedPodNic: implemet reverse phase1
The commit includes removal of bridge, tap and dummy nic if they exist. Follow up commits will take care of the caches files deletion. Notice: 1. The cleanup is general and not binding specific. Any link created by whatecer binding should be removed (although we curretnly support only bridge binding hotunplug). 2. Error removing one of the links doesn't block removal on the others. Signed-off-by: Alona Paz <alkaplan@redhat.com>
- Loading branch information
1 parent
9029ecb
commit 7327506
Showing
4 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package network | ||
|
||
import ( | ||
"errors" | ||
"github.com/vishvananda/netlink" | ||
k8serrors "k8s.io/apimachinery/pkg/util/errors" | ||
netdriver "kubevirt.io/kubevirt/pkg/network/driver" | ||
virtnetlink "kubevirt.io/kubevirt/pkg/network/link" | ||
) | ||
|
||
type unpluggedpodnic struct { | ||
podInterfaceName string | ||
handler netdriver.NetworkHandler | ||
} | ||
|
||
func (c unpluggedpodnic) UnplugPhase1() error { | ||
var unplugErrors []error | ||
|
||
bridgeName := generateInPodBridgeInterfaceName(c.podInterfaceName) | ||
err := c.delLinkIfExists(bridgeName) | ||
if err != nil { | ||
unplugErrors = append(unplugErrors, err) | ||
} | ||
|
||
// remove extra nic | ||
dummyIfaceName := virtnetlink.GenerateNewBridgedVmiInterfaceName(c.podInterfaceName) | ||
err = c.delLinkIfExists(dummyIfaceName) | ||
if err != nil { | ||
unplugErrors = append(unplugErrors, err) | ||
} | ||
|
||
// remove tap if exists | ||
tapDeviceName := virtnetlink.GenerateTapDeviceName(c.podInterfaceName) | ||
err = c.delLinkIfExists(tapDeviceName) | ||
if err != nil { | ||
unplugErrors = append(unplugErrors, err) | ||
} | ||
|
||
// clean caches | ||
// TODO remove all three cache files | ||
|
||
return k8serrors.NewAggregate(unplugErrors) | ||
|
||
} | ||
|
||
func (c unpluggedpodnic) delLinkIfExists(linkName string) error { | ||
link, err := c.handler.LinkByName(linkName) | ||
if err != nil { | ||
var linkNotFoundErr netlink.LinkNotFoundError | ||
if !errors.As(err, linkNotFoundErr) { | ||
return err | ||
} | ||
} | ||
return c.handler.LinkDel(link) | ||
} |