Skip to content

Commit f9e7241

Browse files
vdemeesterclaude
andcommitted
fix(pipelinerun): add missing sort logic for childRefs array
The previous cherry-pick (#9314) 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 #9295. Signed-off-by: Vincent Demeester <vdemeest@redhat.com> Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 04f74ed commit f9e7241

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

2930
"k8s.io/apimachinery/pkg/util/wait"
@@ -1899,6 +1900,18 @@ func updatePipelineRunStatusFromChildRefs(logger *zap.SugaredLogger, pr *v1.Pipe
18991900
for k := range childRefByName {
19001901
newChildRefs = append(newChildRefs, *childRefByName[k])
19011902
}
1903+
1904+
// sorting childRef in a specific order can greatly avoid
1905+
// meaningless updates of status caused by unordered arrays.
1906+
sort.Slice(newChildRefs, func(i, j int) bool {
1907+
if newChildRefs[i].PipelineTaskName == newChildRefs[j].PipelineTaskName {
1908+
if newChildRefs[i].Name == newChildRefs[j].Name {
1909+
return newChildRefs[i].Kind < newChildRefs[j].Kind
1910+
}
1911+
return newChildRefs[i].Name < newChildRefs[j].Name
1912+
}
1913+
return newChildRefs[i].PipelineTaskName < newChildRefs[j].PipelineTaskName
1914+
})
19021915
pr.Status.ChildReferences = newChildRefs
19031916
}
19041917

0 commit comments

Comments
 (0)