Skip to content

Commit

Permalink
fix: delete logic (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteogastaldello authored Jul 30, 2024
1 parent f18c702 commit 4ceb78e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/controllers/workflows/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (reconciler
}

got := ptr.Deref(cr.Status.Digest, "")
if len(got) == 0 && meta.WasDeleted(cr) {
if len(got) == 0 && meta.WasDeleted(cr) && cr.Status.GetCondition(rtv1.TypeReady).Reason == rtv1.ReasonDeleting {
return reconciler.ExternalObservation{
ResourceExists: false,
ResourceUpToDate: true,
Expand Down Expand Up @@ -212,6 +212,7 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) error {
return err
}

cr.Status.SetConditions(rtv1.Deleting())
cr.Status.Digest = ptr.To("")

return e.kube.Status().Update(ctx, cr)
Expand Down
5 changes: 5 additions & 0 deletions internal/workflows/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workflows
import (
"context"
"fmt"
"slices"

"github.com/krateoplatformops/installer/apis/workflows/v1alpha1"
"github.com/krateoplatformops/installer/internal/cache"
Expand Down Expand Up @@ -99,6 +100,10 @@ func (wf *Workflow) Op(op steps.Op) {
func (wf *Workflow) Run(ctx context.Context, spec *v1alpha1.WorkflowSpec, skip func(*v1alpha1.Step) bool) (results []StepResult) {
results = make([]StepResult, len(spec.Steps))

if wf.op == steps.Delete {
slices.Reverse(spec.Steps)
}

for i, x := range spec.Steps {
if skip(x) {
wf.logr.Info(fmt.Sprintf("skipping step with id: %s (%v)", x.ID, x.Type))
Expand Down

0 comments on commit 4ceb78e

Please sign in to comment.