Skip to content

Commit

Permalink
Merge pull request moby#49147 from thaJeztah/fix_gc_default
Browse files Browse the repository at this point in the history
builder: don't fall back to defaultKeepStorage when set to zero
  • Loading branch information
vvoland authored Dec 20, 2024
2 parents 2c56497 + 275bbcd commit ad69293
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions builder/builder-next/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,38 +429,37 @@ func newGraphDriverController(ctx context.Context, rt http.RoundTripper, opt Opt
func getGCPolicy(conf config.BuilderConfig, root string) ([]client.PruneInfo, error) {
var gcPolicy []client.PruneInfo
if conf.GC.Enabled {
var (
defaultKeepStorage int64
err error
)

if conf.GC.DefaultKeepStorage != "" {
defaultKeepStorage, err = units.RAMInBytes(conf.GC.DefaultKeepStorage)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse defaultKeepStorage")
}
}

if conf.GC.Policy == nil {
var defaultKeepStorage int64
if conf.GC.DefaultKeepStorage != "" {
b, err := units.RAMInBytes(conf.GC.DefaultKeepStorage)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse defaultKeepStorage")
}
defaultKeepStorage = b
}
gcPolicy = mobyworker.DefaultGCPolicy(root, defaultKeepStorage)
} else {
gcPolicy = make([]client.PruneInfo, len(conf.GC.Policy))
for i, p := range conf.GC.Policy {
var b int64
var keepStorage int64
if p.KeepStorage != "" {
b, err = units.RAMInBytes(p.KeepStorage)
b, err := units.RAMInBytes(p.KeepStorage)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse keepStorage")
}
}
if b == 0 {
b = defaultKeepStorage
// don't set a default here, zero is a valid value when
// specified by the user, as the gc-policy may be determined
// through other filters;
// https://github.com/moby/moby/pull/49062#issuecomment-2554981829
keepStorage = b
}

// FIXME(thaJeztah): wire up new options https://github.com/moby/moby/issues/48639
var err error
gcPolicy[i], err = toBuildkitPruneInfo(types.BuildCachePruneOptions{
All: p.All,
KeepStorage: b,
KeepStorage: keepStorage,
Filters: filters.Args(p.Filter),
})
if err != nil {
Expand Down

0 comments on commit ad69293

Please sign in to comment.