support to syncfs after pull by using diff plugin

Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
This commit is contained in:
ningmingxiao 2024-05-29 21:52:58 +08:00
parent 7a804489fd
commit 0e4f2108b5
3 changed files with 14 additions and 3 deletions

View File

@ -42,6 +42,10 @@ type config struct {
// correct output, allowing any ordering to be used to prefer // correct output, allowing any ordering to be used to prefer
// more optimimal implementations. // more optimimal implementations.
Order []string `toml:"default"` Order []string `toml:"default"`
// sync_fs is an experimental setting. It's to force sync
// filesystem during unpacking to ensure that data integrity.
// It is effective for all containerd client.
SyncFs bool `toml:"sync_fs"`
} }
type differ interface { type differ interface {
@ -62,7 +66,7 @@ func init() {
if err != nil { if err != nil {
return nil, err return nil, err
} }
syncFs := ic.Config.(*config).SyncFs
orderedNames := ic.Config.(*config).Order orderedNames := ic.Config.(*config).Order
ordered := make([]differ, len(orderedNames)) ordered := make([]differ, len(orderedNames))
for i, n := range orderedNames { for i, n := range orderedNames {
@ -79,6 +83,7 @@ func init() {
return &local{ return &local{
differs: ordered, differs: ordered,
syncfs: syncFs,
}, nil }, nil
}, },
}) })
@ -86,6 +91,7 @@ func init() {
type local struct { type local struct {
differs []differ differs []differ
syncfs bool
} }
var _ diffapi.DiffClient = &local{} var _ diffapi.DiffClient = &local{}
@ -106,6 +112,9 @@ func (l *local) Apply(ctx context.Context, er *diffapi.ApplyRequest, _ ...grpc.C
} }
opts = append(opts, diff.WithPayloads(payloads)) opts = append(opts, diff.WithPayloads(payloads))
} }
if l.syncfs {
er.SyncFs = true
}
opts = append(opts, diff.WithSyncFs(er.SyncFs)) opts = append(opts, diff.WithSyncFs(er.SyncFs))
for _, differ := range l.differs { for _, differ := range l.differs {

View File

@ -20,4 +20,5 @@ package diff
var defaultDifferConfig = &config{ var defaultDifferConfig = &config{
Order: []string{"walking"}, Order: []string{"walking"},
SyncFs: false,
} }

View File

@ -18,4 +18,5 @@ package diff
var defaultDifferConfig = &config{ var defaultDifferConfig = &config{
Order: []string{"windows", "windows-lcow"}, Order: []string{"windows", "windows-lcow"},
SyncFs: false,
} }