Skip to content

Commit

Permalink
bugfix: resource nodes of delete action don't need compute action typ…
Browse files Browse the repository at this point in the history
…e again

- resource nodes created by spec parser can be Update/Delete action, state field is plan state
- resource nodes created by delete parser are definite to Delete action, state field is prior state
  • Loading branch information
howieyuen committed Jul 26, 2022
1 parent 3299afd commit 2a738dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/engine/operation/graph/resource_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (rn *ResourceNode) Execute(operation *opsmodels.Operation) status.Status {

// 1. prepare planedState
planedState := rn.state
if rn.Action == types.Delete {
planedState = nil
}
// predictableState represents dry-run result
predictableState := planedState

Expand All @@ -51,7 +54,11 @@ func (rn *ResourceNode) Execute(operation *opsmodels.Operation) status.Status {
priorState := operation.PriorStateResourceIndex[key]

// 3. get the latest resource from runtime
response := operation.Runtime.Read(context.Background(), &runtime.ReadRequest{Resource: planedState})
readRequest := &runtime.ReadRequest{Resource: planedState}
if readRequest.Resource == nil {
readRequest.Resource = priorState
}
response := operation.Runtime.Read(context.Background(), readRequest)
liveState := response.Resource
s := response.Status
if status.IsErr(s) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/operation/graph/resource_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestResourceNode_Execute(t *testing.T) {
})
monkey.PatchInstanceMethod(reflect.TypeOf(tt.args.operation.Runtime), "Delete",
func(k *runtime.KubernetesRuntime, ctx context.Context, request *runtime.DeleteRequest) *runtime.DeleteResponse {
return nil
return &runtime.DeleteResponse{nil}
})
monkey.PatchInstanceMethod(reflect.TypeOf(tt.args.operation.Runtime), "Read",
func(k *runtime.KubernetesRuntime, ctx context.Context, request *runtime.ReadRequest) *runtime.ReadResponse {
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/operation/preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestOperation_Preview(t *testing.T) {
ID: "fake-id-2",
Action: types.Delete,
From: &FakeResourceState2,
To: &FakeResourceState2,
To: (*models.Resource)(nil),
},
},
},
Expand Down

0 comments on commit 2a738dc

Please sign in to comment.