@@ -228,70 +228,45 @@ func ClearPodBandwidth(podName, podNamespace, ifaceID string) error {
228228 return nil
229229}
230230
231- var lastInterfacePodMap map [string ]string
232-
233- func ListInterfacePodMap () (map [string ]string , error ) {
234- output , err := Exec ("--data=bare" , "--format=csv" , "--no-heading" , "--columns=name,external_ids,error" , "find" ,
235- "interface" , "external_ids:pod_name!=[]" , "external_ids:pod_namespace!=[]" )
231+ // CleanLostInterface will clean up related ovs port, interface and qos
232+ // When reboot node, the ovs internal interface will be deleted.
233+ func CleanLostInterface () {
234+ interfaceList , err := ovsFind ("interface" , "name,error" , "ofport=-1" , "external_ids:pod_netns!=[]" )
236235 if err != nil {
237- klog .Errorf ("failed to list interface, %v" , err )
238- return nil , err
239- }
240- lines := strings .Split (output , "\n " )
241- result := make (map [string ]string , len (lines ))
242- for _ , l := range lines {
243- if len (strings .TrimSpace (l )) == 0 {
244- continue
245- }
246- parts := strings .Split (strings .TrimSpace (l ), "," )
247- if len (parts ) != 3 {
248- continue
249- }
250- ifaceName := strings .TrimSpace (parts [0 ])
251- errText := strings .TrimSpace (parts [2 ])
252- var podNamespace , podName string
253- for externalID := range strings .FieldsSeq (parts [1 ]) {
254- if strings .Contains (externalID , "pod_name=" ) {
255- podName = strings .TrimPrefix (strings .TrimSpace (externalID ), "pod_name=" )
256- }
257-
258- if strings .Contains (externalID , "pod_namespace=" ) {
259- podNamespace = strings .TrimPrefix (strings .TrimSpace (externalID ), "pod_namespace=" )
260- }
261- }
262- result [ifaceName ] = fmt .Sprintf ("%s/%s/%s" , podNamespace , podName , errText )
236+ klog .Errorf ("failed to list failed interface %v" , err )
237+ return
263238 }
264- if ! maps .Equal (result , lastInterfacePodMap ) {
265- klog .Infof ("interface pod map: %v" , result )
266- lastInterfacePodMap = maps .Clone (result )
239+ if len (interfaceList ) > 0 {
240+ klog .Infof ("error interfaces:\n %v" , interfaceList )
267241 }
268- return result , nil
269- }
270242
271- func CleanInterface (name string ) error {
272- qosList , err := ovsFind ("port" , "qos" , "name=" + name )
273- if err != nil {
274- klog .Errorf ("failed to find related port %v" , err )
275- return err
276- }
277- klog .Infof ("delete lost port %s" , name )
278- output , err := Exec ("--if-exists" , "--with-iface" , "del-port" , name )
279- if err != nil {
280- klog .Errorf ("failed to delete ovs port %v, %s" , err , output )
281- return err
282- }
283- for _ , qos := range qosList {
284- qos = strings .TrimSpace (qos )
285- if qos != "" && qos != "[]" {
286- klog .Infof ("delete lost qos %s" , qos )
287- err = ovsDestroy ("qos" , qos )
243+ for _ , intf := range interfaceList {
244+ name , errText := strings .Trim (strings .Split (intf , "\n " )[0 ], "\" " ), strings .Split (intf , "\n " )[1 ]
245+ if strings .Contains (errText , "No such device" ) {
246+ qosList , err := ovsFind ("port" , "qos" , "name=" + name )
288247 if err != nil {
289- klog .Errorf ("failed to delete qos %s, %v" , qos , err )
290- return err
248+ klog .Errorf ("failed to find related port %v" , err )
249+ return
250+ }
251+ klog .Infof ("delete lost port %s" , name )
252+ output , err := Exec ("--if-exists" , "--with-iface" , "del-port" , name )
253+ if err != nil {
254+ klog .Errorf ("failed to delete ovs port %v, %s" , err , output )
255+ return
256+ }
257+ for _ , qos := range qosList {
258+ qos = strings .TrimSpace (qos )
259+ if qos != "" && qos != "[]" {
260+ klog .Infof ("delete lost qos %s" , qos )
261+ err = ovsDestroy ("qos" , qos )
262+ if err != nil {
263+ klog .Errorf ("failed to delete qos %s, %v" , qos , err )
264+ return
265+ }
266+ }
291267 }
292268 }
293269 }
294- return nil
295270}
296271
297272// Find and remove any existing OVS port with this iface-id. Pods can
0 commit comments