-
Notifications
You must be signed in to change notification settings - Fork 12
Optional automatic image cleanup #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d82b4e7
Add automatic image retention cleanup
sjmiller609 4361979
Add image retention observability metrics
sjmiller609 197c298
Address image retention review feedback
sjmiller609 4830d1f
Clean up image usage logging
sjmiller609 8879e48
Add image retention allow list
sjmiller609 99a7b37
Merge remote-tracking branch 'origin/main' into codex/image-retention…
sjmiller609 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "golang.org/x/sync/errgroup" | ||
| ) | ||
|
|
||
| type stubImageRetentionRunner struct { | ||
| runCount atomic.Int32 | ||
| } | ||
|
|
||
| func (s *stubImageRetentionRunner) Run(ctx context.Context) error { | ||
| s.runCount.Add(1) | ||
| <-ctx.Done() | ||
| return nil | ||
| } | ||
|
|
||
| func TestStartImageRetentionControllerSkipsNilController(t *testing.T) { | ||
| grp, ctx := errgroup.WithContext(context.Background()) | ||
|
|
||
| started := startImageRetentionController(grp, ctx, nil) | ||
| if started { | ||
| t.Fatalf("expected nil controller not to start") | ||
| } | ||
| } | ||
|
|
||
| func TestStartImageRetentionControllerStartsRunner(t *testing.T) { | ||
| grp, ctx := errgroup.WithContext(context.Background()) | ||
| ctx, cancel := context.WithCancel(ctx) | ||
| defer cancel() | ||
|
|
||
| runner := &stubImageRetentionRunner{} | ||
| started := startImageRetentionController(grp, ctx, runner) | ||
| if !started { | ||
| t.Fatalf("expected controller to start") | ||
| } | ||
|
|
||
| deadline := time.Now().Add(time.Second) | ||
| for runner.runCount.Load() == 0 && time.Now().Before(deadline) { | ||
| time.Sleep(10 * time.Millisecond) | ||
| } | ||
| if runner.runCount.Load() != 1 { | ||
| t.Fatalf("expected runner to be started once, got %d", runner.runCount.Load()) | ||
| } | ||
|
|
||
| cancel() | ||
| if err := grp.Wait(); err != nil { | ||
| t.Fatalf("wait for retention runner: %v", err) | ||
| } | ||
| } |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Image Retention | ||
|
|
||
| This feature automatically deletes cached converted images after they have been unused for a configurable amount of time. | ||
|
|
||
| The retention window is server-wide and controlled by: | ||
|
|
||
| ```yaml | ||
| images: | ||
| auto_delete: | ||
| enabled: false | ||
| unused_for: 720h | ||
| allowed: [] | ||
| ``` | ||
|
|
||
| When auto-delete is enabled: | ||
|
|
||
| - The server runs a retention sweep on startup and then every minute. | ||
| - Only converted cached images under `data_dir/images` are eligible for deletion. | ||
| - Shared OCI cache data under `data_dir/system/oci-cache` is not modified. | ||
| - An image repository must also match at least one `allowed` pattern before any retention state is recorded or deletion is attempted. | ||
|
|
||
| An image is considered in use if any persisted instance metadata or snapshot record still references it. As long as at least one such reference exists, the image is protected from deletion. | ||
|
|
||
| The retention timer starts only after the last persisted reference disappears and the image repository is allowed by policy. At that point the server records `unused_since` for the image digest. Once `unused_since + unused_for` has elapsed, the cached image digest is deleted. | ||
|
|
||
| Allow-list patterns match normalized repository names such as `docker.io/library/alpine`. A lone `*` pattern allows deletion for every repository. | ||
|
|
||
| New instance creation clears any stale unused state for the resolved image before the new instance metadata is written. This helps prevent races where an image is being reused right as retention cleanup runs. |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing positive duration validation for unused_for config
Low Severity
The
images.auto_delete.unused_forfield is validated only byvalidateDuration, which accepts any parseable Go duration including zero and negative values. A zero or negative value would cause images to be eligible for deletion on the very next sweep after being marked unused (~1 minute), rather than observing a meaningful retention window, contradicting the documented 720h default intent.