Skip to content

Commit ac7caa8

Browse files
committed
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 <[email protected]>
1 parent 6382cf9 commit ac7caa8

File tree

8 files changed

+13
-2
lines changed

8 files changed

+13
-2
lines changed

cache/manager.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type ManagerOpt struct {
4949
Applier diff.Applier
5050
Differ diff.Comparer
5151
MetadataStore *metadata.Store
52+
Root string
5253
MountPoolRoot string
5354
}
5455

@@ -94,6 +95,8 @@ type cacheManager struct {
9495
Differ diff.Comparer
9596
MetadataStore *metadata.Store
9697

98+
root string
99+
97100
mountPool sharableMountPool
98101

99102
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) {
110113
Applier: opt.Applier,
111114
Differ: opt.Differ,
112115
MetadataStore: opt.MetadataStore,
116+
root: opt.Root,
113117
records: make(map[string]*cacheRecord),
114118
}
115119

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

1057-
// TODO: pick a better path here
1058-
dstat, err := disk.GetDiskStat(cm.mountPool.tmpdirRoot)
1061+
dstat, err := disk.GetDiskStat(cm.root)
10591062
if err != nil {
10601063
if opt.Free != 0 {
10611064
// if we are pruning based on disk space, failing to get info on it

cache/manager_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func newCacheManager(ctx context.Context, t *testing.T, opt cmOpt) (co *cmOut, c
152152
GarbageCollect: mdb.GarbageCollect,
153153
Applier: applier,
154154
Differ: differ,
155+
Root: tmpdir,
155156
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
156157
})
157158
if err != nil {

solver/llbsolver/mounts/mount_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func newCacheManager(ctx context.Context, t *testing.T, opt cmOpt) (co *cmOut, e
109109
Differ: differ,
110110
LeaseManager: lm,
111111
GarbageCollect: mdb.GarbageCollect,
112+
Root: tmpdir,
112113
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
113114
})
114115
if err != nil {

source/git/source_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ func setupGitSource(t *testing.T, tmpdir string) source.Source {
649649
Applier: applier,
650650
Differ: differ,
651651
GarbageCollect: mdb.GarbageCollect,
652+
Root: tmpdir,
652653
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
653654
})
654655
require.NoError(t, err)

source/http/source_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ func newHTTPSource(t *testing.T) (source.Source, error) {
355355
Applier: applier,
356356
Differ: differ,
357357
GarbageCollect: mdb.GarbageCollect,
358+
Root: tmpdir,
358359
MountPoolRoot: filepath.Join(tmpdir, "cachemounts"),
359360
})
360361
if err != nil {

worker/base/worker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const labelCreatedAt = "buildkit/createdat"
6262
// See also CommonOpt.
6363
type WorkerOpt struct {
6464
ID string
65+
Root string
6566
Labels map[string]string
6667
Platforms []ocispecs.Platform
6768
GCPolicy []client.PruneInfo
@@ -110,6 +111,7 @@ func NewWorker(ctx context.Context, opt WorkerOpt) (*Worker, error) {
110111
ContentStore: opt.ContentStore,
111112
Differ: opt.Differ,
112113
MetadataStore: opt.MetadataStore,
114+
Root: opt.Root,
113115
MountPoolRoot: opt.MountPoolRoot,
114116
})
115117
if err != nil {

worker/containerd/containerd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func newContainerd(client *containerd.Client, workerOpts WorkerOptions) (base.Wo
184184

185185
opt := base.WorkerOpt{
186186
ID: id,
187+
Root: root,
187188
Labels: xlabels,
188189
MetadataStore: md,
189190
NetworkProviders: np,

worker/runc/runc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func NewWorkerOpt(root string, snFactory SnapshotterFactory, rootless bool, proc
150150

151151
opt = base.WorkerOpt{
152152
ID: id,
153+
Root: root,
153154
Labels: xlabels,
154155
MetadataStore: md,
155156
NetworkProviders: np,

0 commit comments

Comments
 (0)