Skip to content

Commit

Permalink
wait until hook finished
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed Dec 4, 2023
1 parent dfca307 commit 534f52d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
30 changes: 19 additions & 11 deletions pkg/sync/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

Expand Down
19 changes: 15 additions & 4 deletions pkg/sync/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sync/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 534f52d

Please sign in to comment.