@@ -5,11 +5,9 @@ import (
5
5
"fmt"
6
6
"io"
7
7
"os"
8
- "path/filepath"
9
8
"sort"
10
9
"sync"
11
10
"sync/atomic"
12
- "syscall"
13
11
"time"
14
12
15
13
"github.com/dustin/go-humanize"
@@ -52,19 +50,21 @@ func NewHook(ctx context.Context, progressCb func(progress status.Progress)) *Ho
52
50
}
53
51
54
52
type Puller interface {
55
- Pull (ctx context.Context , reference , targetDir string , checkDiskQuota bool ) error
53
+ Pull (ctx context.Context , reference , targetDir string ) error
56
54
}
57
55
58
- var NewPuller = func (ctx context.Context , pullCfg * config.PullConfig , hook * Hook ) Puller {
56
+ var NewPuller = func (ctx context.Context , pullCfg * config.PullConfig , hook * Hook , diskQuotaChecker * DiskQuotaChecker ) Puller {
59
57
return & puller {
60
- pullCfg : pullCfg ,
61
- hook : hook ,
58
+ pullCfg : pullCfg ,
59
+ hook : hook ,
60
+ diskQuotaChecker : diskQuotaChecker ,
62
61
}
63
62
}
64
63
65
64
type puller struct {
66
- pullCfg * config.PullConfig
67
- hook * Hook
65
+ pullCfg * config.PullConfig
66
+ hook * Hook
67
+ diskQuotaChecker * DiskQuotaChecker
68
68
}
69
69
70
70
func (h * Hook ) getProgressDesc () string {
@@ -201,7 +201,7 @@ func (h *Hook) GetProgress() status.Progress {
201
201
return h .getProgress ()
202
202
}
203
203
204
- func (p * puller ) Pull (ctx context.Context , reference , targetDir string , checkDiskQuota bool ) error {
204
+ func (p * puller ) Pull (ctx context.Context , reference , targetDir string ) error {
205
205
keyChain , err := auth .GetKeyChainByRef (reference )
206
206
if err != nil {
207
207
return errors .Wrapf (err , "get auth for model: %s" , reference )
@@ -212,9 +212,10 @@ func (p *puller) Pull(ctx context.Context, reference, targetDir string, checkDis
212
212
return errors .Wrap (err , "create modctl backend" )
213
213
}
214
214
215
- if checkDiskQuota {
216
- if err := p .checkDiskQuota (ctx , reference , filepath .Dir (targetDir ), keyChain .ServerScheme == "http" , b ); err != nil {
217
- return err
215
+ if p .diskQuotaChecker != nil {
216
+ plainHTTP := keyChain .ServerScheme == "http"
217
+ if err := p .diskQuotaChecker .Check (ctx , b , reference , plainHTTP ); err != nil {
218
+ return errors .Wrap (err , "check disk quota" )
218
219
}
219
220
}
220
221
@@ -247,34 +248,3 @@ func (p *puller) Pull(ctx context.Context, reference, targetDir string, checkDis
247
248
248
249
return nil
249
250
}
250
-
251
- func (p * puller ) checkDiskQuota (ctx context.Context , reference , dir string , plainHTTP bool , b backend.Backend ) error {
252
- var st syscall.Statfs_t
253
- if err := syscall .Statfs (dir , & st ); err != nil {
254
- logger .WithContext (ctx ).WithError (err ).Errorf ("failed to stat dir %s in mounting %s" , dir , reference )
255
- } else {
256
- availSpace := int64 (st .Bavail ) * int64 (st .Bsize )
257
- logger .WithContext (ctx ).Infof ("cache dir available space: %s" , humanize .IBytes (uint64 (availSpace )))
258
- // get model image size
259
- result , err := b .Inspect (ctx , reference , & modctlConfig.Inspect {Remote : true , Insecure : true , PlainHTTP : plainHTTP })
260
- if err != nil {
261
- logger .WithContext (ctx ).WithError (err ).Errorf ("failed to inspect model image: %s" , reference )
262
- return errors .Wrap (err , "inspect model image" )
263
- }
264
-
265
- modelArtifact , ok := result .(* backend.InspectedModelArtifact )
266
- if ! ok {
267
- logger .WithContext (ctx ).Errorf ("invalid inspected result: %s" , result )
268
- return fmt .Errorf ("invalid inspected result" )
269
- }
270
-
271
- totalSize := int64 (0 )
272
- for _ , layer := range modelArtifact .Layers {
273
- totalSize += layer .Size
274
- }
275
- if totalSize > availSpace {
276
- return errors .Wrapf (syscall .ENOSPC , "model image %s is %s, but only %s of disk quota is available" , reference , humanize .IBytes (uint64 (totalSize )), humanize .IBytes (uint64 (availSpace )))
277
- }
278
- }
279
- return nil
280
- }
0 commit comments