Skip to content

Commit

Permalink
Fix PipelineRunStatus Reconciler Updates and Tests for EmbeddedStatus…
Browse files Browse the repository at this point in the history
… Switch

This commit fixes the updates for reconciling PipelineRunStatus when switching
the DefaultEmbeddedStatus from `Full` to `Minimal`. The prior runs or taskruns
status would not have been reset before this change. The related emtpy runs and
taskruns are removed because these fields will be `nil`. It also applies for the
switch from `Minimal` to `Full`.
  • Loading branch information
JeromeJu committed Jan 17, 2023
1 parent c752a36 commit 65bbb1e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,15 +1331,20 @@ func (c *Reconciler) updatePipelineRunStatusFromInformer(ctx context.Context, pr

func updatePipelineRunStatusFromChildObjects(ctx context.Context, logger *zap.SugaredLogger, pr *v1beta1.PipelineRun, taskRuns []*v1beta1.TaskRun, runObjects []v1beta1.RunObject) error {
cfg := config.FromContextOrDefaults(ctx)
fullEmbedded := cfg.FeatureFlags.EmbeddedStatus == config.FullEmbeddedStatus || cfg.FeatureFlags.EmbeddedStatus == config.BothEmbeddedStatus
minimalEmbedded := cfg.FeatureFlags.EmbeddedStatus == config.MinimalEmbeddedStatus || cfg.FeatureFlags.EmbeddedStatus == config.BothEmbeddedStatus

if minimalEmbedded {
updatePipelineRunStatusFromChildRefs(logger, pr, taskRuns, runObjects)
}
if fullEmbedded {
switch cfg.FeatureFlags.EmbeddedStatus {
case config.FullEmbeddedStatus:
pr.Status.ChildReferences = nil
updatePipelineRunStatusFromTaskRuns(logger, pr, taskRuns)
updatePipelineRunStatusFromCustomRunsOrRuns(logger, pr, runObjects)
case config.BothEmbeddedStatus:
updatePipelineRunStatusFromTaskRuns(logger, pr, taskRuns)
updatePipelineRunStatusFromCustomRunsOrRuns(logger, pr, runObjects)
updatePipelineRunStatusFromChildRefs(logger, pr, taskRuns, runObjects)
default:
pr.Status.Runs = nil
pr.Status.TaskRuns = nil
updatePipelineRunStatusFromChildRefs(logger, pr, taskRuns, runObjects)
}

return validateChildObjectsInPipelineRunStatus(ctx, pr.Status)
Expand All @@ -1350,6 +1355,8 @@ func validateChildObjectsInPipelineRunStatus(ctx context.Context, prs v1beta1.Pi

var err error

// TODO: Integration test to be introduced for switching in embeddedStatus
// https://github.com/tektoncd/pipeline/issues/5999
// Verify that we don't populate child references for "full"
if cfg.FeatureFlags.EmbeddedStatus == config.FullEmbeddedStatus && len(prs.ChildReferences) > 0 {
return fmt.Errorf("expected no ChildReferences with embedded-status=full, but found %d", len(prs.ChildReferences))
Expand Down

0 comments on commit 65bbb1e

Please sign in to comment.