diff --git a/pkg/controllers/subnet/subnet_controller.go b/pkg/controllers/subnet/subnet_controller.go index 3df4d59da..c51b7aad9 100644 --- a/pkg/controllers/subnet/subnet_controller.go +++ b/pkg/controllers/subnet/subnet_controller.go @@ -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 { diff --git a/pkg/controllers/subnetset/subnetset_controller.go b/pkg/controllers/subnetset/subnetset_controller.go index a802dcde7..48f3ac60d 100644 --- a/pkg/controllers/subnetset/subnetset_controller.go +++ b/pkg/controllers/subnetset/subnetset_controller.go @@ -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() { @@ -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) @@ -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 { diff --git a/pkg/nsx/services/subnet/subnet.go b/pkg/nsx/services/subnet/subnet.go index f6ecb2201..fb3492560 100644 --- a/pkg/nsx/services/subnet/subnet.go +++ b/pkg/nsx/services/subnet/subnet.go @@ -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