diff --git a/pkg/neg/manager.go b/pkg/neg/manager.go index d236f5a1cf..472510a522 100644 --- a/pkg/neg/manager.go +++ b/pkg/neg/manager.go @@ -21,6 +21,7 @@ import ( "fmt" "net/http" "reflect" + "slices" "sync" "time" @@ -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) @@ -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 {