Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Oct 12, 2024
1 parent d041dce commit ba4f45a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/controllers/subnetset/subnetset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (r *SubnetSetReconciler) CollectGarbage(ctx context.Context) {
log.Info("SubnetSet garbage collection completed", "duration(ms)", time.Since(startTime).Milliseconds())
}()

crdSubnetSetIDs, err := r.listSubnetSetIDsFromCRs(ctx)
crdSubnetSetIDs, err := r.listSubnetSetIDsFromCRs(ctx, true)
if err != nil {
log.Error(err, "Failed to list Subnet CRs")
return
Expand Down Expand Up @@ -306,7 +306,7 @@ func (r *SubnetSetReconciler) deleteSubnetForSubnetSet(obj v1alpha1.SubnetSet, u
return nil
}

func (r *SubnetSetReconciler) listSubnetSetIDsFromCRs(ctx context.Context) ([]string, error) {
func (r *SubnetSetReconciler) listSubnetSetIDsFromCRs(ctx context.Context, deleteSubnetForSubnetSet bool) ([]string, error) {
crdSubnetSetList := &v1alpha1.SubnetSetList{}
err := r.Client.List(ctx, crdSubnetSetList)
if err != nil {
Expand All @@ -317,6 +317,15 @@ func (r *SubnetSetReconciler) listSubnetSetIDsFromCRs(ctx context.Context) ([]st
for _, sr := range crdSubnetSetList.Items {
crdSubnetSetIDs = append(crdSubnetSetIDs, string(sr.UID))
}
if deleteSubnetForSubnetSet {
for _, subnetSet := range crdSubnetSetList.Items {
if err := r.deleteSubnetForSubnetSet(subnetSet, true); err != nil {
metrics.CounterInc(r.SubnetService.NSXConfig, metrics.ControllerDeleteFailTotal, MetricResTypeSubnetSet)
} else {
metrics.CounterInc(r.SubnetService.NSXConfig, metrics.ControllerDeleteSuccessTotal, MetricResTypeSubnetSet)
}
}
}
return crdSubnetSetIDs, nil
}

Expand All @@ -339,7 +348,7 @@ func (r *SubnetSetReconciler) deleteSubnets(nsxSubnets []*model.VpcSubnet) error
}

func (r *SubnetSetReconciler) deleteStaleSubnets(ctx context.Context, nsxSubnets []*model.VpcSubnet) error {
crdSubnetSetIDs, err := r.listSubnetSetIDsFromCRs(ctx)
crdSubnetSetIDs, err := r.listSubnetSetIDsFromCRs(ctx, false)
if err != nil {
log.Error(err, "Failed to list Subnet CRs")
return err
Expand Down

0 comments on commit ba4f45a

Please sign in to comment.