Skip to content

Commit

Permalink
fix: image digest check may meet race condition
Browse files Browse the repository at this point in the history
Signed-off-by: Jing Qi <[email protected]>
  • Loading branch information
jinqi7 committed Feb 21, 2024
1 parent 81d6508 commit 4d5415d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/release/pipelines/push_to_external_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ var _ = framework.ReleasePipelinesSuiteDescribe("Push to external registry", Lab
component, err := fw.AsKubeAdmin.HasController.GetComponent(component.GetName(), devNamespace)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("could not get component %s in the %s namespace", component.GetName(), devNamespace))
containerImageDigest := strings.Split(component.Spec.ContainerImage, "@")[1]
imageDigest := strings.Replace(containerImageDigest, ":", "-", -1)

imageDigest, err := releasecommon.GetDigestWithTagInQuay(releasecommon.ReleasedImagePushRepo + ":latest")
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed while getting Digest for quay image %s with error: %+v", releasecommon.ReleasedImagePushRepo + ":latest", err))
Expect(imageDigest).To(Equal(containerImageDigest))
tagExist, err := releasecommon.DoesTagExistsInQuay(releasecommon.ReleasedImagePushRepo + ":" + imageDigest)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed while getting Digest for quay image %s with error: %+v", releasecommon.ReleasedImagePushRepo + ":" + imageDigest, err))
Expect(tagExist).To(BeTrue())
})

It("verifies that a Release is marked as succeeded.", func() {
Expand Down
24 changes: 24 additions & 0 deletions tests/release/quay.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,27 @@ func GetDigestWithTagInQuay(imageURL string) (string, error) {
}
return "", fmt.Errorf("no image is found")
}

// imageURL format example: quay.io/redhat-appstudio-qe/dcmetromap:sha256-386e8280dad01b86f01eaf4ed3a821c82626ec3dd7783c68b2cf558a15431a0f
func DoesTagExistsInQuay(imageURL string) (bool, error) {
urlParts := strings.Split(imageURL, ":")
if len(urlParts) != 2 {
return false, fmt.Errorf("image URL %s has incorrect format", imageURL)
}
repoParts := strings.Split(urlParts[0], "/")
if len(repoParts) <= 2 {
return false, fmt.Errorf("image URL %s is not complete", imageURL)
}
repoName := strings.Join(repoParts[2:], "/")
tagList, _, err := quayClient.GetTagsFromPage(quayOrg, repoName, 0)
if err != nil {
return false, err
}
for _, tag := range tagList {
if tag.Name == urlParts[1] {
return true, nil
}
}
return false, fmt.Errorf("no image is found")
}

0 comments on commit 4d5415d

Please sign in to comment.