Skip to content

Commit

Permalink
fix: update the application even if gitop fails (#367)
Browse files Browse the repository at this point in the history
When deleting a component currently the Application will not be updated
if the gitops deletion fails.

fixes RHTAPBUGS-503
  • Loading branch information
stuartwdouglas authored Aug 9, 2023
1 parent ccbca3c commit 4f7b4a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions controllers/component_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
// only attempt to finalize and update the gitops repo if an Application is present & the previous Component status is good
// A finalizer is present for the Component CR, so make sure we do the necessary cleanup steps
if err := r.Finalize(ctx, &component, &hasApplication, ghClient); err != nil {
if errors.IsConflict(err) {
//conflict means we just retry, we are updating the shared application so conflicts are not unexpected
return ctrl.Result{}, err
}
// if fail to delete the external dependency here, log the error, but don't return error
// Don't want to get stuck in a cycle of repeatedly trying to update the repository and failing
log.Error(err, "Unable to update GitOps repository for component %v in namespace %v", component.GetName(), component.GetNamespace())
Expand Down
19 changes: 13 additions & 6 deletions controllers/component_controller_finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"

appstudiov1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
cdqanalysis "github.com/redhat-appstudio/application-service/cdq-analysis/pkg"
github "github.com/redhat-appstudio/application-service/pkg/github"
Expand Down Expand Up @@ -72,6 +75,15 @@ func (r *ComponentReconciler) Finalize(ctx context.Context, component *appstudio

application.Status.Devfile = string(yamldevfileObj)

err = r.Status().Update(ctx, application)
if err != nil {
if errors.IsConflict(err) {
return err
}
log := ctrl.LoggerFrom(ctx)
log.Error(err, "Failed to update application in finalizer, will not retry to prevent finalizer loop")
}

gitOpsURL, gitOpsBranch, gitOpsContext, err := util.ProcessGitOpsStatus(component.Status.GitOps, ghClient.Token)
if err != nil {
return err
Expand All @@ -90,10 +102,5 @@ func (r *ComponentReconciler) Finalize(ctx context.Context, component *appstudio
return err
}

err = r.AppFS.RemoveAll(tempDir)
if err != nil {
return err
}

return r.Status().Update(ctx, application)
return r.AppFS.RemoveAll(tempDir)
}

0 comments on commit 4f7b4a1

Please sign in to comment.