You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document serves as a high level discussion of the implementation of the extensions framework defined in the [OCI Distribution spec](https://github.com/opencontainers/distribution-spec/tree/main/extensions).
8
+
9
+
## Extension Interface
10
+
11
+
The `Extension` interface is introduced in the new `extension` package. It defines methods to access the extension's namespace-specific attributes such as the Name, Url defining the extension namespace, and the Description of the namespace. It defines route enumeration at the Registry and Repository level. It also encases the `ExtendedStorage` interface which defines the methods requires to extend the underlying storage functionality of the registry.
12
+
13
+
```
14
+
type Extension interface {
15
+
storage.ExtendedStorage
16
+
// GetRepositoryRoutes returns a list of extension routes scoped at a repository level
17
+
GetRepositoryRoutes() []ExtensionRoute
18
+
// GetRegistryRoutes returns a list of extension routes scoped at a registry level
19
+
GetRegistryRoutes() []ExtensionRoute
20
+
// GetNamespaceName returns the name associated with the namespace
21
+
GetNamespaceName() string
22
+
// GetNamespaceUrl returns the url link to the documentation where the namespace's extension and endpoints are defined
23
+
GetNamespaceUrl() string
24
+
// GetNamespaceDescription returns the description associated with the namespace
25
+
GetNamespaceDescription() string
26
+
}
27
+
```
28
+
29
+
The `ExtendedStorage` interface defines methods that specify storage-specific handlers. Each extension will implement a handler extending the functionality. The interface can be expanded in the future to consider new handler types.
30
+
`GetManifestHandlers` is used to return new `ManifestHandlers` defined by each of the extensions.
31
+
`GetGarbageCollectionHandlers` is used to return `GCExtensionHandler` implemented by each extension.
32
+
33
+
```
34
+
type ExtendedStorage interface {
35
+
// GetManifestHandlers returns the list of manifest handlers that handle custom manifest formats supported by the extension
36
+
GetManifestHandlers(
37
+
repo Repository,
38
+
blobStore BlobStore) []ManifestHandler
39
+
// GetGarbageCollectHandlers returns the GCExtensionHandlers that handles custom garbage collection behavior for the extension.
The `GCExtensionHandler` interface defines three methods that are used in the garbage colection mark and sweep process. The `Mark` method is invoked for each `GCExtensionHandler` after the existing mark process finishes in `MarkAndSweep`. It is used to determine if the manifest and blobs should have their temporary ref count incremented in the case of an artifact manifest, or if the manifest and it's referrers should be recursively indexed for deletion in the case of a non-artifact manifest. `OnManifestDelete` is invoked to extend the `RemoveManifest` functionality for the `Vacuum`. New or special-cased manifests may require custom manifest deletion which can be defined with this method. `SweepBlobs` is used to add artifact manifest/blobs to the original `markSet`. These blobs are retained after determining their ref count is still positive.
# Configuration for extensions. It follows the below schema
73
+
# extensions
74
+
# namespace:
75
+
# configuration for the extension and its components in any schema specific to that namespace
76
+
extensions:
77
+
oci:
78
+
ext:
79
+
- discover # enable the discovery extension
80
+
```
81
+
82
+
Each `Extension` defined must call the `RegisterExtension` method to register an extension initialization function with the extension namespace name. The registered extension list is then used during configuration parsing to get and initialize the specified extension. (`GetExtension`)
83
+
84
+
```
85
+
// InitExtension is the initialize function for creating the extension namespace
86
+
type InitExtension func(ctx context.Context, storageDriver driver.StorageDriver, options configuration.ExtensionConfig) (Extension, error)
87
+
88
+
// RegisterExtension is used to register an InitExtension for
Each `Extension` defines an `ExtensionRoute` which contains the new `<namespace>/<extension>/<component>` route attributes. Furthermore, the route `Descriptor` and `Dispatcher` are used to register the new route to the application.
97
+
98
+
```
99
+
type ExtensionRoute struct {
100
+
// Namespace is the name of the extension namespace
101
+
Namespace string
102
+
// Extension is the name of the extension under the namespace
103
+
Extension string
104
+
// Component is the name of the component under the extension
105
+
Component string
106
+
// Descriptor is the route descriptor that gives its path
107
+
Descriptor v2.RouteDescriptor
108
+
// Dispatcher if present signifies that the route is http route with a dispatcher
109
+
Dispatcher RouteDispatchFunc
110
+
}
111
+
112
+
// RouteDispatchFunc is the http route dispatcher used by the extension route handlers
113
+
type RouteDispatchFunc func(extContext *ExtensionContext, r *http.Request) http.Handler
0 commit comments