Skip to content

Commit 5f266e8

Browse files
author
Oleg Bulatov
committed
WIP
1 parent 85c2542 commit 5f266e8

17 files changed

+731
-319
lines changed

pkg/dockerregistry/server/app.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ import (
66
"github.com/docker/distribution"
77
"github.com/docker/distribution/configuration"
88
"github.com/docker/distribution/context"
9-
"github.com/docker/distribution/registry/handlers"
109
storagedriver "github.com/docker/distribution/registry/storage/driver"
1110

1211
"github.com/openshift/image-registry/pkg/dockerregistry/server/client"
1312
registryconfig "github.com/openshift/image-registry/pkg/dockerregistry/server/configuration"
1413
"github.com/openshift/image-registry/pkg/dockerregistry/server/maxconnections"
14+
"github.com/openshift/image-registry/pkg/dockerregistry/server/supermiddleware"
1515
)
1616

1717
const (
1818
// Default values
1919
defaultDigestToRepositoryCacheSize = 2048
2020
)
2121

22+
// appMiddleware should be used only in tests.
23+
type appMiddleware interface {
24+
Apply(supermiddleware.App) supermiddleware.App
25+
}
26+
2227
// App is a global registry application object. Shared resources can be placed
2328
// on this object that will be accessible from all requests.
2429
type App struct {
@@ -57,6 +62,16 @@ type App struct {
5762
quotaEnforcing *quotaEnforcingConfig
5863
}
5964

65+
func (app *App) Storage(driver storagedriver.StorageDriver, options map[string]interface{}) (storagedriver.StorageDriver, error) {
66+
app.driver = driver
67+
return driver, nil
68+
}
69+
70+
func (app *App) Registry(registry distribution.Namespace, options map[string]interface{}) (distribution.Namespace, error) {
71+
app.registry = registry
72+
return registry, nil
73+
}
74+
6075
// NewApp configures the registry application and returns http.Handler for it.
6176
// The program will be terminated if an error happens.
6277
func NewApp(ctx context.Context, registryClient client.RegistryClient, dockerConfig *configuration.Configuration, extraConfig *registryconfig.Configuration, writeLimiter maxconnections.Limiter) http.Handler {
@@ -74,11 +89,9 @@ func NewApp(ctx context.Context, registryClient client.RegistryClient, dockerCon
7489
}
7590
app.cachedLayers = cache
7691

77-
weaveAppIntoConfig(app, dockerConfig)
78-
7992
repositoryEnabled := false
8093
for _, middleware := range dockerConfig.Middleware["repository"] {
81-
if middleware.Name == middlewareOpenShift {
94+
if middleware.Name == "openshift" {
8295
rc, err := newRepositoryConfig(ctx, extraConfig, middleware.Options)
8396
if err != nil {
8497
context.GetLogger(ctx).Fatalf("error configuring the repository middleware: %s", err)
@@ -89,8 +102,13 @@ func NewApp(ctx context.Context, registryClient client.RegistryClient, dockerCon
89102
}
90103
}
91104

92-
dockerApp := handlers.NewApp(ctx, dockerConfig)
105+
superapp := supermiddleware.App(app)
106+
if am := appMiddlewareFrom(ctx); am != nil {
107+
superapp = am.Apply(superapp)
108+
}
109+
dockerApp := supermiddleware.NewApp(ctx, dockerConfig, superapp)
93110

111+
const middlewareOpenShift = "openshift"
94112
if repositoryEnabled {
95113
if app.driver == nil {
96114
context.GetLogger(ctx).Fatalf("configuration error: the storage driver middleware %q is not activated", middlewareOpenShift)

pkg/dockerregistry/server/auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ var (
8989
ErrUnsupportedResource = errors.New("unsupported resource")
9090
)
9191

92-
func (app *App) newAccessController(authcfg *configuration.Auth) (registryauth.AccessController, error) {
92+
func (app *App) Auth(options map[string]interface{}) (registryauth.AccessController, error) {
93+
authcfg := app.extraConfig.Auth
9394
tokenRealm, err := configuration.TokenRealm(authcfg.TokenRealm)
9495
if err != nil {
9596
return nil, err

pkg/dockerregistry/server/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func TestAccessController(t *testing.T) {
433433
if err := configuration.InitExtraConfig(config, app.extraConfig); err != nil {
434434
t.Fatal(err)
435435
}
436-
accessController, err := app.newAccessController(app.extraConfig.Auth)
436+
accessController, err := app.Auth(nil)
437437
if err != nil {
438438
t.Fatal(err)
439439
}

pkg/dockerregistry/server/blobdescriptorservice.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import (
55
"sort"
66
"time"
77

8-
"github.com/Sirupsen/logrus"
98
"github.com/docker/distribution"
109
"github.com/docker/distribution/context"
1110
"github.com/docker/distribution/digest"
1211
"github.com/docker/distribution/manifest/schema2"
13-
"github.com/docker/distribution/registry/middleware/registry"
14-
"github.com/docker/distribution/registry/storage"
1512

1613
kerrors "k8s.io/apimachinery/pkg/api/errors"
1714

@@ -34,37 +31,27 @@ func (b ByGeneration) Less(i, j int) bool { return b[i].Generation > b[j].Genera
3431
func (b ByGeneration) Len() int { return len(b) }
3532
func (b ByGeneration) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
3633

37-
func init() {
38-
err := middleware.RegisterOptions(storage.BlobDescriptorServiceFactory(&blobDescriptorServiceFactory{}))
39-
if err != nil {
40-
logrus.Fatalf("Unable to register BlobDescriptorServiceFactory: %v", err)
41-
}
42-
}
34+
type blobDescriptorServiceFactoryFunc func(svc distribution.BlobDescriptorService) distribution.BlobDescriptorService
4335

44-
// blobDescriptorServiceFactory needs to be able to work with blobs
45-
// directly without using links. This allows us to ignore the distribution
46-
// of blobs between repositories.
47-
type blobDescriptorServiceFactory struct{}
48-
49-
func (bf *blobDescriptorServiceFactory) BlobAccessController(svc distribution.BlobDescriptorService) distribution.BlobDescriptorService {
50-
return &blobDescriptorService{svc}
36+
func (f blobDescriptorServiceFactoryFunc) BlobAccessController(svc distribution.BlobDescriptorService) distribution.BlobDescriptorService {
37+
return f(svc)
5138
}
5239

5340
type blobDescriptorService struct {
5441
distribution.BlobDescriptorService
42+
repo *repository
43+
}
44+
45+
func (r *repository) BlobDescriptorService(svc distribution.BlobDescriptorService) distribution.BlobDescriptorService {
46+
return &blobDescriptorService{svc, r}
5547
}
5648

5749
// Stat returns a a blob descriptor if the given blob is either linked in repository or is referenced in
5850
// corresponding image stream. This method is invoked from inside of upstream's linkedBlobStore. It expects
5951
// a proper repository object to be set on given context by upper openshift middleware wrappers.
6052
func (bs *blobDescriptorService) Stat(ctx context.Context, dgst digest.Digest) (distribution.Descriptor, error) {
6153
context.GetLogger(ctx).Debugf("(*blobDescriptorService).Stat: starting with digest=%s", dgst.String())
62-
repo, found := repositoryFrom(ctx)
63-
if !found || repo == nil {
64-
err := fmt.Errorf("failed to retrieve repository from context")
65-
context.GetLogger(ctx).Error(err)
66-
return distribution.Descriptor{}, err
67-
}
54+
repo := bs.repo
6855

6956
// if there is a repo layer link, return its descriptor
7057
desc, err := bs.BlobDescriptorService.Stat(ctx, dgst)

0 commit comments

Comments
 (0)