Skip to content

Commit 30b5e96

Browse files
JeromeJutekton-robot
authored andcommitted
Fix PipelineRunStatus Reconciler Updates and Tests for EmbeddedStatus Switch
This commit fixes the updates for reconciling PipelineRunStatus when switching the EmbeddedStatus feature flag. It resets the status.runs and status.taskruns to nil with minimal EmbeddedStatus and status.childReferences to nil with full EmbeddedStatus. Prior to this change, the childReferences runs and taskruns in pipelineRunStatus would not have been reset to nil and could have led to validation error when the feature flag is being switched. The following issue could help prevent such bugs in the future: Integration tests for changing feature flags #5999
1 parent 9d39421 commit 30b5e96

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

pkg/reconciler/pipelinerun/pipelinerun.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -1331,20 +1331,32 @@ func (c *Reconciler) updatePipelineRunStatusFromInformer(ctx context.Context, pr
13311331

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

1337-
if minimalEmbedded {
1338-
updatePipelineRunStatusFromChildRefs(logger, pr, taskRuns, runObjects)
1339-
}
1340-
if fullEmbedded {
1335+
switch cfg.FeatureFlags.EmbeddedStatus {
1336+
case config.FullEmbeddedStatus:
1337+
// Clear any ChildReferences that are present.
1338+
// This can occur if the value of "embedded-status" was modified during PipelineRun execution.
1339+
pr.Status.ChildReferences = nil
1340+
updatePipelineRunStatusFromTaskRuns(logger, pr, taskRuns)
1341+
updatePipelineRunStatusFromCustomRunsOrRuns(logger, pr, runObjects)
1342+
case config.BothEmbeddedStatus:
13411343
updatePipelineRunStatusFromTaskRuns(logger, pr, taskRuns)
13421344
updatePipelineRunStatusFromCustomRunsOrRuns(logger, pr, runObjects)
1345+
updatePipelineRunStatusFromChildRefs(logger, pr, taskRuns, runObjects)
1346+
default:
1347+
// Clear any TaskRuns and Runs present in the status.
1348+
// This can occur if the value of "embedded-status" was modified during PipelineRun execution.
1349+
pr.Status.Runs = nil
1350+
pr.Status.TaskRuns = nil
1351+
updatePipelineRunStatusFromChildRefs(logger, pr, taskRuns, runObjects)
13431352
}
13441353

13451354
return validateChildObjectsInPipelineRunStatus(ctx, pr.Status)
13461355
}
13471356

1357+
// TODO: https://github.com/tektoncd/pipeline/issues/5999 integration tests for changing
1358+
// feature flags could help prevent validation errors when the feature-flag is being switched.
1359+
// In such case, the error could keep the pipelineRun run indefinitely.
13481360
func validateChildObjectsInPipelineRunStatus(ctx context.Context, prs v1beta1.PipelineRunStatus) error {
13491361
cfg := config.FromContextOrDefaults(ctx)
13501362

pkg/reconciler/pipelinerun/pipelinerun_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -5161,7 +5161,7 @@ status:
51615161
expectedPr = expectedPrMinimalStatus
51625162
}
51635163

5164-
if d := cmp.Diff(expectedPr, reconciledRun, ignoreResourceVersion, ignoreLastTransitionTime, ignoreCompletionTime, ignoreStartTime); d != "" {
5164+
if d := cmp.Diff(expectedPr, reconciledRun, ignoreResourceVersion, ignoreLastTransitionTime, ignoreCompletionTime, ignoreStartTime, cmpopts.EquateEmpty()); d != "" {
51655165
t.Errorf("expected to see pipeline run results created. Diff %s", diff.PrintWantGot(d))
51665166
}
51675167
}
@@ -5482,7 +5482,7 @@ status:
54825482
expectedPr = expectedPrMinimalStatus
54835483
}
54845484

5485-
if d := cmp.Diff(expectedPr, reconciledRun, ignoreResourceVersion, ignoreLastTransitionTime, ignoreCompletionTime, ignoreStartTime); d != "" {
5485+
if d := cmp.Diff(expectedPr, reconciledRun, ignoreResourceVersion, ignoreLastTransitionTime, ignoreCompletionTime, ignoreStartTime, cmpopts.EquateEmpty()); d != "" {
54865486
t.Errorf("expected to see pipeline run results created. Diff %s", diff.PrintWantGot(d))
54875487
}
54885488
}
@@ -8947,7 +8947,7 @@ spec:
89478947
if err != nil {
89488948
t.Fatalf("Got an error getting reconciled run out of fake client: %s", err)
89498949
}
8950-
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, ignoreFinallyStartTime); d != "" {
8950+
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, ignoreFinallyStartTime, cmpopts.EquateEmpty()); d != "" {
89518951
t.Errorf("expected PipelineRun was not created. Diff %s", diff.PrintWantGot(d))
89528952
}
89538953
})
@@ -9555,7 +9555,7 @@ spec:
95559555
if err != nil {
95569556
t.Fatalf("Got an error getting reconciled run out of fake client: %s", err)
95579557
}
9558-
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, ignoreFinallyStartTime); d != "" {
9558+
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, ignoreFinallyStartTime, cmpopts.EquateEmpty()); d != "" {
95599559
t.Errorf("expected PipelineRun was not created. Diff %s", diff.PrintWantGot(d))
95609560
}
95619561
})
@@ -10015,7 +10015,7 @@ status:
1001510015
if err != nil {
1001610016
t.Fatalf("Got an error getting reconciled run out of fake client: %s", err)
1001710017
}
10018-
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, cmpopts.SortSlices(lessChildReferences)); d != "" {
10018+
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, cmpopts.SortSlices(lessChildReferences), cmpopts.EquateEmpty()); d != "" {
1001910019
t.Errorf("expected PipelineRun was not created. Diff %s", diff.PrintWantGot(d))
1002010020
}
1002110021
})
@@ -10549,7 +10549,7 @@ spec:
1054910549
if err != nil {
1055010550
t.Fatalf("Got an error getting reconciled run out of fake client: %s", err)
1055110551
}
10552-
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, ignoreFinallyStartTime); d != "" {
10552+
if d := cmp.Diff(tt.expectedPipelineRun, pipelineRun, ignoreResourceVersion, ignoreTypeMeta, ignoreLastTransitionTime, ignoreStartTime, ignoreFinallyStartTime, cmpopts.EquateEmpty()); d != "" {
1055310553
t.Errorf("expected PipelineRun was not created. Diff %s", diff.PrintWantGot(d))
1055410554
}
1055510555
})

0 commit comments

Comments
 (0)