Repository navigation
feat: replace the bash cleaner with a Go eviction manager (stage 1) - #197
Draft
masontikhonov wants to merge 101 commits into
Draft
masontikhonov wants to merge 101 commits into
masontikhonov wants to merge 101 commits into
Conversation
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Add a Makefile with test, image, facts and integration targets, and an integration test harness that runs the dind image privileged on a 1G loop-mounted ext4 data root formatted by a helper image built from the image under test. Remove the stale cleaner/dind-cleaner/test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BuildKit counts the filesystem's root reserve as free space, so the backstop rule as first designed would act only at about 0% free as df shows it. Confirmed against Docker 29.9.3. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Add integration tests that check, against the dind image's Docker daemon: the event stream for container, image and volume actions; registry digests after pull, build, import, load and push; build-cache prune with an until filter and with a space bound; and that the BuildKit backstop rule, with the root reserve added to minFreeSpace, stays inert above its level and acts below it. Add BuildKit, classic-build, build-cache and root-reserve helpers to the harness, log cleanup failures, and keep waiting when inspecting a starting pod fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… run Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s of removed containers Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wire the internal packages into the binary, build it from the module's cmd and internal trees, and drop glog. An integration test runs the binary against a real daemon. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run.sh writes the effective dockerd config with dind-cleaner daemon-config, starts dockerd with it, supervises dind-cleaner run with restarts, and on SIGTERM waits for the cleaner's shutdown routine within its timeout. The old cleaner scripts and their metrics are gone. Lifecycle integration tests cover the effective config, the disabled cleaner, restarts, shutdown and removal of the old cleaner's files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A SIGTERM that reaches the supervisor between its loop check and the cleaner's start is now forwarded to the new cleaner. The shutdown trap checks /proc for the supervisor instead of kill -0, so a supervisor that exited early (cleaner disabled) is neither waited for nor confused with a reused PID. The lifecycle tests assert both, and that a restarted cleaner keeps the same --pod-start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wn path Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ail it Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… vacuous checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd Tests sections Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Docker adapter handed events to the tracker over two channels fed by a goroutine, and the tracker drained them in three select branches, with a nested select to tell a failed stream from one that ended. Events now returns an iter.Seq2 that yields each event and, if the stream breaks, the error last. The adapter's goroutine and channels are gone, the tracker's consume is a for-range loop, and Replay ranges over the same sequence with an until. Stopping the loop cancels the request. A stream that ends because the cleaner is stopping is no longer logged as failed. The integration adapter test follows the new shape; it is compiled, not run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- report.NothingLeft holds the policy's counts instead of six fields that the manager copied over one by one. - The manager reads free space through diskStat, which logs a failure. "cannot read free space" was logged from seven places, three of them only to log the one error evict can return. - policy.Tier2 returns its queue as one slice. It returned three, and its only caller joined them at once. - docker.Client.Snapshot is built from images, volumes and buildCache, each with a deferred cancel like the rest of the file, where it repeated the timeout handling inline three times. call is now withTimeout, which says what it returns. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Structs declare one field per line. Config had up to seven on one, and the same habit was in disk.Stat, the report's summaries and several small types. - The two levelVars literals name their fields; they ended in a bare false and true. - config.Load returns its notes next to the Config, as Resolve already did. Notes are not configuration, and the command now logs both lists the same way. - A local named min no longer shadows the builtin. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The config package had four type names for two ideas. Level and Levels are what was configured, a percentage or a size. Triple held one resource's resolved numbers, Thresholds the resolved pair for space and inodes, and the start summary kept a Thresholds in a field named Levels. Levels are now what is configured and thresholds what they resolve to: Triple becomes Thresholds, the pair becomes DiskThresholds, and the start summary's field is Thresholds. The log fields are unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Each write created state.json.tmp-<random>. A cleaner killed between creating that file and renaming it left it on the persistent volume, and nothing ever removed it, so a volume could collect them over many pods. Saves are serialized, so one name is enough. The next write truncates whatever a killed cleaner left under that name and renames it into place. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- usage.Load returns nil with an error. It returned a usable log next to a non-nil error and the command relied on that; the fallback to an empty log is now the caller's, in loadUsage, with a test. - The manager declares the Docker interface it needs, as the tracker already did, and the ten-method docker.API next to its implementation is gone. - RemoveContainer takes RemoveContainerOptions, named as Docker's own client names them, in place of two adjacent booleans. - Docker's words have names: the event types and actions come from moby's constants, the container state and the cache record types the policy compares are constants in inventory. - removeAllContainers and removeExportImages return a plain int. They named the result and then returned it explicitly. - In the command, the dispatcher is dispatch, no longer run next to runCommand, and the usage log is not held in a variable named log. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two rules, applied once on the final shape of the code, tests included. Names are words. Receivers, parameters, locals and unexported fields that were one or two letters are spelled out: cli for the Docker client, log for the usage log, candidate, pressure, input, snapshot, thresholds, and manager, fake, recorder and clock in the tests. Loop indices, counts named n, and err, ok and ctx stay. Two types changed so that a variable does not carry its type's name: state is inputState and loader is envLoader. Booleans read as is or has: Config.IsEnabled and IsDryRun, DiskThresholds.HasInodes, Volume.IsAnonymous, CacheRecord.IsInUse and IsShared, the Pressure fields, Meta.IsFound and IsSamePod, Log.IsDirty, Candidate.IncludesShared, and the manager's isIdle, isWoken and wasBelowEmergency. Fields that mirror Docker's own names (All, Enabled, Force, RemoveVolumes) keep them. Renames only; the log output does not change. The integration tests are renamed with the rest and compile. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The workflow runs go vet and the tests but no linter. The module gets a .golangci.yml with the default linters plus revive, gocritic, unparam and predeclared, over the integration tests' code too, and make lint runs it. Errors of Close, os.Remove and printing to stdout are not checked, as usual, and a test helper may take *testing.T before its context. What it found is fixed: a test helper's parameter named min, a parameter that was always 1, and an event sequence ranged without looking at its error. The workflow step itself is left to the CI work. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ADD . /dind put the Go sources and tests, the Makefile and whatever else the build context held into the production image. At run time the image needs run.sh, docker/ and monitor/, so those are copied by name. The old cleaner's scripts, which were the reason for copying everything, are gone. .git, .github and the top-level Markdown files are left out of the build context as well. Not built here: the base images are private. make integration builds the image and covers it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The cleaner mapped DISK_USAGE_THRESHOLD and INODES_USAGE_THRESHOLD to levels, let DISABLE_CLEANER_AGENT without CLEAN_DOCKER turn it off, ignored the period and retain variables, and reported all of them on one startup log line. About a third of the config package existed for that. The image is only released together with the chart, which sets the new variables in its default values and documents the change. Under that chart the mapping could never apply. And once the chart stops setting CLEAN_DOCKER, the off switch would have turned the whole cleaner off for someone who had only disabled the old mid-run agent. None of the eight variables is read any more, and none is mentioned in the log. An unrecognized CLEANER_ENABLED value now leaves the cleaner on with a note; it used to hand the decision to the old variables. The README's section on them and the design's table are gone; the design records the decision. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CLEANER_ENABLED was a boolean that is true by default. A boolean variable should be off when unset, so the switch is named for what setting it does: CLEANER_DISABLED, off by default. Config.IsEnabled is Config.IsDisabled, for the same reason. It is parsed like the other switch, CLEANER_DRY_RUN: on for any non-empty value other than false or 0. The note for an unrecognized value goes with that. CLEANER_ENABLED is not read; it was never released. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CLEANER_DISABLED and CLEANER_DRY_RUN were on for any non-empty value other than false or 0, so a mistyped false turned the cleaner off. Both now accept true, 1, false and 0, ignoring case and surrounding spaces. Any other value is noted in the log and leaves the switch off. For dry run this cuts the other way too: CLEANER_DRY_RUN=yes, which the old cleaner took as a dry run, is no longer one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The module sat in cleaner/dind-cleaner because on master it was one Go helper among the bash cleaner's scripts. The scripts are gone, so cleaner/ held nothing but the module and its README. Both now live in dind-cleaner, named like the module. The Dockerfile, the Makefile, the unit-test workflow and the Dependabot configuration point at the new path. The module path and the binary's name do not change. The image was not built here; make integration is the first check of the new COPY paths. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
/e2e |
…C rule "Effective config" did not say where the file comes from, and was untrue when dockerd rejects it and starts with the mounted file. "Backstop" named the rule's role in the design, not what it does. The log messages and the README section heading change with the names. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
"Fact" was the design's shorthand for a fact about Docker the cleaner relies on, and said nothing to a reader of the tests. The file, the test names, the helper and the make target (now docker-behaviour) are renamed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
harness_test.go becomes environment_test.go and TestHarnessSmoke becomes TestEnvironmentSmoke, matching the Env type. Each integration test file now opens with a comment that says what it tests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
IT stood for "integration test" and was never spelled out. The Makefile variables, the environment variables the tests read, the local image tags and the names of the Docker resources the tests create now say TEST. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
/e2e |
The helper image was built with `apk add e2fsprogs` on top of the image under test, which fails since the base became a DHI image with no apk: `make image` could not finish. The image already ships mkfs.ext4, so the helper image, TEST_MKFS_IMAGE and DIND_TEST_MKFS_IMAGE are removed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
/e2e |
With TEST_IMAGE set, `make integration` and `make docker-behaviour` run against that image and build nothing. CI uses it to test the image the pipeline has already built. Without it they build dind-test:local as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The tests reached each pod's Docker API on a port published on the daemon's loopback address, which a test process in a container of the same daemon cannot reach. In that case the container now joins the test network and uses the pod's address there, so the suite runs in a CI step that only has the Docker socket. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
TestDockerBuildCacheChain asserted that a bounded prune deletes every record listed as unused and last used before the bound. Docker keeps such a record while newer records are built on it, so the test failed in every run. The cleaner does not depend on that: it skips a batch whose prune deletes nothing. The test now checks the two things the cleaner relies on: a bounded prune deletes nothing used after its bound, and the kept records go with the records built on them once a bound takes those in. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
In the integration tests a Pod was a privileged container of the image under test, which is not what the word says. It is now DindContainer, started with StartDindContainer, and its Docker name is dind-test-container-<id>-<n>. "Pod" stays where it is the cleaner's own term: the --pod-start flag, the pods file and the state file's podStart. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The build stage copies dind-cleaner/cmd and dind-cleaner/internal whole, so a change to a unit test re-ran go build although the binary cannot change. .claude holds local tool settings that no build needs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
/e2e |
…eaner-redesign-stage-1
|
/e2e |
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
Stage 1 of the dind cleaner redesign: the bash cleaner (
cleaner-agent.sh,docker-clean.sh,docker-clean-sigterm.sh,functions.sh, the retain and period settings) is replaced by one Go process,dind-cleaner, that owns every eviction.Draft: the integration suite has run on this head and one Docker behaviour test fails (see Verification).
This image must be released together with the chart change (see Configuration): the cleaner no longer reads any of the variables the chart sets today.
Behaviour
minFree(20% by default). A pass removes the least recently used cache first, across images, volumes and build cache, and stops attargetFree(25%).dfshows as available, which leaves out the filesystem's root reserve. On ext4 (5% reserve) a pass therefore starts above 75% used and stops at 70%; on a filesystem with no reserve, at 80% and 75%.emergencyFree(10%) with tier 1 empty, and removes this build's idle cache in order of harm: recreatable cache, exited containers, then unpushed local images.CLEANER_KEEP_IMAGES,CLEANER_KEEP_VOLUMES).daemon.jsonwith one added rule, the BuildKit low-space GC rule, which acts at half the emergency level plus the root reserve. It replaces all of Docker's default GC rules, including the one that removes cache mounts, local sources and git checkouts unused for 48 hours. A customer's ownbuilder.gcwins.run.shchecks the generateddaemon.jsonwithdockerd --validateand keeps the mounted file ifdockerdrejects it, supervises the cleaner (restart on failure) and gives it a bounded shutdown routine on SIGTERM. A removal in flight at SIGTERM is abandoned, and the shutdown routine has its own deadline.CLEANER_MAX_UNUSED_AGE_HOURS, off by default; meant forlocalstorage.CLEANER_DRY_RUN: logs what it would remove and changes nothing but its own state file. It generates nodaemon.jsoneither, sodockerdkeeps Docker's default builder GC.Configuration
New variables, all optional, documented in
dind-cleaner/README.md:CLEANER_DISABLED,CLEANER_DRY_RUN,CLEANER_SPACE_{MIN,TARGET,EMERGENCY}_FREE,CLEANER_INODES_{MIN,TARGET,EMERGENCY}_FREE,CLEANER_KEEP_IMAGES,CLEANER_KEEP_VOLUMES,CLEANER_MAX_UNUSED_AGE_HOURS, and the_SECONDStiming variables.CLEANER_DISABLEDis set. No boolean is on by default.CLEANER_DISABLEDandCLEANER_DRY_RUNaccepttrue,1,falseand0. Any other value is logged and leaves the switch off.The old cleaner's variables are not read, and the cleaner does not mention them in its log. The chart's
runtime.dind.envdefaults have to be replaced, and customers who set any of these in their own values have to move:DISK_USAGE_THRESHOLDCLEANER_SPACE_MIN_FREE,CLEANER_SPACE_TARGET_FREEandCLEANER_SPACE_EMERGENCY_FREE, all three. The old default0.8corresponds to20%,25%and10%. In general: min = 1 − value, target = min + 5 points, emergency = min / 2. The new levels count the spacedfshows as available, so on ext4 they act five points earlier than the old threshold did.INODES_USAGE_THRESHOLDCLEANER_INODES_MIN_FREE,CLEANER_INODES_TARGET_FREEandCLEANER_INODES_EMERGENCY_FREE, percentages only, by the same rule.CLEAN_DOCKER,DISABLE_CLEANER_AGENTCLEANER_DISABLED=trueturns the cleaner off; it is on when unset. There is one cleaner now, not an agent and a shutdown cleanup.IMAGE_RETAIN_PERIOD,VOLUMES_RETAIN_PERIODCLEANER_MAX_UNUSED_AGE_HOURSsets an age limit for those who want one (recommended onlocalstorage).CLEAN_PERIOD_SECONDS,CLEAN_PERIOD_BUILDSWhat changes for operators
CLEANER_DRY_RUNis strict. The old cleaner took any non-empty value as a dry run. A value such asyesis now logged and is not a dry run, so the cleaner removes things.docker_volume_last_cleaned_ts,docker_volume_last_pruned_tsanddocker_volume_cleaner_agent_actions_*are gone until stage 2. An alert of the formtime() - docker_volume_last_cleaned_ts > Xgoes to no-data; it does not fire. Disk and inode usage metrics are unchanged.events/directory at startup (not in dry run). If a runtime is rolled back to the previous image, the old shutdown cleanup finds no event history and removes every image older thanIMAGE_RETAIN_PERIODexcept those used in that one build. That is a one-time loss of image cache per volume.msg=evicted, start and end summaries);dind-cleaner/README.mdhas a section on reading them.run.sh,docker/andmonitor/under/dind, not the whole repository.Tests
go vet,go test -race,bash -n run.sh) and bymake test.make lintrunsgolangci-lintwith the module's.golangci.yml(default linters plusrevive,gocritic,unparam,predeclared), over the integration tests' code too. It is not a workflow step yet.make integration(25 tests: Docker behaviour tests, which check what the design relies on in Docker and BuildKit with the cleaner off, and lifecycle and eviction scenarios).make integration TEST_IMAGE=<image>tests an existing image and builds nothing (2774a43), and the tests also run from inside a container that only has the Docker socket (a4ed007). codefresh-io/pipelines#625 uses both to run the suite, the unit tests andmake lintin the Codefresh pipeline. They ran there at a4ed007; until that PR is merged, the pipeline has to be pointed at its branch.Documents
docs/superpowers/specs/2026-11-27-dind-cleaner-redesign-design.md. Its "Changes after approval" section has a dated line for every decision made since, including those from the review of this PR.docs/superpowers/specs/2026-11-27-dind-cleaner-redesign-comparison.md.dind-cleaner/README.md.Review
The PR was reviewed at 1487be5. The findings are addressed in the 37 commits after it, up to c79b1f1:
daemon.jsonno longer blocks the pod; dry run changes nothing; SIGTERM handling; idling when nothing can be evicted; volume events on their own stream; the BuildKit low-space GC rule on a volume filled into its root reserve; levels set together;USE_DIND_IMAGES_LIBwith no library; bounded build-cache prunes under inode pressure; the state file's temp file; theDockerfile.is/hasbooleans throughout; the Go module and its README moved fromcleaner/dind-cleanerto a top-leveldind-cleanerdirectory, named like the module.CLEANER_DISABLED, and both switches are strict. The filedockerdstarts with is called the generateddaemon.json, and the rule added to it the BuildKit low-space GC rule (1abd813: names, log messages and the README only). The fact tests are called Docker behaviour tests:TestDocker…inintegration/docker_behaviour_test.go, run bymake docker-behaviour(bb764c8). The tests' shared setup isintegration/environment_test.go, and each integration test file opens with a comment that says what it tests (17e71ec). The integration tests'ITprefix is spelledTEST:TEST_IMAGE,DIND_TEST_IMAGE, thedind-test:localimage anddind-test-*resources (da08d15).Verification
gofmt,go vet(with and without the integration tag),go test -racefor every package andgolangci-lintpass. The behaviour fixes in the Go code have unit tests that fail without them.run.shand theDockerfileare exercised by the integration run below.make integration: 24 of 25 tests passed up to a4ed007; the one failure was a wrong test, rewritten in c3d4068. The pods run the image'sdockerd29.10.1. The suite ran in full on Docker Desktop (engine 29.9.3), on a local Linuxdockerd29.10.1, and at a4ed007 in Codefresh with the steps from codefresh-io/pipelines#625, with the same result each time. At c3d4068 only the rewritten test has been run, locally; it passes.TestDockerBuildCacheChainfailed in every run (7 of 7) up to a4ed007. It asserted that a prune withuntildeletes every record that Docker lists as unused and last used before the bound, but Docker keeps such a record while newer records are built on it. The cleaner does not depend on that: it skips a build-cache batch whose prune deletes nothing, at the cost of one prune call in a pass. Since c3d4068 the test checks what the cleaner relies on: the prune deletes nothing used after its bound, and the kept records are deleted with the records built on them once a bound takes those in.TestDockerBuildCachePruneBoundfailed once in 7 runs. The newest record was listed while BuildKit still held it in use, and its ID was gone after the prune although the prune did not report deleting it. This looks like a race in the test; it is not confirmed.make imagecould not build the test helper image on the DHI base (apk: not found). The image under test shipsmkfs.ext4, so the helper is removed (836b057).Known limits and open points
localstorage, a node filled by other volumes puts every pod on it into tier 2.localstorage, the node agent ofdind-volume-utilsdeletes idle volumes at the level where the cleaner starts evicting, and the cleaner checks far more often, so running builds' cache is trimmed before colder idle volumes go. What to advise operators is still open.FROMbase emits no Docker event, so it ages as unused.TestDockerBuildCacheChaincovers this.+ 2second kill margin and the 0.1 second poll inrun.share hard-coded; whether they become variables is still open.golangci-lintstep in the workflow, stage 2 (metrics, traces, integration tests in CI), the rootless port.PR Comments
Add the following comments to the PR:
/e2e- to trigger E2E build/bump patch- to bump the patch version/bump minor- to bump the minor version/bump major- to bump the major version🤖 Generated with Claude Code
Security report
codefresh/dind — fixed 0 CVEs, 0 tickets
Scan
https://g.codefresh.io/build/6b0f165a098f062a3b162580
Fixed CVEs: 0
Fixed issues: 0