fix(k8s): cap buildLogCache size to bound memory on failure bursts (bug-bash #2)#230
Merged
Merged
Conversation
e2d04dc to
dba8173
Compare
…ug-bash #2) buildLogCache snapshots kaniko build logs of FAILED builds for the failure autopsy. It was TTL-bounded (30m) and swept stale entries on each new failure — but had NO size cap. A burst of failing builds inside one TTL window (a broken base image, a wedged registry, a fork-bomb of bad deploys) accumulates one ≤200-line snapshot per failure with no ceiling: unbounded memory growth on a long-lived api pod. Add buildLogCacheMaxEntries=256 and capBuildLogCacheSize(), called evict-after-store from snapshotBuildLogs. When a store pushes the live count past the cap, evict oldest-first (a recent failure's autopsy is far likelier to be read than one from hundreds of failures ago). sync.Map has no length, so we snapshot keys+times in one Range pass, sort by capturedAt, and delete the excess oldest. Tests: TestCapBuildLogCacheSize_EvictsOldestOverCap (over-cap → newest survive, oldest evicted), TestCapBuildLogCacheSize_NoOpUnderCap. Both new funcs 100% covered; verified locally. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dba8173 to
258f60d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
buildLogCache(k8s provider) snapshots kaniko build logs of failed builds so the failure autopsy can read them after the kaniko Job's 300s TTL reaps the pod. It was TTL-bounded (30m) and swept stale entries on each new failure — but had no size cap.A burst of failing builds inside one TTL window (broken base image, wedged registry, repeated bad deploys) accumulates one ≤200-line snapshot per failure with no ceiling → unbounded memory growth on a long-lived api pod.
Fix
buildLogCacheMaxEntries = 256capBuildLogCacheSize()— called evict-after-store fromsnapshotBuildLogs. When a store pushes the live count past the cap, evict oldest-first (a recent failure's autopsy is far likelier to be read).sync.Maphas no length, so snapshot keys+times in oneRange, sort bycapturedAt, delete the excess oldest.Coverage
🤖 Generated with Claude Code