diff --git a/pkg/sync/hook.go b/pkg/sync/hook.go index d4ec9976..25916d24 100644 --- a/pkg/sync/hook.go +++ b/pkg/sync/hook.go @@ -101,21 +101,29 @@ func (engine *Engine) hooksHandler(ctx context.Context, namespace, name string, components := []*console.ComponentAttributes{} toDelete := object.ObjMetadataSet{} + failed := console.ComponentStateFailed + running := console.ComponentStateRunning for k, v := range statusCollector.latestStatus { - if v.PollResourceInfo.Status == status.FailedStatus { - if deleteFailed.Contains(k) { - toDelete = append(toDelete, k) - } - } - if v.PollResourceInfo.Status == status.CurrentStatus { - if deleteSucceeded.Contains(k) { - toDelete = append(toDelete, k) - } - } - consoleAttr := fromSyncResult(v, vcache) if consoleAttr != nil { + if consoleAttr.State == nil { + if v.PollResourceInfo.Status == status.FailedStatus { + consoleAttr.State = &failed + } + if v.PollResourceInfo.Status == status.CurrentStatus { + consoleAttr.State = &running + } + } components = append(components, consoleAttr) + if *consoleAttr.State == console.ComponentStateFailed { + if deleteFailed.Contains(k) { + toDelete = append(toDelete, k) + } + } else if *consoleAttr.State == console.ComponentStateRunning { + if deleteSucceeded.Contains(k) { + toDelete = append(toDelete, k) + } + } } } diff --git a/pkg/sync/loop.go b/pkg/sync/loop.go index 53dc6a65..db96e566 100644 --- a/pkg/sync/loop.go +++ b/pkg/sync/loop.go @@ -2,17 +2,17 @@ package sync import ( "context" + "errors" "fmt" "runtime/debug" "time" - "github.com/pluralsh/deployment-operator/pkg/hook" + console "github.com/pluralsh/console-client-go" + plrlerrors "github.com/pluralsh/deployment-operator/pkg/errors" + "github.com/pluralsh/deployment-operator/pkg/hook" manis "github.com/pluralsh/deployment-operator/pkg/manifests" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "sigs.k8s.io/cli-utils/pkg/apply" - "sigs.k8s.io/cli-utils/pkg/common" "sigs.k8s.io/cli-utils/pkg/inventory" ) @@ -128,6 +128,17 @@ func (engine *Engine) processItem(item interface{}) error { if err != nil { return err } + + for _, c := range preInstallComponents { + if *c.State != console.ComponentStateRunning { + // wait until hooks are completed + if err := engine.updateStatus(id, preInstallComponents, errorAttributes("sync", err)); err != nil { + log.Error(err, "Failed to update service status, ignoring for now") + } + return nil + } + } + log.Info("Apply service", "name", svc.Name, "namespace", svc.Namespace) ch := engine.applier.Run(ctx, inv, manifests, GetDefaultApplierOptions()) components, err := engine.UpdateApplyStatus(id, svc.Name, svc.Namespace, ch, false, vcache) diff --git a/pkg/sync/utils.go b/pkg/sync/utils.go index fcbf254e..623786d7 100644 --- a/pkg/sync/utils.go +++ b/pkg/sync/utils.go @@ -40,7 +40,7 @@ func GetDefaultPruneOptions() apply.DestroyerOptions { InventoryPolicy: inventory.PolicyAdoptIfNoInventory, DryRunStrategy: common.DryRunNone, DeleteTimeout: 20 * time.Second, - DeletePropagationPolicy: metav1.DeletePropagationForeground, + DeletePropagationPolicy: metav1.DeletePropagationBackground, EmitStatusEvents: true, ValidationPolicy: 1, }