Skip to content

pullthrough is not optional #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/dockerregistry/server/blobdescriptorservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (bs *blobDescriptorService) Stat(ctx context.Context, dgst digest.Digest) (
// ensure it's referenced inside of corresponding image stream
if bs.repo.cache.ContainsRepository(dgst, bs.repo.imageStream.Reference()) {
context.GetLogger(ctx).Debugf("found cached blob %q in repository %s", dgst.String(), bs.repo.imageStream.Reference())
} else if image := bs.repo.imageStream.HasBlob(ctx, dgst, !bs.repo.app.config.Pullthrough.Enabled); image != nil {
} else if image := bs.repo.imageStream.HasBlob(ctx, dgst); image != nil {
// remember all the layers of matching image
RememberLayersOfImage(ctx, bs.repo.cache, image, bs.repo.imageStream.Reference())
} else {
Expand Down
6 changes: 6 additions & 0 deletions pkg/dockerregistry/server/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ func migratePullthroughSection(cfg *Configuration, options configuration.Paramet
if err != nil {
err = fmt.Errorf("configuration error in openshift.pullthrough.mirror: %v", err)
}

if !cfg.Pullthrough.Enabled {
log.Warnf("pullthrough can't be disabled anymore")
cfg.Pullthrough.Enabled = true
}

return
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/dockerregistry/server/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ func newTestRegistry(
osClient registryclient.Interface,
storageDriver driver.StorageDriver,
blobrepositorycachettl time.Duration,
pullthrough bool,
useBlobDescriptorCacheProvider bool,
) (distribution.Namespace, error) {
cfg := &configuration.Configuration{
Server: &configuration.Server{
Addr: "localhost:5000",
},
Pullthrough: &configuration.Pullthrough{
Enabled: pullthrough,
Enabled: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just drop this parameter from the configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmage I want to show warning if someone have it as false. But I can drop the Pullthrough initialization here.

},
Cache: &configuration.Cache{
BlobRepositoryTTL: blobrepositorycachettl,
Expand Down
55 changes: 24 additions & 31 deletions pkg/dockerregistry/server/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ func (app *App) Repository(ctx context.Context, repo distribution.Repository, cr
},
}

if app.config.Pullthrough.Enabled {
r.remoteBlobGetter = NewBlobGetterService(
r.imageStream,
r.imageStream.GetSecrets,
r.cache,
r.app.metrics,
)
}
r.remoteBlobGetter = NewBlobGetterService(
r.imageStream,
r.imageStream.GetSecrets,
r.cache,
r.app.metrics,
)

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

if r.app.config.Pullthrough.Enabled {
ms = &pullthroughManifestService{
ManifestService: ms,
newLocalManifestService: func(ctx context.Context) (distribution.ManifestService, error) {
return r.Repository.Manifests(ctx, opts...)
},
imageStream: r.imageStream,
cache: r.cache,
mirror: r.app.config.Pullthrough.Mirror,
registryAddr: r.app.config.Server.Addr,
metrics: r.app.metrics,
}
ms = &pullthroughManifestService{
ManifestService: ms,
newLocalManifestService: func(ctx context.Context) (distribution.ManifestService, error) {
return r.Repository.Manifests(ctx, opts...)
},
imageStream: r.imageStream,
cache: r.cache,
mirror: r.app.config.Pullthrough.Mirror,
registryAddr: r.app.config.Server.Addr,
metrics: r.app.metrics,
}

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

if r.app.config.Pullthrough.Enabled {
bs = &pullthroughBlobStore{
BlobStore: bs,
bs = &pullthroughBlobStore{
BlobStore: bs,

remoteBlobGetter: r.remoteBlobGetter,
writeLimiter: r.app.writeLimiter,
mirror: r.app.config.Pullthrough.Mirror,
newLocalBlobStore: r.Repository.Blobs,
}
remoteBlobGetter: r.remoteBlobGetter,
writeLimiter: r.app.writeLimiter,
mirror: r.app.config.Pullthrough.Mirror,
newLocalBlobStore: r.Repository.Blobs,
}

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

ts = &tagService{
TagService: ts,
imageStream: r.imageStream,
pullthroughEnabled: r.app.config.Pullthrough.Enabled,
TagService: ts,
imageStream: r.imageStream,
}

ts = newPendingErrorsTagService(ts, r)
Expand Down
14 changes: 7 additions & 7 deletions pkg/dockerregistry/server/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func TestRepositoryBlobStat(t *testing.T) {
stat string
images []imageapiv1.Image
imageStreams []imageapiv1.ImageStream
pullthrough bool
skipAuth bool
deferredErrors deferredErrors
expectedDescriptor distribution.Descriptor
Expand Down Expand Up @@ -165,7 +164,6 @@ func TestRepositoryBlobStat(t *testing.T) {
},
},
},
pullthrough: true,
expectedDescriptor: testNewDescriptorForLayer(testImages["nm/unmanaged:missing-layer-links"][0].DockerImageLayers[1]),
expectedActions: []clientAction{{"get", "imagestreams"}, {"get", "images"}},
},
Expand Down Expand Up @@ -205,7 +203,7 @@ func TestRepositoryBlobStat(t *testing.T) {
},
},
expectedError: distribution.ErrBlobUnknown,
expectedActions: []clientAction{{"get", "imagestreams"}, {"get", "images"}},
expectedActions: []clientAction{{"get", "imagestreams"}, {"get", "images"}, {"list", "imagestreams"}},
},

{
Expand All @@ -232,7 +230,8 @@ func TestRepositoryBlobStat(t *testing.T) {
},
},
},
expectedError: distribution.ErrBlobUnknown,
expectedError: distribution.ErrBlobUnknown,
expectedActions: []clientAction{{"get", "imagestreams"}, {"list", "imagestreams"}},
},

