Skip to content

config: set buildkit gc enabled to default to true #49899

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 1 commit into from
May 1, 2025

Conversation

jsternberg
Copy link
Collaborator

@jsternberg jsternberg commented Apr 29, 2025

This will use the default settings for buildkit gc unless explicitly
disabled by setting enabled: false in the gc configuration.

Fixes #49826.

containerd image store: Enable BuildKit garbage collector by default.

@jsternberg jsternberg force-pushed the buildkit-gc-enabled-default branch from 6c54381 to c2eaed4 Compare April 29, 2025 15:32
@jsternberg jsternberg requested a review from tonistiigi as a code owner April 29, 2025 15:32
@jsternberg jsternberg force-pushed the buildkit-gc-enabled-default branch from c2eaed4 to 98b977a Compare April 29, 2025 16:37
Comment on lines 93 to 100

func (x *BuilderGCConfig) IsEnabled() bool {
return x.Enabled == nil || *x.Enabled
}

func (x *BuilderGCConfig) UnmarshalJSON(data []byte) error {
var xx struct {
Enabled bool `json:",omitempty"`
Copy link
Member

@thaJeztah thaJeztah Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was even considering if we had to modify BuilderGCConfig. Enabled to be a pointer, or if we'd only need to modify this temporary struct (unmarshal to xx and if it's nil, then we set the default to true, which we already do below), but that would require New() to set the default (for cases where the UnmarshalJSON is not called, and looks like we'd have to patch other places to start with New() (default config) instead of starting with an empty config.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the temporary struct doesn't work because UnmarshalJSON only gets called if there's a gc section. So doing the change in the temporary struct works for this:

"builder": {"gc": {}}

But it doesn't work when "gc" is missing or if the entire configuration is missing. At the same time, doing it this way ensures that "enabled": null isn't accidentally an acceptable value. If the temporary struct has a pointer, then it would be ok for someone to set null as the value. If we set Enabled to true before running unmarshal then it will be set to true if the attribute isn't present otherwise it'll be overridden and null will cause it to error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I came to that conclusion as well; I had a bit of a brain-fart and thought it would be called unconditionally, but that's that didn't really make sense;

for cases where the UnmarshalJSON is not called

This will use the default settings for buildkit gc unless explicitly
disabled by setting `enabled: false` in the gc configuration.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit e547b63 into moby:master May 1, 2025
152 of 153 checks passed
@jsternberg jsternberg deleted the buildkit-gc-enabled-default branch May 1, 2025 14:36
@vvoland vvoland added containerd-integration Issues and PRs related to containerd integration kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/builder/buildkit Issues affecting buildkit area/builder area/daemon containerd-integration Issues and PRs related to containerd integration impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default BuildKit GC policy
4 participants