Open sajayantony opened 2 years ago
ohman. 👀
@mnltejaswini brought up a conversation about simplifying this further during a conversation and I believe we can try to match this with OCI Distribution spec of
extensions:
<name>
- <ext>
- <component>
As a follow up of the the extension proposal discussed during the OCI call the issue below outlines a proposal for an extensions model to distribution API. The goal here is to provide a reference implementation that would demonstrate adding capabilities to support scenarios like reference artifacts for an image.
opencontainers/distribution-spec#111 - extension proposal opencontainers/distribution-spec#302 - adds some description for adding dist extensions
https://github.com/opencontainers/distribution-spec/pull/111#issuecomment-867251252
/cc @stevvooe's @shizhmsft @mikebrow @mnltejaswini
Details of the design proposal
PRs showing the idea
Current PR - https://github.com/distribution/distribution/pull/3522
Earlier Iterations - https://github.com/distribution/distribution/pull/3522 https://github.com/shizhMSFT/distribution/pull/1 https://github.com/shizhMSFT/distribution/pull/2 ——
Distribution Extensions
This document describes the changes to the distribution to support the extension API that is proposed to the distribution specification. It also outlines some of the guidelines for the extension authors when it is added to the distribution.
Extensions Discovery APIs
As per the extension specification, the distribution MUST support two new routes to enable the discovery of the extensions that are registered with the distribution.
Registry level extensions may be discovered with a standard GET as follows.
Repository level extensions may be discovered with a standard GET as follows.
To enable these routes, the distribution is updated to add these corresponding routes names, descriptors, URLs and handlers under the V2 API. The route handlers uses two properties
registryExtensions
andrepositoryExtensions
of the registry application to serve these requests. These properties are set during the registration process of the extensions.Authoring Extensions
This section describes various aspects of adding new extensions to the distribution. They include configuration, registration, interfaces and some guiding principles for integrating with the distribution codebase.
Guiding Principles
When distribution code has to be updated to support the addition of a new extension, the following guiding principles can be used by the extension authors
github.com/distribution/distribution/v3/registry/extension
extension.go
under that corresponding package.storage
package. In cases where extensions need a handle to this linked blob storage, it is advisable to write utilities that create general blob storage abstractions over this linked blob storage instead of exposing the linked storage directly. It is also advisable to expose this linked blob storage for read only operations only to limit the change surface.Extension Configuration
A new section named
extensions
is added to the distribution configuration. This is parsed to a typemap[string]interface{}
and is read as a map with extension namespace as the key and the rest of the configuration under it as a genericinterface{}
All the configuration specified under the extension namespace is considered as opaque and will be passed to the extension initializer during registration. The configuration can be structured to match the extension route or the extension spec as shown belowExtension Interfaces
A new interface called
ExtensionNamespace
is declared to represent an extension namespace. Currently this interface defines two methods as shown belowThe extension namespace SHOULD return the set of registry and repository scoped routes that will be handled by it. This interface is open and can be updated to include any generic methods that apply to all extensions. The type
ExtensionRoute
includes the route components for an extension route defined by the spec as shown belowOnly routes that are created with a dispatcher will be considered as HTTP routes and will be registered in the distribution router. If a route doesn't define the dispatcher, it is considered as an extension to a capability like storage rather than a HTTP server. Irrespective of the dispatcher, all the routes will be stored and will be included as part of the extension discovery API response.
Extension Registration
The registration workflow for extensions follows the same pattern that is used to register storage drivers, middlewares etc. in the distribution. An extension creator/initializer is defined that will create a namespace of type
ExtensionNamespace
.The registration of an extension namespace includes the registration of the corresponding namespace initializer at startup using the go package
init()
function semantics. Because of this semantics, the package path of the extension should be imported in themain.go
of the distribution.The name that is used to register an extension namespace should match with the name of the
ns
that is defined in the extension configuration.Sample Extensions
References