Skip to content

Commit

Permalink
Removing the finalizer after the catalog is disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Lalatendu Mohanty <[email protected]>
  • Loading branch information
LalatenduMohanty committed Oct 16, 2024
1 parent eba52e7 commit 6cd0ea3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
1 change: 0 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ func main() {
LocalStorage: localStorage,
}

// Start the catalogd web server
err = serverutil.AddCatalogServerToManager(mgr, catalogServerConfig, cw)
if err != nil {
setupLog.Error(err, "unable to configure catalog server")
Expand Down
45 changes: 25 additions & 20 deletions internal/controllers/core/clustercatalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
crfinalizer "sigs.k8s.io/controller-runtime/pkg/finalizer"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -161,25 +162,25 @@ func (r *ClusterCatalogReconciler) reconcile(ctx context.Context, catalog *v1alp
// Check if the catalog availability is set to disabled, if true then
// unset content URL, delete it from the cache and set appropriate status
if catalog.Spec.Availability == v1alpha1.AvailabilityDisabled {

Check failure on line 164 in internal/controllers/core/clustercatalog_controller.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)
// Delete the catalog from local cache
if err := r.Storage.Delete(catalog.Name); err != nil {
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
return ctrl.Result{}, err
}

// Set status.conditions[type=Serving] to False, unset status.contentURL and
// update status.lastUnpacked
updateStatusNotServing(&catalog.Status, catalog.GetGeneration())
if err := r.Unpacker.Cleanup(ctx, catalog); err != nil {
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)

// Delete the catalog from local cache
err := r.deleteCatalogCache(ctx, catalog)
if err != nil {
return ctrl.Result{}, err
}
r.deleteStoredCatalog(catalog.Name)

// Set status.conditions[type=Progressing] to False as we are done with
// all that needs to be done with the catalog
updateStatusCatalogDisabled(&catalog.Status, catalog.GetGeneration())

// Remove the fbcDeletionFinalizer as we do not want a finalizer attached to the catalog
// when it is disabled. Because the finalizer serves no purpose now.
controllerutil.RemoveFinalizer(catalog, fbcDeletionFinalizer)

return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -395,18 +396,8 @@ func (r *ClusterCatalogReconciler) setupFinalizers() error {
if !ok {
panic("could not convert object to clusterCatalog")
}
if err := r.Storage.Delete(catalog.Name); err != nil {
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
return crfinalizer.Result{StatusUpdated: true}, err
}
updateStatusNotServing(&catalog.Status, catalog.GetGeneration())
if err := r.Unpacker.Cleanup(ctx, catalog); err != nil {
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
return crfinalizer.Result{StatusUpdated: true}, err
}

r.deleteStoredCatalog(catalog.Name)
return crfinalizer.Result{StatusUpdated: true}, nil
err := r.deleteCatalogCache(ctx, catalog)
return crfinalizer.Result{StatusUpdated: true}, err
}))
if err != nil {
return err
Expand All @@ -420,3 +411,17 @@ func (r *ClusterCatalogReconciler) deleteStoredCatalog(catalogName string) {
defer r.storedCatalogsMu.Unlock()
delete(r.storedCatalogs, catalogName)
}

func (r *ClusterCatalogReconciler) deleteCatalogCache(ctx context.Context, catalog *v1alpha1.ClusterCatalog) error {
if err := r.Storage.Delete(catalog.Name); err != nil {
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
return err
}
updateStatusNotServing(&catalog.Status, catalog.GetGeneration())
if err := r.Unpacker.Cleanup(ctx, catalog); err != nil {
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
return err
}
r.deleteStoredCatalog(catalog.Name)
return nil
}

0 comments on commit 6cd0ea3

Please sign in to comment.