Skip to content

Commit 3d889c8

Browse files
Merge pull request #103 from legionus/alweays-pullthrough
pullthrough is not optional
2 parents 89843cd + 8516796 commit 3d889c8

File tree

9 files changed

+56
-189
lines changed

9 files changed

+56
-189
lines changed

pkg/dockerregistry/server/blobdescriptorservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (bs *blobDescriptorService) Stat(ctx context.Context, dgst digest.Digest) (
5252
// ensure it's referenced inside of corresponding image stream
5353
if bs.repo.cache.ContainsRepository(dgst, bs.repo.imageStream.Reference()) {
5454
context.GetLogger(ctx).Debugf("found cached blob %q in repository %s", dgst.String(), bs.repo.imageStream.Reference())
55-
} else if image := bs.repo.imageStream.HasBlob(ctx, dgst, !bs.repo.app.config.Pullthrough.Enabled); image != nil {
55+
} else if image := bs.repo.imageStream.HasBlob(ctx, dgst); image != nil {
5656
// remember all the layers of matching image
5757
RememberLayersOfImage(ctx, bs.repo.cache, image, bs.repo.imageStream.Reference())
5858
} else {

pkg/dockerregistry/server/configuration/configuration.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ func migratePullthroughSection(cfg *Configuration, options configuration.Paramet
440440
if err != nil {
441441
err = fmt.Errorf("configuration error in openshift.pullthrough.mirror: %v", err)
442442
}
443+
444+
if !cfg.Pullthrough.Enabled {
445+
log.Warnf("pullthrough can't be disabled anymore")
446+
cfg.Pullthrough.Enabled = true
447+
}
448+
443449
return
444450
}
445451

pkg/dockerregistry/server/registry_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ func newTestRegistry(
3737
osClient registryclient.Interface,
3838
storageDriver driver.StorageDriver,
3939
blobrepositorycachettl time.Duration,
40-
pullthrough bool,
4140
useBlobDescriptorCacheProvider bool,
4241
) (distribution.Namespace, error) {
4342
cfg := &configuration.Configuration{
4443
Server: &configuration.Server{
4544
Addr: "localhost:5000",
4645
},
4746
Pullthrough: &configuration.Pullthrough{
48-
Enabled: pullthrough,
47+
Enabled: true,
4948
},
5049
Cache: &configuration.Cache{
5150
BlobRepositoryTTL: blobrepositorycachettl,

pkg/dockerregistry/server/repository.go

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,12 @@ func (app *App) Repository(ctx context.Context, repo distribution.Repository, cr
7676
},
7777
}
7878

79-
if app.config.Pullthrough.Enabled {
80-
r.remoteBlobGetter = NewBlobGetterService(
81-
r.imageStream,
82-
r.imageStream.GetSecrets,
83-
r.cache,
84-
r.app.metrics,
85-
)
86-
}
79+
r.remoteBlobGetter = NewBlobGetterService(
80+
r.imageStream,
81+
r.imageStream.GetSecrets,
82+
r.cache,
83+
r.app.metrics,
84+
)
8785

8886
repo = distribution.Repository(r)
8987
repo = r.app.metrics.Repository(repo, repo.Named().Name())
@@ -112,18 +110,16 @@ func (r *repository) Manifests(ctx context.Context, options ...distribution.Mani
112110
acceptSchema2: r.app.config.Compatibility.AcceptSchema2,
113111
}
114112

115-
if r.app.config.Pullthrough.Enabled {
116-
ms = &pullthroughManifestService{
117-
ManifestService: ms,
118-
newLocalManifestService: func(ctx context.Context) (distribution.ManifestService, error) {
119-
return r.Repository.Manifests(ctx, opts...)
120-
},
121-
imageStream: r.imageStream,
122-
cache: r.cache,
123-
mirror: r.app.config.Pullthrough.Mirror,
124-
registryAddr: r.app.config.Server.Addr,
125-
metrics: r.app.metrics,
126-
}
113+
ms = &pullthroughManifestService{
114+
ManifestService: ms,
115+
newLocalManifestService: func(ctx context.Context) (distribution.ManifestService, error) {
116+
return r.Repository.Manifests(ctx, opts...)
117+
},
118+
imageStream: r.imageStream,
119+
cache: r.cache,
120+
mirror: r.app.config.Pullthrough.Mirror,
121+
registryAddr: r.app.config.Server.Addr,
122+
metrics: r.app.metrics,
127123
}
128124

129125
ms = newPendingErrorsManifestService(ms, r)
@@ -147,15 +143,13 @@ func (r *repository) Blobs(ctx context.Context) distribution.BlobStore {
147143
}
148144
}
149145

150-
if r.app.config.Pullthrough.Enabled {
151-
bs = &pullthroughBlobStore{
152-
BlobStore: bs,
146+
bs = &pullthroughBlobStore{
147+
BlobStore: bs,
153148

154-
remoteBlobGetter: r.remoteBlobGetter,
155-
writeLimiter: r.app.writeLimiter,
156-
mirror: r.app.config.Pullthrough.Mirror,
157-
newLocalBlobStore: r.Repository.Blobs,
158-
}
149+
remoteBlobGetter: r.remoteBlobGetter,
150+
writeLimiter: r.app.writeLimiter,
151+
mirror: r.app.config.Pullthrough.Mirror,
152+
newLocalBlobStore: r.Repository.Blobs,
159153
}
160154

161155
bs = newPendingErrorsBlobStore(bs, r)
@@ -172,9 +166,8 @@ func (r *repository) Tags(ctx context.Context) distribution.TagService {
172166
ts := r.Repository.Tags(ctx)
173167

174168
ts = &tagService{
175-
TagService: ts,
176-
imageStream: r.imageStream,
177-
pullthroughEnabled: r.app.config.Pullthrough.Enabled,
169+
TagService: ts,
170+
imageStream: r.imageStream,
178171
}
179172

180173
ts = newPendingErrorsTagService(ts, r)

pkg/dockerregistry/server/repository_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func TestRepositoryBlobStat(t *testing.T) {
9999
stat string
100100
images []imageapiv1.Image
101101
imageStreams []imageapiv1.ImageStream
102-
pullthrough bool
103102
skipAuth bool
104103
deferredErrors deferredErrors
105104
expectedDescriptor distribution.Descriptor
@@ -165,7 +164,6 @@ func TestRepositoryBlobStat(t *testing.T) {
165164
},
166165
},
167166
},
168-
pullthrough: true,
169167
expectedDescriptor: testNewDescriptorForLayer(testImages["nm/unmanaged:missing-layer-links"][0].DockerImageLayers[1]),
170168
expectedActions: []clientAction{{"get", "imagestreams"}, {"get", "images"}},
171169
},
@@ -205,7 +203,7 @@ func TestRepositoryBlobStat(t *testing.T) {
205203
},
206204
},
207205
expectedError: distribution.ErrBlobUnknown,
208-
expectedActions: []clientAction{{"get", "imagestreams"}, {"get", "images"}},
206+
expectedActions: []clientAction{{"get", "imagestreams"}, {"get", "images"}, {"list", "imagestreams"}},
209207
},
210208

211209
{
@@ -232,7 +230,8 @@ func TestRepositoryBlobStat(t *testing.T) {
232230
},
233231
},
234232
},
235-
expectedError: distribution.ErrBlobUnknown,
233+
expectedError: distribution.ErrBlobUnknown,
234+
expectedActions: []clientAction{{"get", "imagestreams"}, {"list", "imagestreams"}},
236235
},
237236

