Skip to content

Commit 58befa1

Browse files
Merge pull request #94 from qiangzii/master
fix repair and free hostnic when nic was deleted
2 parents 14e9f96 + 27beebf commit 58befa1

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pkg/allocator/allocator.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ func (a *Allocator) freeHostnic(nic *rpc.HostNic) error {
339339
}
340340

341341
if _, err := qcclient.QClient.DeattachNics([]string{nic.ID}, true); err != nil {
342+
if strings.Contains(err.Error(), constants.ResourceNotFound) {
343+
log.Infof("nic %s/%s was not found from api, skip DeattachNics and DeleteNics", nic.VxNet.ID, nic.ID)
344+
return nil
345+
}
342346
log.Errorf("DeattachNics for vxnet %s failed: nic %s failed: %v", nic.VxNet.ID, nic.ID, err)
343347
return err
344348
}
@@ -355,13 +359,14 @@ func (a *Allocator) ClearFreeHostnic(force bool) error {
355359
a.lock.Lock()
356360
defer a.lock.Unlock()
357361

358-
maxVxnetNicsCount := a.getVxnetMaxNicNum()
359-
if len(a.nics) < a.conf.NodeThreshold && maxVxnetNicsCount < a.conf.VxnetThreshold && !force {
360-
log.Infof("no hostnic to free: %d %d %d %d", len(a.nics), maxVxnetNicsCount, a.conf.NodeThreshold, a.conf.VxnetThreshold)
361-
return nil
362-
}
362+
// maxVxnetNicsCount := a.getVxnetMaxNicNum()
363+
// log.Infof("freeHostnic: %d %d %d %d", len(a.nics), maxVxnetNicsCount, a.conf.NodeThreshold, a.conf.VxnetThreshold)
364+
// if len(a.nics) < a.conf.NodeThreshold && maxVxnetNicsCount < a.conf.VxnetThreshold && !force {
365+
// log.Infof("no hostnic to free: %d %d %d %d", len(a.nics), maxVxnetNicsCount, a.conf.NodeThreshold, a.conf.VxnetThreshold)
366+
// return nil
367+
// }
363368

364-
log.Infof("freeHostnic: %d %d %d %d", len(a.nics), maxVxnetNicsCount, a.conf.NodeThreshold, a.conf.VxnetThreshold)
369+
log.Infof("freeHostnic: %d", len(a.nics))
365370
for vxnet, status := range a.nics {
366371
if len(status.Pods) == 0 {
367372
nicKey := getNicKey(status.Nic)

pkg/networkutils/networkutil.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ func (n NetworkUtils) CheckAndRepairNetwork(nic *rpc.HostNic) (rpc.Phase, error)
111111
if err != nil {
112112
return rpc.Phase_Init, fmt.Errorf("failed to get nic %s from api: %v", nicKey, err)
113113
}
114+
if _, ok := nicCur[nic.ID]; !ok {
115+
return rpc.Phase_Init, fmt.Errorf("nic %s was not found from api, can't repair this hostnic", nicKey)
116+
}
114117
if nicCur[nic.ID].Using {
115-
return rpc.Phase_Init, fmt.Errorf("nic %s status is in-use", nicKey)
118+
return rpc.Phase_Init, fmt.Errorf("nic %s status is in-use, please deattach it from other instance", nicKey)
116119
}
117120

118121
//attach nic

0 commit comments

Comments
 (0)