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 10, 2024
1 parent 46199d5 commit f5ac307
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/subnet/subnet_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (r *SubnetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr

func (r *SubnetReconciler) deleteSubnetByID(subnetID string) error {
nsxSubnets := r.SubnetService.SubnetStore.GetByIndex(servicecommon.TagScopeSubnetCRUID, subnetID)
return r.deleteStaleSubnets(nsxSubnets)
return r.deleteSubnets(nsxSubnets)
}

func (r *SubnetReconciler) deleteSubnets(nsxSubnets []*model.VpcSubnet) error {
Expand Down
7 changes: 4 additions & 3 deletions pkg/controllers/subnetset/subnetset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *SubnetSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
return ResultNormal, nil
}
log.Error(err, "Unable to fetch Subnet CR", "req", req.NamespacedName)
log.Error(err, "Unable to fetch SubnetSet CR", "req", req.NamespacedName)
return ResultRequeue, err
}
if !subnetsetCR.ObjectMeta.DeletionTimestamp.IsZero() {
Expand All @@ -79,11 +79,12 @@ func (r *SubnetSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ResultRequeue, err
}
if err := r.Client.Delete(ctx, subnetsetCR); err != nil {
log.Error(err, "Failed to delete Subnet CR, retrying", "SubnetSet", req.NamespacedName)
log.Error(err, "Failed to delete SubnetSet CR, retrying", "SubnetSet", req.NamespacedName)
deleteFail(r, ctx, subnetsetCR, err.Error())
return ResultRequeue, err
}
deleteSuccess(r, ctx, subnetsetCR)
return ResultNormal, nil
}

metrics.CounterInc(r.SubnetService.NSXConfig, metrics.ControllerUpdateTotal, MetricResTypeSubnetSet)
Expand Down Expand Up @@ -302,7 +303,7 @@ func (r *SubnetSetReconciler) deleteSubnetBySubnetSetName(subnetSetName, ns stri

func (r *SubnetSetReconciler) deleteSubnetForSubnetSet(obj v1alpha1.SubnetSet, updateStatus bool) error {
nsxSubnets := r.SubnetService.SubnetStore.GetByIndex(servicecommon.TagScopeSubnetSetCRUID, string(obj.GetUID()))
if err := r.deleteStaleSubnets(nsxSubnets); err != nil {
if err := r.deleteSubnets(nsxSubnets); err != nil {
return err
}
if updateStatus {
Expand Down
4 changes: 3 additions & 1 deletion pkg/nsx/services/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ func (service *SubnetService) createOrUpdateSubnet(obj client.Object, nsxSubnet
Jitter: 0,
Steps: 6,
}
//
// Failure of CheckRealizeState may result in the creation of an existing Subnet.
// For Subnets, it's important to reuse the already created NSXSubnet.
// For SubnetSets, since the ID includes a random value, the created NSX Subnet needs to be deleted and recreated.
if err = realizeService.CheckRealizeState(backoff, *nsxSubnet.Path, "RealizedLogicalSwitch"); err != nil {
log.Error(err, "failed to check subnet realization state", "ID", *nsxSubnet.Id)
return "", err
Expand Down

0 comments on commit f5ac307

Please sign in to comment.