Skip to content

Commit

Permalink
Fixed pre-delete logic of NetworkConfig resource
Browse files Browse the repository at this point in the history
Invocations in pre-delete logic of NetworkConfig have been re-organized so that functions are called before the finalizer is removed.
  • Loading branch information
davidefalcone1 committed Jun 17, 2021
1 parent d9fcab7 commit 7cc4131
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,25 @@ func (tec *TunnelEndpointCreator) Reconcile(ctx context.Context, req ctrl.Reques
return result, nil
}
} else {
// the object is being deleted
if err := tec.deleteTunEndpoint(&netConfig); err != nil {
klog.Errorf("an error occurred while deleting tunnel endpoint related to %s: %s", netConfig.Name, err)
return result, err
}
// The object is being deleted
if controllerutil.ContainsFinalizer(&netConfig, tunnelEndpointCreatorFinalizer) {
// remove the finalizer from the list and update it.
// Remove IPAM configuration per cluster
if err := tec.IPManager.RemoveClusterConfig(netConfig.Spec.ClusterID); err != nil {
klog.Errorf("cannot delete local subnets assigned to cluster %s: %s", netConfig.Spec.ClusterID, err.Error())
return result, err
}
// Remove TunnelEndpoint resource relative to this NetworkConfig
if err := tec.deleteTunEndpoint(&netConfig); err != nil {
klog.Errorf("an error occurred while deleting tunnel endpoint related to %s: %s", netConfig.Name, err)
return result, err
}
// Remove the finalizer and update resource.
controllerutil.RemoveFinalizer(&netConfig, tunnelEndpointCreatorFinalizer)
if err := tec.Update(ctx, &netConfig); err != nil {
if apierrors.IsConflict(err) {
return ctrl.Result{}, nil
}
klog.Errorf("an error occurred while removing finalizer from resource %s: %s", req.NamespacedName, err)
return result, err
}
}
// Remove IPAM configuration per cluster
if err := tec.IPManager.RemoveClusterConfig(netConfig.Spec.ClusterID); err != nil {
klog.Errorf("cannot delete local subnets assigned to cluster %s: %s", netConfig.Spec.ClusterID, err.Error())
}
return result, nil
}

Expand Down

0 comments on commit 7cc4131

Please sign in to comment.