Skip to content

Commit

Permalink
chore: use a better root for computing free disk space
Browse files Browse the repository at this point in the history
We shouldn't use the cachemount root, we should actually properly
use the worker's specified root which is propagated from the config.

Signed-off-by: Justin Chadwell <[email protected]>
  • Loading branch information
jedevc committed Sep 25, 2024
1 parent 6382cf9 commit ac7caa8
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ManagerOpt struct {
Applier diff.Applier
Differ diff.Comparer
MetadataStore *metadata.Store
Root string
MountPoolRoot string
}

Expand Down Expand Up @@ -94,6 +95,8 @@ type cacheManager struct {
Differ diff.Comparer
MetadataStore *metadata.Store

root string

mountPool sharableMountPool

muPrune sync.Mutex // make sure parallel prune is not allowed so there will not be inconsistent results
Expand All @@ -110,6 +113,7 @@ func NewManager(opt ManagerOpt) (Manager, error) {
Applier: opt.Applier,
Differ: opt.Differ,
MetadataStore: opt.MetadataStore,
root: opt.Root,
records: make(map[string]*cacheRecord),
}

Expand Down Expand Up @@ -1054,8 +1058,7 @@ func (cm *cacheManager) pruneOnce(ctx context.Context, ch chan client.UsageInfo,
}
}

// TODO: pick a better path here
dstat, err := disk.GetDiskStat(cm.mountPool.tmpdirRoot)
dstat, err := disk.GetDiskStat(cm.root)
if err != nil {
if opt.Free != 0 {
// if we are pruning based on disk space, failing to get info on it
Expand Down
1 change: 1 addition & 0 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func newCacheManager(ctx context.Context, t *testing.T, opt cmOpt) (co *cmOut, c
GarbageCollect: mdb.GarbageCollect,
Applier: applier,
Differ: differ,
Root: tmpdir,
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions solver/llbsolver/mounts/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func newCacheManager(ctx context.Context, t *testing.T, opt cmOpt) (co *cmOut, e
Differ: differ,
LeaseManager: lm,
GarbageCollect: mdb.GarbageCollect,
Root: tmpdir,
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions source/git/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ func setupGitSource(t *testing.T, tmpdir string) source.Source {
Applier: applier,
Differ: differ,
GarbageCollect: mdb.GarbageCollect,
Root: tmpdir,
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
})
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions source/http/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ func newHTTPSource(t *testing.T) (source.Source, error) {
Applier: applier,
Differ: differ,
GarbageCollect: mdb.GarbageCollect,
Root: tmpdir,
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
})
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions worker/base/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const labelCreatedAt = "buildkit/createdat"
// See also CommonOpt.
type WorkerOpt struct {
ID string
Root string
Labels map[string]string
Platforms []ocispecs.Platform
GCPolicy []client.PruneInfo
Expand Down Expand Up @@ -110,6 +111,7 @@ func NewWorker(ctx context.Context, opt WorkerOpt) (*Worker, error) {
ContentStore: opt.ContentStore,
Differ: opt.Differ,
MetadataStore: opt.MetadataStore,
Root: opt.Root,
MountPoolRoot: opt.MountPoolRoot,
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions worker/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func newContainerd(client *containerd.Client, workerOpts WorkerOptions) (base.Wo

opt := base.WorkerOpt{
ID: id,
Root: root,
Labels: xlabels,
MetadataStore: md,
NetworkProviders: np,
Expand Down
1 change: 1 addition & 0 deletions worker/runc/runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func NewWorkerOpt(root string, snFactory SnapshotterFactory, rootless bool, proc

opt = base.WorkerOpt{
ID: id,
Root: root,
Labels: xlabels,
MetadataStore: md,
NetworkProviders: np,
Expand Down

0 comments on commit ac7caa8

Please sign in to comment.