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 22, 2024
1 parent e0fcc8b commit cb2c24e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (ci CI) TestE2E() error {
}

func RunE2ETests() error {
labelFilter := utils.GetEnv("E2E_TEST_SUITE_LABEL", "!upgrade-create && !upgrade-verify && !upgrade-cleanup && !release-pipelines")
labelFilter := utils.GetEnv("E2E_TEST_SUITE_LABEL", "!upgrade-create && !upgrade-verify && !upgrade-cleanup")
return runTests(labelFilter, "e2e-report.xml")
}

Expand Down
14 changes: 7 additions & 7 deletions tests/release/pipelines/push_to_external_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("Push to external registry", Lab
"mapping": map[string]interface{}{
"components": []map[string]interface{}{
{
"name": component.GetName(),
"name": component.GetName(),
"repository": releasecommon.ReleasedImagePushRepo,
},
},
Expand Down Expand Up @@ -168,15 +168,15 @@ var _ = framework.ReleasePipelinesSuiteDescribe("Push to external registry", Lab
})

It("tests if the image was pushed to quay", func() {
//retrieve the component to get the latest data
//retrieve the component to get the latest data
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]
containerImageDigest := strings.Split(component.Spec.ContainerImage, ":")[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))
})
digestExist, err := releasecommon.DoesDigestExistInQuay(releasecommon.ReleasedImagePushRepo, containerImageDigest)[1])

Check failure on line 176 in tests/release/pipelines/push_to_external_registry.go

View check run for this annotation

Red Hat Konflux / Red Hat Konflux / e2e-on-pull-request

tests/release/pipelines/push_to_external_registry.go#L176

syntax error: unexpected ) at end of statement
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed while getting Digest for quay image %s and digest %s with error: %+v", releasecommon.ReleasedImagePushRepo, containerImageDigest, err))
Expect(digestExist).To(BeTrue())
})

It("verifies that a Release is marked as succeeded.", func() {
Eventually(func() error {
Expand Down
26 changes: 12 additions & 14 deletions tests/release/quay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@ var (
quayClient = quay.NewQuayClient(&http.Client{Transport: &http.Transport{}}, quayToken, quayApiUrl)
)

// imageURL format example: quay.io/redhat-appstudio-qe/devfile-go-rhtap-uvv7:latest
func GetDigestWithTagInQuay(imageURL string) (string, error) {
urlParts := strings.Split(imageURL, ":")
if len(urlParts) != 2 {
return "", fmt.Errorf("image URL %s has incorrect format", imageURL)
}
repoParts := strings.Split(urlParts[0], "/")
// repoURL format example: quay.io/redhat-appstudio-qe/dcmetromap
func DoesDigestExistInQuay(repoURL string, digest string) (bool, error) {
repoParts := strings.Split(repoURL, "/")
if len(repoParts) <= 2 {
return "", fmt.Errorf("image URL %s is not complete", imageURL)
return false, fmt.Errorf("repo URL %s is not complete", repoURL)
}
repoName := strings.Join(repoParts[2:], "/")
tagList, _, err := quayClient.GetTagsFromPage(quayOrg, repoName, 0)

tagList, _, err := quayClient.GetTagsFromPage(repoParts[1], repoParts[2], 0)
if err != nil {
return "", err
return false, err
}

for _, tag := range tagList {
if tag.Name == urlParts[1] {
return tag.ManifestDigest, nil
if tag.ManifestDigest == digest {
return true, nil
}
}
return "", fmt.Errorf("no image is found")

return false, fmt.Errorf("no image is found")
}

0 comments on commit cb2c24e

Please sign in to comment.