From ac7caa8f3b354fba7622d9da29a1171b5b709734 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 25 Sep 2024 10:49:50 +0100 Subject: [PATCH] chore: use a better root for computing free disk space 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 --- cache/manager.go | 7 +++++-- cache/manager_test.go | 1 + solver/llbsolver/mounts/mount_test.go | 1 + source/git/source_test.go | 1 + source/http/source_test.go | 1 + worker/base/worker.go | 2 ++ worker/containerd/containerd.go | 1 + worker/runc/runc.go | 1 + 8 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cache/manager.go b/cache/manager.go index 266b4eddd753..c4e2e84f12fc 100644 --- a/cache/manager.go +++ b/cache/manager.go @@ -49,6 +49,7 @@ type ManagerOpt struct { Applier diff.Applier Differ diff.Comparer MetadataStore *metadata.Store + Root string MountPoolRoot string } @@ -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 @@ -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), } @@ -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 diff --git a/cache/manager_test.go b/cache/manager_test.go index 2a9ee9877935..1aef32987104 100644 --- a/cache/manager_test.go +++ b/cache/manager_test.go @@ -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 { diff --git a/solver/llbsolver/mounts/mount_test.go b/solver/llbsolver/mounts/mount_test.go index 44536d795dc2..180f40607b75 100644 --- a/solver/llbsolver/mounts/mount_test.go +++ b/solver/llbsolver/mounts/mount_test.go @@ -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 { diff --git a/source/git/source_test.go b/source/git/source_test.go index 104263934a7c..59a0fdd83e4f 100644 --- a/source/git/source_test.go +++ b/source/git/source_test.go @@ -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) diff --git a/source/http/source_test.go b/source/http/source_test.go index 980ec2117b2e..8f091dd7008c 100644 --- a/source/http/source_test.go +++ b/source/http/source_test.go @@ -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 { diff --git a/worker/base/worker.go b/worker/base/worker.go index d57cf457618f..0a1743929a91 100644 --- a/worker/base/worker.go +++ b/worker/base/worker.go @@ -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 @@ -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 { diff --git a/worker/containerd/containerd.go b/worker/containerd/containerd.go index d3ec2e4d632b..c00b951bb3f7 100644 --- a/worker/containerd/containerd.go +++ b/worker/containerd/containerd.go @@ -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, diff --git a/worker/runc/runc.go b/worker/runc/runc.go index 937e96017b56..ce756ce3754e 100644 --- a/worker/runc/runc.go +++ b/worker/runc/runc.go @@ -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,