Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image digest check may meet race condition #1051

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/release/pipelines/push_to_external_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,13 @@ 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]

imageDigest, err := releasecommon.GetDigestWithTagInQuay(releasecommon.ReleasedImagePushRepo + ":latest")
johnbieren marked this conversation as resolved.
Show resolved Hide resolved
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)
Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("failed while getting Digest for quay image %s with error: %+v", releasecommon.ReleasedImagePushRepo+"@"+containerImageDigest, err))
Expect(digestExist).To(BeTrue())
})

It("verifies that a Release is marked as succeeded.", func() {
Expand Down
27 changes: 13 additions & 14 deletions tests/release/quay.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,29 @@ import (

var (
quayApiUrl = "https://quay.io/api/v1"
quayOrg = utils.GetEnv("IMAGE_CONTROLLER_QUAY_ORG", "hacbs-release-tests")
// quayOrg = utils.GetEnv("IMAGE_CONTROLLER_QUAY_ORG", "hacbs-release-tests")
quayToken = utils.GetEnv("IMAGE_CONTROLLER_QUAY_ORG_TOKEN", "")
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], repoName, 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")
}
Loading