238237
{
@@ -259,7 +258,8 @@ func TestRepositoryBlobStat(t *testing.T) {
259258
},
260259
},
261260
},
262-
expectedError: distribution.ErrBlobUnknown,
261+
expectedError: distribution.ErrBlobUnknown,
262+
expectedActions: []clientAction{{"get", "imagestreams"}, {"list", "imagestreams"}},
263263
},
264264

265265
{
@@ -312,7 +312,7 @@ func TestRepositoryBlobStat(t *testing.T) {
312312
}
313313
}
314314

315-
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, cfg.Cache.BlobRepositoryTTL, tc.pullthrough, true)
315+
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, cfg.Cache.BlobRepositoryTTL, true)
316316
if err != nil {
317317
t.Fatalf("unexpected error: %v", err)
318318
}
@@ -374,7 +374,7 @@ func TestRepositoryBlobStatCacheEviction(t *testing.T) {
374374
testutil.AddImageStream(t, fos, "nm", "is", nil)
375375
testutil.AddImage(t, fos, testImage, "nm", "is", "latest")
376376

377-
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, blobRepoCacheTTL, false, false)
377+
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, blobRepoCacheTTL, false)
378378
if err != nil {
379379
t.Fatalf("unexpected error: %v", err)
380380
}

pkg/dockerregistry/server/tagservice.go

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
type tagService struct {
1212
distribution.TagService
1313

14-
imageStream imagestream.ImageStream
15-
pullthroughEnabled bool
14+
imageStream imagestream.ImageStream
1615
}
1716

