Skip to content

Commit

Permalink
Remove deleted NEG reference during GC.
Browse files Browse the repository at this point in the history
  • Loading branch information
sawsa307 committed Jul 17, 2024
1 parent 0656864 commit 9c054a7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/neg/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"reflect"
"slices"
"sync"
"time"

Expand Down Expand Up @@ -615,6 +616,7 @@ func (manager *syncerManager) processNEGDeletionCandidate(svcNegCR *negv1beta1.S
var errList []error
shouldDeleteNegCR := true
deleteByZone := len(svcNegCR.Status.NetworkEndpointGroups) == 0
var deletedNegRefIds []string

for _, negRef := range svcNegCR.Status.NetworkEndpointGroups {
resourceID, err := cloud.ParseResourceURL(negRef.SelfLink)
Expand All @@ -623,10 +625,19 @@ func (manager *syncerManager) processNEGDeletionCandidate(svcNegCR *negv1beta1.S
deleteByZone = true
continue
}
deletedNegRefIds = append(deletedNegRefIds, negRef.Id)

shouldDeleteNegCR = shouldDeleteNegCR && manager.deleteNegOrReportErr(resourceID.Key.Name, resourceID.Key.Zone, svcNegCR, &errList)
}

// Clear NEG Refs for those that has been successfully deleted.
var newNegRef []negv1beta1.NegObjectReference
for _, negRef := range svcNegCR.Status.NetworkEndpointGroups {
if !slices.Contains(deletedNegRefIds, negRef.Id) {
newNegRef = append(newNegRef, negRef)
}
}

if deleteByZone {
manager.logger.V(2).Info("Deletion candidate has 0 NEG reference", "svcneg", klog.KObj(svcNegCR), "svcNegCR", svcNegCR)
for _, zone := range zones {
Expand Down

0 comments on commit 9c054a7

Please sign in to comment.