Skip to content

Commit

Permalink
refined the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
droot committed Aug 31, 2022
1 parent 6495bab commit 12677e0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions porch/pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,6 @@ func (cad *cadEngine) UpdatePackageResources(ctx context.Context, repositoryObj
newResources: new,
oldResources: old,
},
&renderPackageMutation{
renderer: cad.renderer,
runtime: cad.runtime,
},
}

apiResources, err := oldPackage.GetResources(ctx)
Expand All @@ -416,11 +412,24 @@ func (cad *cadEngine) UpdatePackageResources(ctx context.Context, repositoryObj
resources := repository.PackageResources{
Contents: apiResources.Spec.Resources,
}
renderResult, err := applyResourceMutations(ctx, draft, resources, mutations)
if err != nil {
return nil, renderResult, err
if _, err := applyResourceMutations(ctx, draft, resources, mutations); err != nil {
return nil, nil, err
}

renderResult, err := applyResourceMutations(ctx,
draft,
resources,
[]mutation{&renderPackageMutation{
renderer: cad.renderer,
runtime: cad.runtime,
}})
if err != nil {
// render failed on the package but we won't fail the overall
// update operation. Instead, we will continue with saving the draft with
// original incoming resources. Clients will examine the status
// which will contain renderResult for graceful handling.
err = nil
}
// No lifecycle change when updating package resources; updates are done.
updatedRev, err := draft.Close(ctx)
return updatedRev, renderResult, err
Expand All @@ -432,12 +441,12 @@ func applyResourceMutations(ctx context.Context, draft repository.PackageDraft,
var renderResult *fnresult.ResultList
for _, m := range mutations {
applied, taskResult, task, err := m.Apply(ctx, baseResources)
if err != nil {
return renderResult, err
}
if taskResult != nil && taskResult.Type == api.TaskTypeEval {
renderResult = taskResult.Render
}
if err != nil {
return renderResult, err
}
if err := draft.UpdateResources(ctx, &api.PackageRevisionResources{
Spec: api.PackageRevisionResourcesSpec{
Resources: applied.Contents,
Expand Down

0 comments on commit 12677e0

Please sign in to comment.