Skip to content

Commit f407407

Browse files
authored
Add implementation of 'porch.kpt.dev/push-on-render-failure' for clone and upgrade (#1126)
* Add implementation of 'porch.kpt.dev/push-on-render-failure' for subpackages Signed-off-by: liamfallon <liam.fallon@est.tech> * Address copilot comments Signed-off-by: liamfallon <liam.fallon@est.tech> * Get e2e tests working Signed-off-by: liamfallon <liam.fallon@est.tech> * Add unit tests Signed-off-by: liamfallon <liam.fallon@est.tech> * Address CoPilot comments Signed-off-by: liamfallon <liam.fallon@est.tech> * Add unit tests Signed-off-by: liamfallon <liam.fallon@est.tech> * Update unit tests Signed-off-by: liamfallon <liam.fallon@est.tech> * Address comments on PR Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix unit and e2e tests Signed-off-by: liamfallon <liam.fallon@est.tech> * Updated to address comments Signed-off-by: liamfallon <liam.fallon@est.tech> * Update comment on refreshPR Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix failing e2e test Signed-off-by: liamfallon <liam.fallon@est.tech> --------- Signed-off-by: liamfallon <liam.fallon@est.tech>
1 parent f6fa8e2 commit f407407

6 files changed

Lines changed: 919 additions & 37 deletions

File tree

pkg/engine/engine.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ func (cad *cadEngine) CreatePackageRevision(ctx context.Context, repositoryObj *
238238
return nil, fmt.Errorf("failed to close package revision draft: %w", err)
239239
}
240240

241+
if err := cad.updatePkgRevMeta(ctx, repoPkgRev, newPr); err != nil {
242+
return nil, err
243+
}
244+
241245
return repoPkgRev, nil
242246
}
243247

@@ -282,7 +286,13 @@ func validateCloneTask(obj *porchapi.PackageRevision, existingRevs []repository.
282286
return nil
283287
}
284288

285-
func (cad *cadEngine) UpdatePackageRevision(ctx context.Context, version int, repositoryObj *configapi.Repository, repoPr repository.PackageRevision, oldObj, newObj *porchapi.PackageRevision, parent repository.PackageRevision) (repository.PackageRevision, error) {
289+
func (cad *cadEngine) UpdatePackageRevision(
290+
ctx context.Context,
291+
version int,
292+
repositoryObj *configapi.Repository,
293+
repoPr repository.PackageRevision,
294+
oldObj, newObj *porchapi.PackageRevision,
295+
parent repository.PackageRevision) (repository.PackageRevision, error) {
286296
ctx, span := tracer.Start(ctx, "cadEngine::UpdatePackageRevision", trace.WithAttributes())
287297
defer span.End()
288298

@@ -364,8 +374,12 @@ func (cad *cadEngine) UpdatePackageRevision(ctx context.Context, version int, re
364374
return nil, err
365375
}
366376

367-
if err := cad.taskHandler.DoPRMutations(ctx, repoPr, oldObj, newObj, draft); err != nil {
368-
return nil, err
377+
renderErr := cad.taskHandler.DoPRMutations(ctx, repoPr, oldObj, newObj, draft)
378+
379+
if renderErr != nil {
380+
if result, err := handleMutationError(renderErr, newObj); err != nil {
381+
return result, err
382+
}
369383
}
370384

371385
if err := draft.UpdateLifecycle(ctx, newObj.Spec.Lifecycle); err != nil {
@@ -503,8 +517,8 @@ func (cad *cadEngine) UpdatePackageResources(ctx context.Context, repositoryObj
503517
renderStatus, renderErr := cad.taskHandler.DoPRResourceMutations(ctx, pr2Update, draft, oldRes, newRes)
504518

505519
if renderErr != nil {
506-
if result, status, err := handleMutationError(renderErr, renderStatus, rev); err != nil {
507-
return result, status, err
520+
if result, err := handleMutationError(renderErr, rev); err != nil {
521+
return result, renderStatus, err
508522
}
509523
}
510524

@@ -577,25 +591,25 @@ func (cad *cadEngine) UpdatePackageResourcesWithoutRender(ctx context.Context, r
577591
// handleMutationError decides whether to bail out or allow push-on-render-failure.
578592
// Returns a non-nil error to signal the caller should return immediately.
579593
// Returns a nil error to signal the caller should proceed to close the draft.
580-
func handleMutationError(renderErr error, renderStatus *porchapi.RenderStatus, rev *porchapi.PackageRevision) (repository.PackageRevision, *porchapi.RenderStatus, error) {
594+
func handleMutationError(renderErr error, rev *porchapi.PackageRevision) (repository.PackageRevision, error) {
581595
// If persistence failed after render, never push — draft contents are stale.
582596
var persistErr *task.RenderPersistError
583597
if errors.As(renderErr, &persistErr) {
584-
return nil, renderStatus, renderErr
598+
return nil, renderErr
585599
}
586600

587601
// Only apply push-on-render-failure for actual render errors.
588602
// For any other error (e.g. draft.UpdateResources failure when render succeeded),
589603
// never push — the draft contents may be stale.
590604
var renderError *task.RenderError
591605
if !errors.As(renderErr, &renderError) {
592-
return nil, renderStatus, renderErr
606+
return nil, renderErr
593607
}
594608

595609
if !rev.IsPushOnRenderFailure() {
596-
return nil, renderStatus, fmt.Errorf("error rendering package in kpt function pipeline. "+
610+
return nil, fmt.Errorf("error rendering package in kpt function pipeline. "+
597611
"Package NOT pushed to remote. Fix locally (until 'kpt fn render' succeeds) and retry. Details: %w", renderErr)
598612
}
599613

600-
return nil, renderStatus, nil
614+
return nil, nil
601615
}

0 commit comments

Comments
 (0)