@@ -2015,20 +2015,41 @@ func (c *Controller) createVlanSubinterfaces(vlanInterfaces []string, baseInterf
20152015 return nil
20162016}
20172017
2018- func (c * Controller ) cleanupAutoCreatedVlanInterfaces (providerName string ) error {
2019- createdInterfaces , err := util .FindKubeOVNAutoCreatedInterfaces (providerName )
2018+ func (c * Controller ) cleanupAutoCreatedVlanInterfaces (providerName , nic string , preservedIfaces map [ string ] int ) error {
2019+ gcVlanIfaces , err := util .FindKubeOVNAutoCreatedInterfaces (providerName )
20202020 if err != nil {
20212021 return fmt .Errorf ("failed to find auto-created interfaces for provider %s: %w" , providerName , err )
20222022 }
20232023
2024- if len (createdInterfaces ) == 0 {
2024+ inUseVlanIface := ""
2025+ if strings .Contains (nic , "." ) {
2026+ inUseVlanIface = nic
2027+ }
2028+
2029+ filteredIfaces := make ([]string , 0 , len (gcVlanIfaces ))
2030+ for _ , iface := range gcVlanIfaces {
2031+ if iface == inUseVlanIface {
2032+ continue
2033+ }
2034+ if preservedIfaces != nil {
2035+ if _ , skip := preservedIfaces [iface ]; skip {
2036+ continue
2037+ }
2038+ }
2039+ if iface == "" {
2040+ continue
2041+ }
2042+ filteredIfaces = append (filteredIfaces , iface )
2043+ }
2044+ gcVlanIfaces = filteredIfaces
2045+ if len (gcVlanIfaces ) == 0 {
20252046 klog .V (3 ).Infof ("No auto-created VLAN interfaces found for provider %s" , providerName )
20262047 return nil
20272048 }
20282049
2029- klog .Infof ("Found %d auto-created VLAN interfaces to clean up for provider %s: %v" , len (createdInterfaces ), providerName , createdInterfaces )
2050+ klog .Infof ("Cleaning %d auto-created VLAN interfaces for provider %s: %v" , len (gcVlanIfaces ), providerName , gcVlanIfaces )
20302051
2031- for _ , ifaceName := range createdInterfaces {
2052+ for _ , ifaceName := range gcVlanIfaces {
20322053 klog .Infof ("Cleaning up auto-created VLAN interface %s" , ifaceName )
20332054 output , err := exec .Command ("ip" , "link" , "delete" , ifaceName ).CombinedOutput ()
20342055 if err != nil {
0 commit comments