mirror of
https://github.com/project-zot/zot.git
synced 2026-06-19 05:57:57 +08:00
feat(sync): move stream from global to per upstream
Signed-off-by: Vishwas Rajashekar <dev@vrajashkr.com>
This commit is contained in:
@@ -53,6 +53,17 @@ func (onDemand *BaseOnDemand) StreamManager() StreamManager {
|
||||
return onDemand.streamManager
|
||||
}
|
||||
|
||||
// IsStreamingEnabledForRepo returns true if any on-demand service has streaming enabled for the given repo.
|
||||
func (onDemand *BaseOnDemand) IsStreamingEnabledForRepo(repo string) bool {
|
||||
for _, service := range onDemand.services {
|
||||
if service.IsStreamingForRepo(repo) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// FetchManifestForStream directly fetches the manifest from the upstream services and prepares the image
|
||||
// for streaming.
|
||||
// This is only intended for use with streaming sync.
|
||||
|
||||
@@ -29,3 +29,7 @@ func (onDemand *BaseOnDemand) FetchManifestForStream(
|
||||
func (onDemand *BaseOnDemand) StreamManager() StreamManager {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (onDemand *BaseOnDemand) IsStreamingEnabledForRepo(_ string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -215,6 +215,21 @@ func (service *BaseService) CanRetryOnError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsStreamingForRepo returns whether streaming is enabled for the given local repo on this service.
|
||||
// Streaming is enabled if the registry config has Stream set to true and the repo matches the content config.
|
||||
func (service *BaseService) IsStreamingForRepo(repo string) bool {
|
||||
if !service.config.IsStreamEnabled() {
|
||||
return false
|
||||
}
|
||||
|
||||
// If no content filter is configured, all repos match.
|
||||
if len(service.config.Content) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return service.contentManager.GetContentByLocalRepo(repo) != nil
|
||||
}
|
||||
|
||||
func (service *BaseService) GetSyncTimeout() time.Duration {
|
||||
if service.config.SyncTimeout == 0 {
|
||||
return syncConstants.DefaultSyncTimeout
|
||||
@@ -520,7 +535,7 @@ func (service *BaseService) syncRef(ctx context.Context, localRepo string, remot
|
||||
|
||||
copyOpts := []regclient.ImageOpts{}
|
||||
|
||||
if service.streamManager != nil {
|
||||
if service.config.Stream != nil && *service.config.Stream && service.streamManager != nil {
|
||||
service.log.Debug().Str("repo", localRepo).Str("reference", remoteImageRef.Tag).
|
||||
Msg("streaming is enabled. Enabling reader hook")
|
||||
copyOpts = append(copyOpts, regclient.ImageWithBlobReaderHook(service.streamManager.StreamingBlobReader))
|
||||
|
||||
@@ -39,6 +39,8 @@ type Service interface {
|
||||
GetSyncTimeout() time.Duration
|
||||
|
||||
FetchManifest(ctx context.Context, repo, reference string) (manifest.Manifest, error)
|
||||
// Returns whether streaming is enabled for the given local repo on this service.
|
||||
IsStreamingForRepo(repo string) bool
|
||||
}
|
||||
|
||||
// Registry interface must be implemented by local and remote registries.
|
||||
|
||||
Reference in New Issue
Block a user