{
Expand All @@ -259,7 +258,8 @@ func TestRepositoryBlobStat(t *testing.T) {
},
},
},
expectedError: distribution.ErrBlobUnknown,
expectedError: distribution.ErrBlobUnknown,
expectedActions: []clientAction{{"get", "imagestreams"}, {"list", "imagestreams"}},
},

{
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestRepositoryBlobStat(t *testing.T) {
}
}

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

reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, blobRepoCacheTTL, false, false)
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, blobRepoCacheTTL, false)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
60 changes: 4 additions & 56 deletions pkg/dockerregistry/server/tagservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
type tagService struct {
distribution.TagService

imageStream imagestream.ImageStream
pullthroughEnabled bool
imageStream imagestream.ImageStream
}

func (t tagService) Get(ctx context.Context, tag string) (distribution.Descriptor, error) {
Expand All @@ -33,17 +32,6 @@ func (t tagService) Get(ctx context.Context, tag string) (distribution.Descripto
return distribution.Descriptor{}, distribution.ErrTagUnknown{Tag: tag}
}

if !t.pullthroughEnabled {
image, err := t.imageStream.GetImageOfImageStream(ctx, dgst)
if err != nil {
return distribution.Descriptor{}, err
}

if !imagestream.IsImageManaged(image) {
return distribution.Descriptor{}, distribution.ErrTagUnknown{Tag: tag}
}
}

return distribution.Descriptor{Digest: dgst}, nil
}

Expand All @@ -62,30 +50,10 @@ func (t tagService) All(ctx context.Context) ([]string, error) {
}

tagList := []string{}
managedImages := make(map[string]bool)
for tag, dgst := range tags {
if t.pullthroughEnabled {
tagList = append(tagList, tag)
continue
}

managed, found := managedImages[dgst.String()]
if !found {
image, err := t.imageStream.GetImageOfImageStream(ctx, dgst)
if err != nil {
context.GetLogger(ctx).Errorf("unable to get image %s %s: %v", t.imageStream.Reference(), dgst.String(), err)
continue
}
managed = imagestream.IsImageManaged(image)
managedImages[dgst.String()] = managed
}

if !managed {
continue
}

for tag := range tags {
tagList = append(tagList, tag)
}

return tagList, nil
}

Expand All @@ -104,34 +72,14 @@ func (t tagService) Lookup(ctx context.Context, desc distribution.Descriptor) ([
}

tagList := []string{}
managedImages := make(map[string]bool)
for tag, dgst := range tags {
if dgst != desc.Digest {
continue
}

if t.pullthroughEnabled {
tagList = append(tagList, tag)
continue
}

managed, found := managedImages[dgst.String()]
if !found {
image, err := t.imageStream.GetImageOfImageStream(ctx, dgst)
if err != nil {
context.GetLogger(ctx).Errorf("unable to get image %s %s: %v", t.imageStream.Reference(), dgst.String(), err)
continue
}
managed = imagestream.IsImageManaged(image)
managedImages[dgst.String()] = managed
}

if !managed {
continue
}

tagList = append(tagList, tag)
}

return tagList, nil
}

Expand Down
Loading