1817
func (t tagService) Get(ctx context.Context, tag string) (distribution.Descriptor, error) {
@@ -35,17 +34,6 @@ func (t tagService) Get(ctx context.Context, tag string) (distribution.Descripto
3534
return distribution.Descriptor{}, distribution.ErrTagUnknown{Tag: tag}
3635
}
3736

38-
if !t.pullthroughEnabled {
39-
image, err := t.imageStream.GetImageOfImageStream(ctx, dgst)
40-
if err != nil {
41-
return distribution.Descriptor{}, err
42-
}
43-
44-
if !imagestream.IsImageManaged(image) {
45-
return distribution.Descriptor{}, distribution.ErrTagUnknown{Tag: tag}
46-
}
47-
}
48-
4937
return distribution.Descriptor{Digest: dgst}, nil
5038
}
5139

@@ -64,30 +52,10 @@ func (t tagService) All(ctx context.Context) ([]string, error) {
6452
}
6553

6654
tagList := []string{}
67-
managedImages := make(map[string]bool)
68-
for tag, dgst := range tags {
69-
if t.pullthroughEnabled {
70-
tagList = append(tagList, tag)
71-
continue
72-
}
73-
74-
managed, found := managedImages[dgst.String()]
75-
if !found {
76-
image, err := t.imageStream.GetImageOfImageStream(ctx, dgst)
77-
if err != nil {
78-
context.GetLogger(ctx).Errorf("unable to get image %s %s: %v", t.imageStream.Reference(), dgst.String(), err)
79-
continue
80-
}
81-
managed = imagestream.IsImageManaged(image)
82-
managedImages[dgst.String()] = managed
83-
}
84-
85-
if !managed {
86-
continue
87-
}
88-
55+
for tag := range tags {
8956
tagList = append(tagList, tag)
9057
}
58+
9159
return tagList, nil
9260
}
9361

@@ -106,34 +74,14 @@ func (t tagService) Lookup(ctx context.Context, desc distribution.Descriptor) ([
10674
}
10775

10876
tagList := []string{}
109-
managedImages := make(map[string]bool)
11077
for tag, dgst := range tags {
11178
if dgst != desc.Digest {
11279
continue
11380
}
11481

115-
if t.pullthroughEnabled {
116-
tagList = append(tagList, tag)
117-
continue
118-
}
119-
120-
managed, found := managedImages[dgst.String()]
121-
if !found {
122-
image, err := t.imageStream.GetImageOfImageStream(ctx, dgst)
123-
if err != nil {
124-
context.GetLogger(ctx).Errorf("unable to get image %s %s: %v", t.imageStream.Reference(), dgst.String(), err)
125-
continue
126-
}
127-
managed = imagestream.IsImageManaged(image)
128-
managedImages[dgst.String()] = managed
129-
}
130-
131-
if !managed {
132-
continue
133-
}
134-
13582
tagList = append(tagList, tag)
13683
}
84+
13785
return tagList, nil
13886
}
13987

0 commit comments

Comments
 (0)