Skip to content

Commit

Permalink
fix shallow copy
Browse files Browse the repository at this point in the history
  • Loading branch information
l1b0k committed Nov 30, 2021
1 parent 94c2a85 commit ccb7371
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/controller/pod-eni/eni_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (m *ReconcilePodENI) gcENIs(enis []ecs.NetworkInterfaceSet, force bool) err
}
layout := "2006-01-02T15:04:05Z"
now := time.Now()
for _, eni := range enis {
for i, eni := range enis {
if !m.eniFilter(eni, tagFilter) {
continue
}
Expand All @@ -376,7 +376,7 @@ func (m *ReconcilePodENI) gcENIs(enis []ecs.NetworkInterfaceSet, force bool) err
continue
}
}
eniMap[eni.NetworkInterfaceId] = &eni
eniMap[eni.NetworkInterfaceId] = &enis[i]
}
if len(eniMap) == 0 {
return nil
Expand All @@ -403,21 +403,21 @@ func (m *ReconcilePodENI) gcENIs(enis []ecs.NetworkInterfaceSet, force bool) err
}

// 4. the left eni is going to be deleted
for id, eni := range eniMap {
for _, eni := range eniMap {
if eni.Type == string(aliyun.ENITypeMember) && eni.Status == string(aliyun.ENIStatusInUse) {
l.Info("detach eni", "eni", id, "trunk-eni", eni.Attachment.TrunkNetworkInterfaceId)
err = m.aliyun.DetachNetworkInterface(context.Background(), id, eni.Attachment.InstanceId, eni.Attachment.TrunkNetworkInterfaceId)
l.Info("detach eni", "eni", eni.NetworkInterfaceId, "trunk-eni", eni.Attachment.TrunkNetworkInterfaceId)
err = m.aliyun.DetachNetworkInterface(context.Background(), eni.NetworkInterfaceId, eni.Attachment.InstanceId, eni.Attachment.TrunkNetworkInterfaceId)
if err != nil {
l.Error(err, fmt.Sprintf("errot detach eni %s", id))
l.Error(err, fmt.Sprintf("errot detach eni %s", eni.NetworkInterfaceId))
}
// we continue here because we can delete eni in next check
continue
}
if eni.Status == string(aliyun.ENIStatusAvailable) {
l.Info("delete eni", "eni", id)
err = m.aliyun.DeleteNetworkInterface(context.Background(), id)
l.Info("delete eni", "eni", eni.NetworkInterfaceId)
err = m.aliyun.DeleteNetworkInterface(context.Background(), eni.NetworkInterfaceId)
if err != nil {
l.Info(fmt.Sprintf("delete leaked eni %s, %s", id, err))
l.Info(fmt.Sprintf("delete leaked eni %s, %s", eni.NetworkInterfaceId, err))
}
continue
}
Expand Down

0 comments on commit ccb7371

Please sign in to comment.