diff --git a/tests/release/pipelines/push_to_external_registry.go b/tests/release/pipelines/push_to_external_registry.go deleted file mode 100644 index d644a1600c..0000000000 --- a/tests/release/pipelines/push_to_external_registry.go +++ /dev/null @@ -1,194 +0,0 @@ -package pipelines - -import ( - "encoding/json" - "fmt" - "strings" - - tektonutils "github.com/redhat-appstudio/release-service/tekton/utils" - "k8s.io/apimachinery/pkg/runtime" - - ecp "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - appservice "github.com/redhat-appstudio/application-api/api/v1alpha1" - "github.com/redhat-appstudio/e2e-tests/pkg/clients/has" - "github.com/redhat-appstudio/e2e-tests/pkg/constants" - "github.com/redhat-appstudio/e2e-tests/pkg/framework" - "github.com/redhat-appstudio/e2e-tests/pkg/utils" - "github.com/redhat-appstudio/e2e-tests/pkg/utils/contract" - "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" - releasecommon "github.com/redhat-appstudio/e2e-tests/tests/release" - releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" - corev1 "k8s.io/api/core/v1" -) - -var _ = framework.ReleasePipelinesSuiteDescribe("Push to external registry", Label("release-pipelines", "push-to-external-registry"), func() { - defer GinkgoRecover() - - var fw *framework.Framework - AfterEach(framework.ReportFailure(&fw)) - var err error - var devNamespace, managedNamespace string - - var component *appservice.Component - var releaseCR *releaseApi.Release - - BeforeAll(func() { - // Initialize the tests controllers - fw, err = framework.NewFramework(utils.GetGeneratedNamespace("ex-registry")) - Expect(err).NotTo(HaveOccurred()) - devNamespace = fw.UserNamespace - managedNamespace = utils.GetGeneratedNamespace("ex-registry-managed") - _, err = fw.AsKubeAdmin.CommonController.CreateTestNamespace(managedNamespace) - Expect(err).NotTo(HaveOccurred(), "Error when creating managedNamespace: %v", err) - - sourceAuthJson := utils.GetEnv("QUAY_TOKEN", "") - Expect(sourceAuthJson).ToNot(BeEmpty()) - - managedServiceAccount, err := fw.AsKubeAdmin.CommonController.CreateServiceAccount(releasecommon.ReleasePipelineServiceAccountDefault, managedNamespace, releasecommon.ManagednamespaceSecret, nil) - Expect(err).NotTo(HaveOccurred()) - - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePipelineRoleBindingForServiceAccount(devNamespace, managedServiceAccount) - Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePipelineRoleBindingForServiceAccount(managedNamespace, managedServiceAccount) - Expect(err).NotTo(HaveOccurred()) - - _, err = fw.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(releasecommon.RedhatAppstudioUserSecret, managedNamespace, sourceAuthJson) - Expect(err).ToNot(HaveOccurred()) - - err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(devNamespace, releasecommon.HacbsReleaseTestsTokenSecret, constants.DefaultPipelineServiceAccount, true) - Expect(err).ToNot(HaveOccurred()) - - err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(managedNamespace, releasecommon.RedhatAppstudioUserSecret, constants.DefaultPipelineServiceAccount, true) - Expect(err).ToNot(HaveOccurred()) - - publicKey, err := fw.AsKubeAdmin.TektonController.GetTektonChainsPublicKey() - Expect(err).ToNot(HaveOccurred()) - Expect(fw.AsKubeAdmin.TektonController.CreateOrUpdateSigningSecret( - publicKey, releasecommon.PublicSecretNameAuth, managedNamespace)).To(Succeed()) - - defaultECP, err := fw.AsKubeAdmin.TektonController.GetEnterpriseContractPolicy("default", "enterprise-contract-service") - Expect(err).NotTo(HaveOccurred()) - policy := contract.PolicySpecWithSourceConfig(defaultECP.Spec, ecp.SourceConfig{Include: []string{"@minimal"}, Exclude: []string{"cve"}}) - - _, err = fw.AsKubeAdmin.HasController.CreateApplication(releasecommon.ApplicationNameDefault, devNamespace) - Expect(err).NotTo(HaveOccurred()) - - component = releasecommon.CreateComponentByCDQ(*fw, devNamespace, managedNamespace, releasecommon.ApplicationNameDefault, releasecommon.ComponentName, releasecommon.GitSourceComponentUrl) - - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releasecommon.SourceReleasePlanName, devNamespace, releasecommon.ApplicationNameDefault, managedNamespace, "") - Expect(err).NotTo(HaveOccurred()) - - data, err := json.Marshal(map[string]interface{}{ - "mapping": map[string]interface{}{ - "components": []map[string]interface{}{ - { - "name": component.GetName(), - "repository": releasecommon.ReleasedImagePushRepo, - }, - }, - }, - }) - Expect(err).NotTo(HaveOccurred()) - - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(releasecommon.TargetReleasePlanAdmissionName, managedNamespace, "", devNamespace, releasecommon.ReleaseStrategyPolicyDefault, releasecommon.ReleasePipelineServiceAccountDefault, []string{releasecommon.ApplicationNameDefault}, true, &tektonutils.PipelineRef{ - Resolver: "git", - Params: []tektonutils.Param{ - {Name: "url", Value: releasecommon.RelSvcCatalogURL}, - {Name: "revision", Value: releasecommon.RelSvcCatalogRevision}, - {Name: "pathInRepo", Value: "pipelines/push-to-external-registry/push-to-external-registry.yaml"}, - }, - }, &runtime.RawExtension{ - Raw: data, - }) - Expect(err).NotTo(HaveOccurred()) - - _, err = fw.AsKubeAdmin.TektonController.CreateEnterpriseContractPolicy(releasecommon.ReleaseStrategyPolicyDefault, managedNamespace, policy) - Expect(err).NotTo(HaveOccurred()) - - _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releasecommon.ReleasePvcName, managedNamespace, corev1.ReadWriteOnce) - Expect(err).NotTo(HaveOccurred()) - - _, err = fw.AsKubeAdmin.CommonController.CreateRole("role-release-service-account", managedNamespace, map[string][]string{ - "apiGroupsList": {""}, - "roleResources": {"secrets"}, - "roleVerbs": {"get", "list", "watch"}, - }) - Expect(err).NotTo(HaveOccurred()) - - _, err = fw.AsKubeAdmin.CommonController.CreateRoleBinding("role-release-service-account-binding", managedNamespace, "ServiceAccount", releasecommon.ReleasePipelineServiceAccountDefault, managedNamespace, "Role", "role-release-service-account", "rbac.authorization.k8s.io") - Expect(err).NotTo(HaveOccurred()) - }) - - AfterAll(func() { - if !CurrentSpecReport().Failed() { - Expect(fw.AsKubeAdmin.CommonController.DeleteNamespace(managedNamespace)).NotTo(HaveOccurred()) - Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue()) - } - }) - - var _ = Describe("Post-release verification", func() { - It("verifies that a build PipelineRun is created in dev namespace and succeeds", func() { - Expect(fw.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component, "", - fw.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true})).To(Succeed()) - }) - - It("verifies that a Release CR should have been created in the dev namespace", func() { - Eventually(func() error { - releaseCR, err = fw.AsKubeAdmin.ReleaseController.GetFirstReleaseInNamespace(devNamespace) - return err - }, releasecommon.ReleaseCreationTimeout, releasecommon.DefaultInterval).Should(Succeed()) - }) - - It("verifies that Release PipelineRun is triggered", func() { - Eventually(func() error { - pr, err := fw.AsKubeAdmin.ReleaseController.GetPipelineRunInNamespace(managedNamespace, releaseCR.GetName(), releaseCR.GetNamespace()) - if err != nil { - GinkgoWriter.Printf("release pipelineRun for release '%s' in namespace '%s' not created yet: %+v\n", releaseCR.GetName(), releaseCR.GetNamespace(), err) - return err - } - if !pr.HasStarted() { - return fmt.Errorf("pipelinerun %s/%s hasn't started yet", pr.GetNamespace(), pr.GetName()) - } - return nil - }, releasecommon.ReleasePipelineRunCreationTimeout, releasecommon.DefaultInterval).Should(Succeed(), fmt.Sprintf("timed out waiting for a pipelinerun to start for a release %s/%s", releaseCR.GetName(), releaseCR.GetNamespace())) - }) - - It("verifies that Release PipelineRun should eventually succeed", func() { - Eventually(func() error { - pr, err := fw.AsKubeAdmin.ReleaseController.GetPipelineRunInNamespace(managedNamespace, releaseCR.GetName(), releaseCR.GetNamespace()) - Expect(err).ShouldNot(HaveOccurred()) - if !pr.IsDone() { - return fmt.Errorf("release pipelinerun %s/%s did not finish yet", pr.GetNamespace(), pr.GetName()) - } - Expect(tekton.HasPipelineRunSucceeded(pr)).To(BeTrue(), fmt.Sprintf("release pipelinerun %s/%s did not succeed", pr.GetNamespace(), pr.GetName())) - return nil - }, releasecommon.ReleasePipelineRunCompletionTimeout, releasecommon.DefaultInterval).Should(Succeed()) - }) - - It("tests if the image was pushed to quay", func() { - //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") - 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)) - }) - - It("verifies that a Release is marked as succeeded.", func() { - Eventually(func() error { - releaseCR, err = fw.AsKubeAdmin.ReleaseController.GetFirstReleaseInNamespace(devNamespace) - if err != nil { - return err - } - if !releaseCR.IsReleased() { - return fmt.Errorf("release %s/%s is not marked as finished yet", releaseCR.GetNamespace(), releaseCR.GetName()) - } - return nil - }, releasecommon.ReleaseCreationTimeout, releasecommon.DefaultInterval).Should(Succeed()) - }) - }) -}) diff --git a/tests/release/quay.go b/tests/release/quay.go index 1da691b64b..e001624dcb 100644 --- a/tests/release/quay.go +++ b/tests/release/quay.go @@ -16,25 +16,34 @@ 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, ":") +// imageURL format example: quay.io/redhat-appstudio-qe/dcmetromap@sha256:386exxx +func DoesDigestExistInQuay(imageURL string) (bool, error) { + urlParts := strings.Split(imageURL, "@") if len(urlParts) != 2 { - return "", fmt.Errorf("image URL %s has incorrect format", imageURL) + return false, fmt.Errorf("image URL %s has incorrect format", imageURL) } + repoParts := strings.Split(urlParts[0], "/") if len(repoParts) <= 2 { - return "", fmt.Errorf("image URL %s is not complete", imageURL) + return false, fmt.Errorf("image URL %s is not complete", imageURL) } + 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 + } + + digestParts := strings.Split(urlParts[1], ":") + if len(digestParts) != 2 { + return false, fmt.Errorf("image URL %s has incorrect format", imageURL) } + for _, tag := range tagList { - if tag.Name == urlParts[1] { - return tag.ManifestDigest, nil + if tag.ManifestDigest == digestParts[1] { + return true, nil } } - return "", fmt.Errorf("no image is found") + + return false, fmt.Errorf("no image is found") }