ITADN

(tutorial) CronJob sample: inconsistent nil StartTime comparator after sort → slices migration

#5740Opencamilamacedo86 创建于 2026-06-10
help wantedkind/bug
C
camilamacedo86commented
## What broke? What's expected? PR #5265 replaced `sort.Slice` with `slices.SortStableFunc` in the CronJob tutorial, but the new comparator breaks the contract `cmp(a, b) == -cmp(b, a)`: - `cmp(nil, non-nil)` returns `1` - `cmp(non-nil, nil)` returns `0` (both `Before` checks are false) It also flipped the original behavior: jobs with nil `StartTime` used to sort first (pruned first by the history limit); now they tend to sort last and are kept instead. Expected: a consistent comparator preserving nil-first ordering, e.g.: ```go switch { case aStartTime == nil && bStartTime == nil: return 0 case aStartTime == nil: return -1 case bStartTime == nil: return 1 case aStartTime.Before(bStartTime): return -1 case bStartTime.Before(aStartTime): return 1 default: return 0 } ``` ## Affected files (2 call sites each: failedJobs/successfulJobs) - `docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go` - `docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go` - `hack/docs/internal/cronjob-tutorial/controller_implementation.go` (generator template — fix together and run `make generate-docs`) Not caught by CI: the tutorial tests don't cover the pruning path. ## KubeBuilder (CLI) Version master (introduced by #5265, commit a0f3e729e)
1 条评论