Repository navigation
feat(snapshot s3): add --allow-empty-bucket to report an empty bucket as an empty snapshot - #1405
Conversation
A bucket that holds no objects failed the snapshot with "no matching file or dirs in bucket", whatever the fingerprint source. An empty bucket is a state the bucket can be in, not a mistake in the command: a caller snapshotting a set of buckets on a schedule failed on every run while one of them was empty, and a bucket that had been emptied kept its last snapshot in Kosli, which went on showing an artifact that was no longer there. The check dates from when the include and exclude filters were added, where nothing left to report most likely means a mistyped filter. That case keeps the error. With no filter set, the command now warns and reports an empty snapshot, exiting 0, as --skip-unusable-checksums already does when every object is skipped. A bucket holding only folder markers counts as empty, as it did for the error. This changes the exit code of an unfiltered snapshot of an empty bucket from 1 to 0. A caller that relied on the failure to notice an unexpectedly empty bucket now has the warning on stderr instead. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Claude finished @gsavage's task in 2m 27s —— View job Follow-up review complete
Scope: Previous findings (already marked resolved on GitHub):
New issues in the changed lines: none — the testdata fixture addition is correct and alphabetically placed. Full summary posted here. |
The previous commit made an unfiltered snapshot of an empty bucket report an empty snapshot by default, which changed the command's exit code from 1 to 0. This is a public tool, and a caller may rely on that failure to notice a bucket that is unexpectedly empty, so changing it silently is a breaking change. The default is restored: an empty bucket fails with "no matching file or dirs in bucket", as before. --allow-empty-bucket opts in to the new behaviour, a warning and an empty snapshot, for either fingerprint source. The flag is about the bucket and not the filters, so a filter that leaves no object still fails with it set. The harvest now returns EmptyBucketError for a bucket that lists nothing with no filter set, carrying the message both cases have always had, and the command turns that into an empty snapshot when the flag is set. That keeps the policy in the command and the signatures of the harvest functions unchanged. Command-level cases with an empty fake bucket are added to SnapshotS3TestSuite, which also checks that the server accepts a snapshot with no artifacts for an S3 environment. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
TestEmptyFlagAuditCoversEveryCommandAndFlag compares the command tree against the surface the empty-flag audit is expected to cover, and failed in CI because --allow-empty-bucket was added to snapshot s3 without being recorded there. The coverage file is regenerated from the command tree, which adds the flag as a boolean. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Follow-up review: 118632a..c47b769The only new commit in this range ( Previous findings (both raised on
No new inline comments. |
kosli snapshot s3fails withno matching file or dirs in bucketwhen the bucket holds no objects. An empty bucket is a legitimate state, so this adds an opt-in flag,--allow-empty-bucket, that reports it as an empty snapshot instead. Related issue: #1404.What changes
--allow-empty-bucket. A bucket that lists no objects (or only folder markers) logsbucket [name] holds no objects; reporting an empty snapshot, sends a snapshot with no artifacts and exits 0. It works with both--fingerprint-source contentandmetadata, and alongside--skip-unusable-checksums.--include,--include-regex,--excludeor--exclude-regexis set and nothing is left, the snapshot fails even with the flag, since a mistyped filter is the likelier cause.How it works
getS3DataWithSourcereturns a typedaws.EmptyBucketErrorwhen the listing is empty and no filter is set; its message is the one the error has always had.snapshotS3Options.harvestturns that error into an empty snapshot when the flag is set. The harvest functions keep their signatures.History
The first commit made the empty snapshot the default. That changed the exit code from 1 to 0 for existing callers, so the second commit restores the default and puts the behaviour behind the flag; the third records the flag for the flag audit. They could be squashed on merge.
Things to decide in review
Testing
go test ./internal/aws/passes: the typed error is returned only for an unfiltered empty listing, in both fingerprint sources.cmd/kosli/snapshotS3Harvest_test.gopass locally; they driveharvestagainst the fake S3 client and need no server.make lintpasses.SnapshotS3TestSuitehas three new cases with an empty fake bucket, including that the server accepts a snapshot with no artifacts for an S3 environment. I could not run it locally (it needs the local Kosli server); it passes in CI.--allow-empty-bucketis recorded intestdata/empty-flag-audit-coverage.json, which the flag audit test requires for every new flag.Checklist
charts/k8s-reporter/) updated, if needed. Note: these changes live in a separate PR🤖 Generated with Claude Code