Skip to content

Commit 857dc6f

Browse files
authored
Merge pull request containerd#10162 from dmcgowan/cleanup-local-transfer
Cleanup local transfer interface
2 parents 193af78 + fe01cad commit 857dc6f

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

core/transfer/local/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (ts *localTransferService) pull(ctx context.Context, ir transfer.ImageFetch
5656
}
5757

5858
// Verify image before pulling.
59-
for vfName, vf := range ts.verifiers {
59+
for vfName, vf := range ts.config.Verifiers {
6060
log := log.G(ctx).WithFields(logrus.Fields{
6161
"name": name,
6262
"digest": desc.Digest.String(),

core/transfer/local/transfer.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,20 @@ import (
3636
)
3737

3838
type localTransferService struct {
39-
leases leases.Manager
40-
content content.Store
41-
images images.Store
42-
verifiers map[string]imageverifier.ImageVerifier
39+
content content.Store
40+
images images.Store
4341
// limiter for upload
4442
limiterU *semaphore.Weighted
4543
// limiter for download operation
4644
limiterD *semaphore.Weighted
4745
config TransferConfig
4846
}
4947

50-
func NewTransferService(lm leases.Manager, cs content.Store, is images.Store, vfs map[string]imageverifier.ImageVerifier, tc *TransferConfig) transfer.Transferrer {
48+
func NewTransferService(cs content.Store, is images.Store, tc TransferConfig) transfer.Transferrer {
5149
ts := &localTransferService{
52-
leases: lm,
53-
content: cs,
54-
images: is,
55-
verifiers: vfs,
56-
config: *tc,
50+
content: cs,
51+
images: is,
52+
config: tc,
5753
}
5854
if tc.MaxConcurrentUploadedLayers > 0 {
5955
ts.limiterU = semaphore.NewWeighted(int64(tc.MaxConcurrentUploadedLayers))
@@ -142,7 +138,10 @@ func (ts *localTransferService) withLease(ctx context.Context, opts ...leases.Op
142138
return ctx, nop, nil
143139
}
144140

145-
ls := ts.leases
141+
ls := ts.config.Leases
142+
if ls == nil {
143+
return ctx, nop, nil
144+
}
146145

147146
if len(opts) == 0 {
148147
// Use default lease configuration if no options provided
@@ -164,6 +163,9 @@ func (ts *localTransferService) withLease(ctx context.Context, opts ...leases.Op
164163
}
165164

166165
type TransferConfig struct {
166+
// Leases manager is used to create leases during operations if none, exists
167+
Leases leases.Manager
168+
167169
// MaxConcurrentDownloads is the max concurrent content downloads for pull.
168170
MaxConcurrentDownloads int
169171
// MaxConcurrentUploadedLayers is the max concurrent uploads for push
@@ -182,6 +184,9 @@ type TransferConfig struct {
182184
// UnpackPlatforms are used to specify supported combination of platforms and snapshotters
183185
UnpackPlatforms []unpack.Platform
184186

187+
// ImageVerifiers verify the image before saving into the image store.
188+
Verifiers map[string]imageverifier.ImageVerifier
189+
185190
// RegistryConfigPath is a path to the root directory containing registry-specific configurations
186191
RegistryConfigPath string
187192
}

plugins/transfer/plugin.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,27 @@ func init() {
5757
return nil, err
5858
}
5959
ms := m.(*metadata.DB)
60+
61+
var lc local.TransferConfig
62+
6063
l, err := ic.GetSingle(plugins.LeasePlugin)
6164
if err != nil {
6265
return nil, err
6366
}
67+
lc.Leases = l.(leases.Manager)
6468

65-
vfs := make(map[string]imageverifier.ImageVerifier)
6669
vps, err := ic.GetByType(plugins.ImageVerifierPlugin)
6770
if err != nil {
6871
return nil, err
6972
}
70-
71-
for name, vp := range vps {
72-
vfs[name] = vp.(imageverifier.ImageVerifier)
73+
if len(vps) > 0 {
74+
lc.Verifiers = make(map[string]imageverifier.ImageVerifier)
75+
for name, vp := range vps {
76+
lc.Verifiers[name] = vp.(imageverifier.ImageVerifier)
77+
}
7378
}
7479

7580
// Set configuration based on default or user input
76-
var lc local.TransferConfig
7781
lc.MaxConcurrentDownloads = config.MaxConcurrentDownloads
7882
lc.MaxConcurrentUploadedLayers = config.MaxConcurrentUploadedLayers
7983

@@ -140,7 +144,7 @@ func init() {
140144
}
141145
lc.RegistryConfigPath = config.RegistryConfigPath
142146

143-
return local.NewTransferService(l.(leases.Manager), ms.ContentStore(), metadata.NewImageStore(ms), vfs, &lc), nil
147+
return local.NewTransferService(ms.ContentStore(), metadata.NewImageStore(ms), lc), nil
144148
},
145149
})
146150
}

0 commit comments

Comments
 (0)