Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply failure will cause release state to be completely empty #1390

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/engine/api/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ func Apply(
Release: rel,
Graph: gph,
})
if rsp != nil {
upRel = rsp.Release
}
if v1.IsErr(st) {
return nil, fmt.Errorf("apply failed, status:\n%v", st)
}
upRel = rsp.Release
}

// wait for msgCh closed
Expand Down
21 changes: 13 additions & 8 deletions pkg/engine/operation/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func (ao *ApplyOperation) Apply(req *ApplyRequest) (rsp *ApplyResponse, s v1.Sta
log.Infof("engine: Apply start!")
o := ao.Operation

// keep release state
rsp = &ApplyResponse{
Release: req.Release,
}

defer func() {
close(o.MsgCh)

Expand All @@ -62,12 +67,12 @@ func (ao *ApplyOperation) Apply(req *ApplyRequest) (rsp *ApplyResponse, s v1.Sta
}()

if s = validateApplyRequest(req); v1.IsErr(s) {
return nil, s
return rsp, s
}

// Update the operation semaphore.
if err := o.UpdateSemaphore(); err != nil {
return nil, v1.NewErrorStatus(err)
return rsp, v1.NewErrorStatus(err)
}

// 1. init & build Indexes
Expand All @@ -81,22 +86,22 @@ func (ao *ApplyOperation) Apply(req *ApplyRequest) (rsp *ApplyResponse, s v1.Sta

runtimesMap, s := runtimeinit.Runtimes(*req.Release.Spec, *req.Release.State)
if v1.IsErr(s) {
return nil, s
return rsp, s
}
o.RuntimeMap = runtimesMap

// 2. build & walk DAG
applyGraph, s := newApplyGraph(req.Release.Spec, priorState)
if v1.IsErr(s) {
return nil, s
return rsp, s
}
log.Infof("Apply Graph:\n%s", applyGraph.String())
// Get dependencies and dependents of each node to be populated into resource graph.
resourceGraph := populateResourceGraph(applyGraph, req.Graph)

rel, s := copyRelease(req.Release)
if v1.IsErr(s) {
return nil, s
return rsp, s
}
applyOperation := &ApplyOperation{
Operation: models.Operation{
Expand All @@ -122,10 +127,10 @@ func (ao *ApplyOperation) Apply(req *ApplyRequest) (rsp *ApplyResponse, s v1.Sta
// Wait
if diags := w.Wait(); diags.HasErrors() {
s = v1.NewErrorStatus(diags.Err())
return nil, s
}

return &ApplyResponse{Release: applyOperation.Release, Graph: resourceGraph}, nil
rsp.Release = applyOperation.Release
rsp.Graph = resourceGraph
return rsp, s
}

func (ao *ApplyOperation) walkFun(v dag.Vertex) (diags tfdiags.Diagnostics) {
Expand Down
Loading