mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 04:48:26 +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:
@@ -1228,7 +1228,7 @@ func (bdw *BoltDB) UpdateStatsOnDownload(repo string, reference string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (bdw *BoltDB) UpdateSignaturesValidity(repo string, manifestDigest godigest.Digest) error {
|
||||
func (bdw *BoltDB) UpdateSignaturesValidity(ctx context.Context, repo string, manifestDigest godigest.Digest) error {
|
||||
err := bdw.DB.Update(func(transaction *bbolt.Tx) error {
|
||||
imgTrustStore := bdw.ImageTrustStore()
|
||||
|
||||
@@ -1267,6 +1267,10 @@ func (bdw *BoltDB) UpdateSignaturesValidity(repo string, manifestDigest godigest
|
||||
|
||||
manifestSignatures := proto_go.ManifestSignatures{Map: map[string]*proto_go.SignaturesInfo{"": {}}}
|
||||
for sigType, sigs := range protoRepoMeta.Signatures[manifestDigest.String()].Map {
|
||||
if zcommon.IsContextDone(ctx) {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
signaturesInfo := []*proto_go.SignatureInfo{}
|
||||
|
||||
for _, sigInfo := range sigs.List {
|
||||
|
||||
@@ -107,8 +107,10 @@ func TestWrapperErrors(t *testing.T) {
|
||||
boltdbWrapper.SetImageTrustStore(imgTrustStore{})
|
||||
digest := image.Digest()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
Convey("image meta blob not found", func() {
|
||||
err := boltdbWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err := boltdbWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
@@ -116,7 +118,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
err := setImageMeta(digest, badProtoBlob, boltdbWrapper.DB)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = boltdbWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err = boltdbWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -124,7 +126,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
err := boltdbWrapper.SetImageMeta(digest, imageMeta)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = boltdbWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err = boltdbWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -135,7 +137,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
err = setRepoMeta("repo", badProtoBlob, boltdbWrapper.DB)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = boltdbWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err = boltdbWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1128,20 +1128,20 @@ func (dwr *DynamoDB) UpdateStatsOnDownload(repo string, reference string) error
|
||||
return dwr.setProtoRepoMeta(repo, repoMeta)
|
||||
}
|
||||
|
||||
func (dwr *DynamoDB) UpdateSignaturesValidity(repo string, manifestDigest godigest.Digest) error {
|
||||
func (dwr *DynamoDB) UpdateSignaturesValidity(ctx context.Context, repo string, manifestDigest godigest.Digest) error {
|
||||
imgTrustStore := dwr.ImageTrustStore()
|
||||
|
||||
if imgTrustStore == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
protoImageMeta, err := dwr.GetProtoImageMeta(context.Background(), manifestDigest)
|
||||
protoImageMeta, err := dwr.GetProtoImageMeta(ctx, manifestDigest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update signatures with details about validity and author
|
||||
protoRepoMeta, err := dwr.getProtoRepoMeta(context.Background(), repo)
|
||||
protoRepoMeta, err := dwr.getProtoRepoMeta(ctx, repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1149,6 +1149,10 @@ func (dwr *DynamoDB) UpdateSignaturesValidity(repo string, manifestDigest godige
|
||||
manifestSignatures := proto_go.ManifestSignatures{Map: map[string]*proto_go.SignaturesInfo{"": {}}}
|
||||
|
||||
for sigType, sigs := range protoRepoMeta.Signatures[manifestDigest.String()].Map {
|
||||
if zcommon.IsContextDone(ctx) {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
signaturesInfo := []*proto_go.SignatureInfo{}
|
||||
|
||||
for _, sigInfo := range sigs.List {
|
||||
@@ -1181,7 +1185,7 @@ func (dwr *DynamoDB) UpdateSignaturesValidity(repo string, manifestDigest godige
|
||||
|
||||
protoRepoMeta.Signatures[manifestDigest.String()] = &manifestSignatures
|
||||
|
||||
return dwr.setProtoRepoMeta(protoRepoMeta.Name, protoRepoMeta)
|
||||
return dwr.setProtoRepoMeta(protoRepoMeta.Name, protoRepoMeta) //nolint: contextcheck
|
||||
}
|
||||
|
||||
func (dwr *DynamoDB) AddManifestSignature(repo string, signedManifestDigest godigest.Digest,
|
||||
|
||||
@@ -164,6 +164,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
// t.FailNow()
|
||||
// }
|
||||
|
||||
//nolint: contextcheck
|
||||
Convey("Errors", t, func() {
|
||||
params := mdynamodb.DBDriverParameters{ //nolint:contextcheck
|
||||
Endpoint: endpoint,
|
||||
@@ -258,7 +259,15 @@ func TestWrapperErrors(t *testing.T) {
|
||||
digest := image.Digest()
|
||||
|
||||
Convey("image meta blob not found", func() {
|
||||
err := dynamoWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err := dynamoWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("UpdateSignaturesValidity with context done", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err := dynamoWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -266,7 +275,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
err := setImageMeta(digest, badProtoBlob, dynamoWrapper)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = dynamoWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err = dynamoWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -274,7 +283,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
err := dynamoWrapper.SetImageMeta(digest, imageMeta)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = dynamoWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err = dynamoWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -285,7 +294,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
err = setRepoMeta("repo", badProtoBlob, dynamoWrapper)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = dynamoWrapper.UpdateSignaturesValidity("repo", digest)
|
||||
err = dynamoWrapper.UpdateSignaturesValidity(ctx, "repo", digest)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
+10
-2
@@ -1366,7 +1366,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = metaDB.UpdateSignaturesValidity(repo1, image1.Digest())
|
||||
err = metaDB.UpdateSignaturesValidity(ctx, repo1, image1.Digest())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoData, err := metaDB.GetRepoMeta(ctx, repo1)
|
||||
@@ -1375,6 +1375,14 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func
|
||||
ShouldBeEmpty)
|
||||
So(repoData.Signatures[image1.DigestStr()]["cosign"][0].LayersInfo[0].Date,
|
||||
ShouldBeZeroValue)
|
||||
|
||||
Convey("with context done", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err = metaDB.UpdateSignaturesValidity(ctx, repo1, image1.Digest())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
//nolint: contextcheck
|
||||
@@ -1462,7 +1470,7 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func
|
||||
err = imagetrust.UploadCertificate(imgTrustStore.NotationStorage, certificateContent, "ca")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = metaDB.UpdateSignaturesValidity(repo, image1.Digest()) //nolint:contextcheck
|
||||
err = metaDB.UpdateSignaturesValidity(ctx, repo, image1.Digest()) //nolint:contextcheck
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoData, err := metaDB.GetRepoMeta(ctx, repo)
|
||||
|
||||
+1
-1
@@ -353,7 +353,7 @@ func SetImageMetaFromInput(ctx context.Context, repo, reference, mediaType strin
|
||||
return err
|
||||
}
|
||||
|
||||
err = metaDB.UpdateSignaturesValidity(repo, signedManifestDigest)
|
||||
err = metaDB.UpdateSignaturesValidity(ctx, repo, signedManifestDigest)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("repository", repo).Str("reference", reference).Str("digest",
|
||||
signedManifestDigest.String()).Msg("load-repo: failed verify signatures validity for signed image")
|
||||
|
||||
@@ -254,7 +254,9 @@ func TestParseStorageErrors(t *testing.T) {
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
Convey("UpdateSignaturesValidity errors", func() {
|
||||
mockedMetaDB.UpdateSignaturesValidityFn = func(repo string, manifestDigest godigest.Digest) error {
|
||||
mockedMetaDB.UpdateSignaturesValidityFn = func(ctx context.Context, repo string,
|
||||
manifestDigest godigest.Digest,
|
||||
) error {
|
||||
return ErrTestError
|
||||
}
|
||||
err := meta.SetImageMetaFromInput(ctx, "repo", "tag", mediaType, goodNotationSignature.Digest(),
|
||||
|
||||
@@ -101,7 +101,7 @@ type MetaDB interface { //nolint:interfacebloat
|
||||
DeleteSignature(repo string, signedManifestDigest godigest.Digest, sigMeta SignatureMetadata) error
|
||||
|
||||
// UpdateSignaturesValidity checks and updates signatures validity of a given manifest
|
||||
UpdateSignaturesValidity(repo string, manifestDigest godigest.Digest) error
|
||||
UpdateSignaturesValidity(ctx context.Context, repo string, manifestDigest godigest.Digest) error
|
||||
|
||||
// IncrementRepoStars adds 1 to the star count of an image
|
||||
IncrementRepoStars(repo string) error
|
||||
|
||||
Reference in New Issue
Block a user