Skip to content

Commit 14b2f49

Browse files
vdemeesterclaude
andcommitted
fix(pipelinerun): add missing sort logic for childRefs array
The previous cherry-pick (tektoncd#9312) only included the test file changes (removing cmpopts.SortSlices) but not the actual sorting logic in pipelinerun.go. This caused tests to fail because they expected sorted output but the production code wasn't sorting. This commit adds the missing sort.Slice call that sorts childRefs by PipelineTaskName, then Name, then Kind to prevent excessive status updates caused by unordered arrays. Cherry-pick of the missing part from tektoncd#9295. Signed-off-by: Vincent Demeester <vdemeest@redhat.com> Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ce3a889 commit 14b2f49

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/reconciler/pipelinerun/pipelinerun.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"path/filepath"
2525
"reflect"
2626
"regexp"
27+
"sort"
2728
"strings"
2829
"time"
2930

@@ -1748,6 +1749,18 @@ func updatePipelineRunStatusFromChildRefs(logger *zap.SugaredLogger, pr *v1.Pipe
17481749
for k := range childRefByName {
17491750
newChildRefs = append(newChildRefs, *childRefByName[k])
17501751
}
1752+
1753+
// sorting childRef in a specific order can greatly avoid
1754+
// meaningless updates of status caused by unordered arrays.
1755+
sort.Slice(newChildRefs, func(i, j int) bool {
1756+
if newChildRefs[i].PipelineTaskName == newChildRefs[j].PipelineTaskName {
1757+
if newChildRefs[i].Name == newChildRefs[j].Name {
1758+
return newChildRefs[i].Kind < newChildRefs[j].Kind
1759+
}
1760+
return newChildRefs[i].Name < newChildRefs[j].Name
1761+
}
1762+
return newChildRefs[i].PipelineTaskName < newChildRefs[j].PipelineTaskName
1763+
})
17511764
pr.Status.ChildReferences = newChildRefs
17521765
}
17531766

0 commit comments

Comments
 (0)