Skip to content

Commit b875d90

Browse files
authored
fix: apply failure will cause release state to be completely empty (#1390)
1 parent 83f1467 commit b875d90

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pkg/engine/api/apply.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ func Apply(
139139
Release: rel,
140140
Graph: gph,
141141
})
142+
if rsp != nil {
143+
upRel = rsp.Release
144+
}
142145
if v1.IsErr(st) {
143146
return nil, fmt.Errorf("apply failed, status:\n%v", st)
144147
}
145-
upRel = rsp.Release
146148
}
147149

148150
// wait for msgCh closed

pkg/engine/operation/apply.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ func (ao *ApplyOperation) Apply(req *ApplyRequest) (rsp *ApplyResponse, s v1.Sta
4444
log.Infof("engine: Apply start!")
4545
o := ao.Operation
4646

47+
// keep release state
48+
rsp = &ApplyResponse{
49+
Release: req.Release,
50+
}
51+
4752
defer func() {
4853
close(o.MsgCh)
4954

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

6469
if s = validateApplyRequest(req); v1.IsErr(s) {
65-
return nil, s
70+
return rsp, s
6671
}
6772

6873
// Update the operation semaphore.
6974
if err := o.UpdateSemaphore(); err != nil {
70-
return nil, v1.NewErrorStatus(err)
75+
return rsp, v1.NewErrorStatus(err)
7176
}
7277

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

8287
runtimesMap, s := runtimeinit.Runtimes(*req.Release.Spec, *req.Release.State)
8388
if v1.IsErr(s) {
84-
return nil, s
89+
return rsp, s
8590
}
8691
o.RuntimeMap = runtimesMap
8792

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

97102
rel, s := copyRelease(req.Release)
98103
if v1.IsErr(s) {
99-
return nil, s
104+
return rsp, s
100105
}
101106
applyOperation := &ApplyOperation{
102107
Operation: models.Operation{
@@ -122,10 +127,10 @@ func (ao *ApplyOperation) Apply(req *ApplyRequest) (rsp *ApplyResponse, s v1.Sta
122127
// Wait
123128
if diags := w.Wait(); diags.HasErrors() {
124129
s = v1.NewErrorStatus(diags.Err())
125-
return nil, s
126130
}
127-
128-
return &ApplyResponse{Release: applyOperation.Release, Graph: resourceGraph}, nil
131+
rsp.Release = applyOperation.Release
132+
rsp.Graph = resourceGraph
133+
return rsp, s
129134
}
130135

131136
func (ao *ApplyOperation) walkFun(v dag.Vertex) (diags tfdiags.Diagnostics) {

0 commit comments

Comments
 (0)