mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
feat(scheduler): gracefully shutdown (#1951)
wait for workers to finish before exiting should fix tests reporting they couldn't remove rootDir because it's being written by tasks Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
+22
-19
@@ -1,36 +1,39 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"zotregistry.io/zot/pkg/common"
|
||||
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
||||
)
|
||||
|
||||
type CveInfoMock struct {
|
||||
GetImageListForCVEFn func(repo, cveID string) ([]cvemodel.TagInfo, error)
|
||||
GetImageListWithCVEFixedFn func(repo, cveID string) ([]cvemodel.TagInfo, error)
|
||||
GetCVEListForImageFn func(repo string, reference string, searchedCVE string, pageInput cvemodel.PageInput,
|
||||
) ([]cvemodel.CVE, common.PageInfo, error)
|
||||
GetCVESummaryForImageMediaFn func(repo string, digest, mediaType string,
|
||||
GetImageListForCVEFn func(ctx context.Context, repo, cveID string) ([]cvemodel.TagInfo, error)
|
||||
GetImageListWithCVEFixedFn func(ctx context.Context, repo, cveID string) ([]cvemodel.TagInfo, error)
|
||||
GetCVEListForImageFn func(ctx context.Context, repo string, reference string, searchedCVE string,
|
||||
pageInput cvemodel.PageInput) ([]cvemodel.CVE, common.PageInfo, error)
|
||||
GetCVESummaryForImageMediaFn func(ctx context.Context, repo string, digest, mediaType string,
|
||||
) (cvemodel.ImageCVESummary, error)
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetImageListForCVE(repo, cveID string) ([]cvemodel.TagInfo, error) {
|
||||
func (cveInfo CveInfoMock) GetImageListForCVE(ctx context.Context, repo, cveID string) ([]cvemodel.TagInfo, error) {
|
||||
if cveInfo.GetImageListForCVEFn != nil {
|
||||
return cveInfo.GetImageListForCVEFn(repo, cveID)
|
||||
return cveInfo.GetImageListForCVEFn(ctx, repo, cveID)
|
||||
}
|
||||
|
||||
return []cvemodel.TagInfo{}, nil
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetImageListWithCVEFixed(repo, cveID string) ([]cvemodel.TagInfo, error) {
|
||||
func (cveInfo CveInfoMock) GetImageListWithCVEFixed(ctx context.Context, repo, cveID string,
|
||||
) ([]cvemodel.TagInfo, error) {
|
||||
if cveInfo.GetImageListWithCVEFixedFn != nil {
|
||||
return cveInfo.GetImageListWithCVEFixedFn(repo, cveID)
|
||||
return cveInfo.GetImageListWithCVEFixedFn(ctx, repo, cveID)
|
||||
}
|
||||
|
||||
return []cvemodel.TagInfo{}, nil
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetCVEListForImage(repo string, reference string,
|
||||
func (cveInfo CveInfoMock) GetCVEListForImage(ctx context.Context, repo string, reference string,
|
||||
searchedCVE string, pageInput cvemodel.PageInput,
|
||||
) (
|
||||
[]cvemodel.CVE,
|
||||
@@ -38,16 +41,16 @@ func (cveInfo CveInfoMock) GetCVEListForImage(repo string, reference string,
|
||||
error,
|
||||
) {
|
||||
if cveInfo.GetCVEListForImageFn != nil {
|
||||
return cveInfo.GetCVEListForImageFn(repo, reference, searchedCVE, pageInput)
|
||||
return cveInfo.GetCVEListForImageFn(ctx, repo, reference, searchedCVE, pageInput)
|
||||
}
|
||||
|
||||
return []cvemodel.CVE{}, common.PageInfo{}, nil
|
||||
}
|
||||
|
||||
func (cveInfo CveInfoMock) GetCVESummaryForImageMedia(repo, digest, mediaType string,
|
||||
func (cveInfo CveInfoMock) GetCVESummaryForImageMedia(ctx context.Context, repo, digest, mediaType string,
|
||||
) (cvemodel.ImageCVESummary, error) {
|
||||
if cveInfo.GetCVESummaryForImageMediaFn != nil {
|
||||
return cveInfo.GetCVESummaryForImageMediaFn(repo, digest, mediaType)
|
||||
return cveInfo.GetCVESummaryForImageMediaFn(ctx, repo, digest, mediaType)
|
||||
}
|
||||
|
||||
return cvemodel.ImageCVESummary{}, nil
|
||||
@@ -58,8 +61,8 @@ type CveScannerMock struct {
|
||||
IsImageMediaScannableFn func(repo string, digest, mediaType string) (bool, error)
|
||||
IsResultCachedFn func(digest string) bool
|
||||
GetCachedResultFn func(digest string) map[string]cvemodel.CVE
|
||||
ScanImageFn func(image string) (map[string]cvemodel.CVE, error)
|
||||
UpdateDBFn func() error
|
||||
ScanImageFn func(ctx context.Context, image string) (map[string]cvemodel.CVE, error)
|
||||
UpdateDBFn func(ctx context.Context) error
|
||||
}
|
||||
|
||||
func (scanner CveScannerMock) IsImageFormatScannable(repo string, reference string) (bool, error) {
|
||||
@@ -94,17 +97,17 @@ func (scanner CveScannerMock) GetCachedResult(digest string) map[string]cvemodel
|
||||
return map[string]cvemodel.CVE{}
|
||||
}
|
||||
|
||||
func (scanner CveScannerMock) ScanImage(image string) (map[string]cvemodel.CVE, error) {
|
||||
func (scanner CveScannerMock) ScanImage(ctx context.Context, image string) (map[string]cvemodel.CVE, error) {
|
||||
if scanner.ScanImageFn != nil {
|
||||
return scanner.ScanImageFn(image)
|
||||
return scanner.ScanImageFn(ctx, image)
|
||||
}
|
||||
|
||||
return map[string]cvemodel.CVE{}, nil
|
||||
}
|
||||
|
||||
func (scanner CveScannerMock) UpdateDB() error {
|
||||
func (scanner CveScannerMock) UpdateDB(ctx context.Context) error {
|
||||
if scanner.UpdateDBFn != nil {
|
||||
return scanner.UpdateDBFn()
|
||||
return scanner.UpdateDBFn(ctx)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
@@ -46,11 +47,12 @@ type MockedImageStore struct {
|
||||
GetReferrersFn func(repo string, digest godigest.Digest, artifactTypes []string) (ispec.Index, error)
|
||||
GetOrasReferrersFn func(repo string, digest godigest.Digest, artifactType string,
|
||||
) ([]artifactspec.Descriptor, error)
|
||||
URLForPathFn func(path string) (string, error)
|
||||
RunGCRepoFn func(repo string) error
|
||||
RunGCPeriodicallyFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
RunDedupeBlobsFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
RunDedupeForDigestFn func(digest godigest.Digest, dedupe bool, duplicateBlobs []string) error
|
||||
URLForPathFn func(path string) (string, error)
|
||||
RunGCRepoFn func(repo string) error
|
||||
RunGCPeriodicallyFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
RunDedupeBlobsFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
RunDedupeForDigestFn func(ctx context.Context, digest godigest.Digest, dedupe bool,
|
||||
duplicateBlobs []string) error
|
||||
GetNextDigestWithBlobPathsFn func(repos []string, lastDigests []godigest.Digest) (godigest.Digest, []string, error)
|
||||
GetAllBlobsFn func(repo string) ([]string, error)
|
||||
CleanupRepoFn func(repo string, blobs []godigest.Digest, removeRepo bool) (int, error)
|
||||
@@ -383,9 +385,11 @@ func (is MockedImageStore) RunDedupeBlobs(interval time.Duration, sch *scheduler
|
||||
}
|
||||
}
|
||||
|
||||
func (is MockedImageStore) RunDedupeForDigest(digest godigest.Digest, dedupe bool, duplicateBlobs []string) error {
|
||||
func (is MockedImageStore) RunDedupeForDigest(ctx context.Context, digest godigest.Digest, dedupe bool,
|
||||
duplicateBlobs []string,
|
||||
) error {
|
||||
if is.RunDedupeForDigestFn != nil {
|
||||
return is.RunDedupeForDigestFn(digest, dedupe, duplicateBlobs)
|
||||
return is.RunDedupeForDigestFn(ctx, digest, dedupe, duplicateBlobs)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -81,7 +81,7 @@ type MetaDBMock struct {
|
||||
|
||||
UpdateStatsOnDownloadFn func(repo string, reference string) error
|
||||
|
||||
UpdateSignaturesValidityFn func(repo string, manifestDigest godigest.Digest) error
|
||||
UpdateSignaturesValidityFn func(ctx context.Context, crepo string, manifestDigest godigest.Digest) error
|
||||
|
||||
AddManifestSignatureFn func(repo string, signedManifestDigest godigest.Digest, sygMeta mTypes.SignatureMetadata,
|
||||
) error
|
||||
@@ -403,9 +403,9 @@ func (sdm MetaDBMock) UpdateStatsOnDownload(repo string, reference string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sdm MetaDBMock) UpdateSignaturesValidity(repo string, manifestDigest godigest.Digest) error {
|
||||
func (sdm MetaDBMock) UpdateSignaturesValidity(ctx context.Context, repo string, manifestDigest godigest.Digest) error {
|
||||
if sdm.UpdateSignaturesValidityFn != nil {
|
||||
return sdm.UpdateSignaturesValidityFn(repo, manifestDigest)
|
||||
return sdm.UpdateSignaturesValidityFn(ctx, repo, manifestDigest)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user