From 03caa6584d7ffa4c4f446d97ec2abe2f8f74d714 Mon Sep 17 00:00:00 2001 From: Kasem Alem Date: Tue, 10 Oct 2023 15:28:47 +0300 Subject: [PATCH] test: Add fbc e2e-test happy path to pipelines suite (#808) --- cmd/e2e_test.go | 1 + go.mod | 1 - go.sum | 13 -- pkg/constants/constants.go | 20 ++ pkg/framework/describe.go | 4 + pkg/framework/framework.go | 25 +-- pkg/utils/release/strategies.go | 17 ++ .../tekton/enterprise_contract_policies.go | 15 ++ tests/release/pipelines/README.md | 42 ++++- tests/release/pipelines/e2e-fbc.go | 177 ++++++++++++++++++ 10 files changed, 287 insertions(+), 28 deletions(-) create mode 100644 tests/release/pipelines/e2e-fbc.go diff --git a/cmd/e2e_test.go b/cmd/e2e_test.go index e8fd5dcd6..95c8b2225 100644 --- a/cmd/e2e_test.go +++ b/cmd/e2e_test.go @@ -16,6 +16,7 @@ import ( _ "github.com/redhat-appstudio/e2e-tests/tests/enterprise-contract" _ "github.com/redhat-appstudio/e2e-tests/tests/integration-service" _ "github.com/redhat-appstudio/e2e-tests/tests/release" + _ "github.com/redhat-appstudio/e2e-tests/tests/release/pipelines" _ "github.com/redhat-appstudio/e2e-tests/tests/remotesecret" _ "github.com/redhat-appstudio/e2e-tests/tests/rhtap-demo" _ "github.com/redhat-appstudio/e2e-tests/tests/spi" diff --git a/go.mod b/go.mod index e920d93f6..d9ec85c58 100644 --- a/go.mod +++ b/go.mod @@ -168,7 +168,6 @@ require ( github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect github.com/go-redis/cache/v9 v9.0.0 // indirect - github.com/go-resty/resty/v2 v2.9.1 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect diff --git a/go.sum b/go.sum index 8cba00cf1..84cbccae3 100644 --- a/go.sum +++ b/go.sum @@ -642,8 +642,6 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-redis/cache/v9 v9.0.0 h1:0thdtFo0xJi0/WXbRVu8B066z8OvVymXTJGaXrVWnN0= github.com/go-redis/cache/v9 v9.0.0/go.mod h1:cMwi1N8ASBOufbIvk7cdXe2PbPjK/WMRL95FFHWsSgI= -github.com/go-resty/resty/v2 v2.9.1 h1:PIgGx4VrHvag0juCJ4dDv3MiFRlDmP0vicBucwf+gLM= -github.com/go-resty/resty/v2 v2.9.1/go.mod h1:4/GYJVjh9nhkhGR6AUNW3XhpDYNUr+Uvy9gV/VGZIy4= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -1629,8 +1627,6 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1762,8 +1758,6 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1937,8 +1931,6 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -1952,8 +1944,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= -golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= -golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1972,8 +1962,6 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1982,7 +1970,6 @@ golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20220609170525-579cf78fd858/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 6f567e18c..433c1a5fc 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -60,6 +60,22 @@ const ( // Cert auth for accessing Pyxis stage external registry PYXIS_STAGE_CERT_ENV string = "PYXIS_STAGE_CERT" + // Offline/refresh token used for getting Keycloak token in order to authenticate against stage/prod cluster + // More details: https://access.redhat.com/articles/3626371 + OFFLINE_TOKEN_ENV = "OFFLINE_TOKEN" + + // Keycloak URL used for authentication against stage/prod cluster + KEYLOAK_URL_ENV = "KEYLOAK_URL" + + // Toolchain API URL used for authentication against stage/prod cluster + TOOLCHAIN_API_URL_ENV = "TOOLCHAIN_API_URL" + + // Dev workspace for release pipelines tests + RELEASE_DEV_WORKSPACE_ENV = "RELEASE_DEV_WORKSPACE" + + // Managed workspace for release pipelines tests + RELEASE_MANAGED_WORKSPACE_ENV = "RELEASE_MANAGED_WORKSPACE" + // Bundle ref for overriding the default Java build bundle specified in BuildPipelineSelectorYamlURL CUSTOM_JAVA_PIPELINE_BUILD_BUNDLE_ENV string = "CUSTOM_JAVA_PIPELINE_BUILD_BUNDLE" @@ -106,6 +122,10 @@ const ( ReleasePipelineImageRef = "quay.io/hacbs-release/pipeline-release:0.20" + FromIndex = "quay.io/scoheb/fbc-index-testing:latest" + TargetIndex = "quay.io/scoheb/fbc-target-index-testing:latest" + BinaryImage = "registry.redhat.io/openshift4/ose-operator-registry:v4.12" + StrategyConfigsRepo = "strategy-configs" StrategyConfigsDefaultBranch = "main" StrategyConfigsRevision = "caeaaae63a816ab42dad6c7be1e4b352ea8aabf4" diff --git a/pkg/framework/describe.go b/pkg/framework/describe.go index 5c30d5f64..554680cab 100644 --- a/pkg/framework/describe.go +++ b/pkg/framework/describe.go @@ -53,3 +53,7 @@ func EnterpriseContractSuiteDescribe(text string, args ...interface{}) bool { func UpgradeSuiteDescribe(text string, args ...interface{}) bool { return Describe("[upgrade-suite "+text+"]", args, Ordered) } + +func ReleasePipelinesSuiteDescribe(text string, args ...interface{}) bool { + return Describe("[release-pipelines-suite "+text+"]", args, Ordered) +} diff --git a/pkg/framework/framework.go b/pkg/framework/framework.go index f08f3ff3d..0dae55f3a 100644 --- a/pkg/framework/framework.go +++ b/pkg/framework/framework.go @@ -23,15 +23,15 @@ import ( ) type ControllerHub struct { - HasController *has.HasController - CommonController *common.SuiteController - TektonController *tekton.TektonController - GitOpsController *gitops.GitopsController - SPIController *spi.SPIController - RemoteSecretController *remotesecret.RemoteSecretController - ReleaseController *release.ReleaseController - IntegrationController *integration.IntegrationController - JvmbuildserviceController *jvmbuildservice.JvmbuildserviceController + HasController *has.HasController + CommonController *common.SuiteController + TektonController *tekton.TektonController + GitOpsController *gitops.GitopsController + SPIController *spi.SPIController + RemoteSecretController *remotesecret.RemoteSecretController + ReleaseController *release.ReleaseController + IntegrationController *integration.IntegrationController + JvmbuildserviceController *jvmbuildservice.JvmbuildserviceController } type Framework struct { @@ -104,10 +104,11 @@ func NewFrameworkWithTimeout(userName string, timeout time.Duration, options ... asAdmin = asUser } - if err = utils.WaitUntil(asAdmin.CommonController.ServiceaccountPresent(constants.DefaultPipelineServiceAccount, k.UserNamespace), timeout); err != nil { - return nil, fmt.Errorf("'%s' service account wasn't created in %s namespace: %+v", constants.DefaultPipelineServiceAccount, k.UserNamespace, err) + if !isStage { + if err = utils.WaitUntil(asAdmin.CommonController.ServiceaccountPresent(constants.DefaultPipelineServiceAccount, k.UserNamespace), timeout); err != nil { + return nil, fmt.Errorf("'%s' service account wasn't created in %s namespace: %+v", constants.DefaultPipelineServiceAccount, k.UserNamespace, err) + } } - return &Framework{ AsKubeAdmin: asAdmin, AsKubeDeveloper: asUser, diff --git a/pkg/utils/release/strategies.go b/pkg/utils/release/strategies.go index e52524cb4..f99298f8a 100644 --- a/pkg/utils/release/strategies.go +++ b/pkg/utils/release/strategies.go @@ -2,9 +2,11 @@ package release import ( "context" + "github.com/redhat-appstudio/release-service/tekton/utils" releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" + k8sErrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -50,3 +52,18 @@ func (r *ReleaseController) GenerateReleaseStrategyConfig(components []Component Mapping{Components: components}, } } + +// DeleteReleaseStrategy deletes ReleaseStrategy. +func (r *ReleaseController) DeleteReleaseStrategy(name, namespace string, failOnNotFound bool) error { + releasePlan := &releaseApi.ReleaseStrategy{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + } + err := r.KubeRest().Delete(context.TODO(), releasePlan) + if err != nil && !failOnNotFound && k8sErrors.IsNotFound(err) { + err = nil + } + return err +} diff --git a/pkg/utils/tekton/enterprise_contract_policies.go b/pkg/utils/tekton/enterprise_contract_policies.go index bcb9a348b..8b31ef515 100644 --- a/pkg/utils/tekton/enterprise_contract_policies.go +++ b/pkg/utils/tekton/enterprise_contract_policies.go @@ -76,3 +76,18 @@ func (t *TektonController) GetEnterpriseContractPolicy(name, namespace string) ( return &defaultEcPolicy, err } + +// DeleteEnterpriseContractPolicy deletes enterprise contract policy. +func (t *TektonController) DeleteEnterpriseContractPolicy(name string, namespace string, failOnNotFound bool) error { + ecPolicy := ecp.EnterpriseContractPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + } + err := t.KubeRest().Delete(context.TODO(), &ecPolicy) + if err != nil && !failOnNotFound && errors.IsNotFound(err) { + err = nil + } + return err +} diff --git a/tests/release/pipelines/README.md b/tests/release/pipelines/README.md index e284da607..2bfdb1b1a 100644 --- a/tests/release/pipelines/README.md +++ b/tests/release/pipelines/README.md @@ -1,3 +1,41 @@ -# Release Bundles Tests +# Release Pipelines Tests + +This suite contains e2e-tests for testing release pipelines from repository [release-service-catalog](https://github.com/redhat-appstudio/release-service-catalog/tree/main), those tests run against RHTAP RH-Stage. + +### All tests must have the label `release-pipelines` to avoid running them against the dev environment by OpenShift CI +## prerequisites: + - Export the following environment variables: + ``` + - TOOLCHAIN_API_URL_ENV: Offline token used for getting Keycloak token in order to authenticate against stage/prod cluster + - KEYLOAK_URL_ENV: Keycloak URL used for authentication against stage/prod cluster + - OFFLINE_TOKEN_ENV : Toolchain API URL used for authentication against stage/prod cluster + ``` + - The tests will run on two dedicated namespaces, so a user not part of them need to request access to the following namespaces: + ``` + - dev-release-team-tenant + - managed-release-team-tenant + ``` + +## How to Run tests: + +### 1. To run all e2e-tests in suite ensure your changes of the suite tests are saved. +- navigate to `e2e-tests` directoy + ```bash + make build + ./bin/e2e-appstudio --ginkgo.junit-report=report.xml --ginkgo.focus="pipelines" + ``` + +### 2. To run specific test we should define the test with specific label. +[Ginkgo](https://onsi.github.io/ginkgo/#why-ginkgo) uses labels filtering, adding a label for a test will enable to run specific tests with this label. + +For example: +If a test has the label `label-test` to a test in suite `pipelines` then the test should run using the following arguments: + +- navigate to `e2e-tests` directoy + ```bash + make build + ./bin/e2e-appstudio --ginkgo.junit-report=report.xml --ginkgo.focus="pipelines" --ginkgo.label-filter="label-test" + ``` + + -This suite contains e2e-tests for testing release pipelines from repository [release-service-catalog](https://github.com/redhat-appstudio/release-service-catalog/tree/main), those tests run against RHTAP RH-Stage. \ No newline at end of file diff --git a/tests/release/pipelines/e2e-fbc.go b/tests/release/pipelines/e2e-fbc.go new file mode 100644 index 000000000..a273656c2 --- /dev/null +++ b/tests/release/pipelines/e2e-fbc.go @@ -0,0 +1,177 @@ +package pipelines + +import ( + "fmt" + "os" + "time" + + 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/constants" + "github.com/redhat-appstudio/e2e-tests/pkg/framework" + "github.com/redhat-appstudio/e2e-tests/pkg/utils" + releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" +) + +var _ = framework.ReleasePipelinesSuiteDescribe("[RHTAPREL-373]fbc happy path e2e-test.", Label("release-pipelines", "fbcHappyPath"), func() { + defer GinkgoRecover() + + const ( + fbcApplicationName = "fbc-pipelines-aplication" + fbcComponentName = "fbc-pipelines-component" + fbcReleasePlanName = "fbc-pipelines-releaseplan" + fbcReleasePlanAdmissionName = "fbc-pipelines-releaseplanadmission" + fbcReleaseStrategyName = "fbc-pipelines-strategy" + fbcEnterpriseContractPolicyName = "fbc-pipelines-policy" + fbcServiceAccountName = "release-service-account" + fbcSourceGitUrl = "https://github.com/redhat-appstudio-qe/fbc-sample-repo" + ) + + var devWorkspace = os.Getenv(constants.RELEASE_DEV_WORKSPACE_ENV) + var managedWorkspace = os.Getenv(constants.RELEASE_MANAGED_WORKSPACE_ENV) + var devNamespace = devWorkspace + "-tenant" + var managedNamespace = managedWorkspace + "-tenant" + var releasePipelineRunCompletionTimeout = 20 * time.Minute + var releaseCreationTimeout = 5 * time.Minute + var defaultInterval = 100 * time.Millisecond + + var err error + var dev_fw *framework.Framework + var managed_fw *framework.Framework + var component *appservice.Component + var releaseCR *releaseApi.Release + var buildPr *v1beta1.PipelineRun + var releasePr *v1beta1.PipelineRun + var snapshot *appservice.Snapshot + + stageOptions := utils.Options{ + ToolchainApiUrl: os.Getenv(constants.TOOLCHAIN_API_URL_ENV), + KeycloakUrl: os.Getenv(constants.KEYLOAK_URL_ENV), + OfflineToken: os.Getenv(constants.OFFLINE_TOKEN_ENV), + } + + BeforeAll(func() { + + dev_fw, err = framework.NewFrameworkWithTimeout( + devWorkspace, + time.Minute*60, + stageOptions, + ) + Expect(err).NotTo(HaveOccurred()) + + managed_fw, err = framework.NewFrameworkWithTimeout( + managedWorkspace, + time.Minute*60, + stageOptions, + ) + Expect(err).NotTo(HaveOccurred()) + + _, err = dev_fw.AsKubeDeveloper.HasController.CreateApplication(fbcApplicationName, dev_fw.UserNamespace) + Expect(err).NotTo(HaveOccurred()) + + componentObj := appservice.ComponentSpec{ + ComponentName: fbcComponentName, + Application: fbcApplicationName, + Source: appservice.ComponentSource{ + ComponentSourceUnion: appservice.ComponentSourceUnion{ + GitSource: &appservice.GitSource{ + URL: fbcSourceGitUrl, + }, + }, + }, + TargetPort: 50051, + } + component, err = dev_fw.AsKubeDeveloper.HasController.CreateComponent(componentObj, dev_fw.UserNamespace, "", "", fbcApplicationName, false, map[string]string{}) + GinkgoWriter.Println("component : ", component.Name) + Expect(err).ShouldNot(HaveOccurred()) + + _, err = managed_fw.AsKubeDeveloper.ReleaseController.CreateReleaseStrategy(fbcReleaseStrategyName, managedNamespace, "fbc-release", "quay.io/hacbs-release/pipeline-fbc-release:main", fbcEnterpriseContractPolicyName, fbcServiceAccountName, []releaseApi.Params{ + {Name: "fromIndex", Value: constants.FromIndex}, + {Name: "targetIndex", Value: constants.TargetIndex}, + {Name: "binaryImage", Value: constants.BinaryImage}, + {Name: "requestUpdateTimeout", Value: "420"}, + {Name: "buildTimeoutSeconds", Value: "480"}, + }) + Expect(err).NotTo(HaveOccurred()) + + _, err = dev_fw.AsKubeDeveloper.ReleaseController.CreateReleasePlan(fbcReleasePlanName, devNamespace, fbcApplicationName, managedNamespace, "true") + Expect(err).NotTo(HaveOccurred()) + + _, err = managed_fw.AsKubeDeveloper.ReleaseController.CreateReleasePlanAdmission(fbcReleasePlanAdmissionName, devNamespace, fbcApplicationName, managedNamespace, "", "", fbcReleaseStrategyName) + Expect(err).NotTo(HaveOccurred()) + + defaultEcPolicySpec := ecp.EnterpriseContractPolicySpec{ + Description: "Red Hat's enterprise requirements", + PublicKey: "k8s://openshift-pipelines/public-key", + Sources: []ecp.Source{{ + Name: "Default", + Policy: []string{"github.com/enterprise-contract/ec-policies//policy/lib", "github.com/enterprise-contract/ec-policies//policy/release"}, + Data: []string{"github.com/enterprise-contract/ec-policies//data"}, + }}, + Configuration: &ecp.EnterpriseContractPolicyConfiguration{ + Collections: []string{"minimal"}, + Exclude: []string{"cve", "step_image_registries"}, + Include: []string{"@slsa1", "@slsa2", "@slsa3"}, + }, + } + + _, err = managed_fw.AsKubeDeveloper.TektonController.CreateEnterpriseContractPolicy(fbcEnterpriseContractPolicyName, managedNamespace, defaultEcPolicySpec) + Expect(err).NotTo(HaveOccurred()) + + }) + + AfterAll(func() { + if !CurrentSpecReport().Failed() { + Expect(dev_fw.AsKubeDeveloper.HasController.DeleteApplication(fbcApplicationName, devNamespace, false)).NotTo(HaveOccurred()) + Expect(managed_fw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcEnterpriseContractPolicyName, managedNamespace, false)).NotTo(HaveOccurred()) + Expect(managed_fw.AsKubeDeveloper.ReleaseController.DeleteReleaseStrategy(fbcReleaseStrategyName, managedNamespace, false)).NotTo(HaveOccurred()) + Expect(managed_fw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred()) + } + }) + + var _ = Describe("Post-release verification", func() { + + It("verifies that a build PipelineRun is created in dev namespace and succeeds", func() { + Expect(dev_fw.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(component, "", 2, dev_fw.AsKubeDeveloper.TektonController)).To(Succeed()) + buildPr, err = dev_fw.AsKubeDeveloper.HasController.GetComponentPipelineRun(component.Name, fbcApplicationName, devNamespace, "") + Expect(err).ShouldNot(HaveOccurred()) + + }) + + It("verifies the fbc release pipelinerun is running and succeeds", func() { + snapshot, err = dev_fw.AsKubeDeveloper.IntegrationController.GetSnapshot("", buildPr.Name, component.Name, devNamespace) + Expect(err).ShouldNot(HaveOccurred()) + releaseCR, err = dev_fw.AsKubeDeveloper.ReleaseController.GetRelease("", snapshot.Name, devNamespace) + Expect(err).ShouldNot(HaveOccurred()) + + Eventually(func() error { + releasePr, err = managed_fw.AsKubeAdmin.ReleaseController.GetPipelineRunInNamespace(managed_fw.UserNamespace, releaseCR.GetName(), releaseCR.GetNamespace()) + Expect(err).ShouldNot(HaveOccurred()) + if !releasePr.IsDone() { + return fmt.Errorf("release pipelinerun %s in namespace %s did not finish yet", releasePr.Name, releasePr.Namespace) + } + GinkgoWriter.Println("Release PR: ", releasePr.Name) + Expect(utils.HasPipelineRunSucceeded(releasePr)).To(BeTrue(), fmt.Sprintf("release pipelinerun %s/%s did not succeed", releasePr.GetNamespace(), releasePr.GetName())) + return nil + }, releasePipelineRunCompletionTimeout, defaultInterval).Should(Succeed(), "timed out when waiting for release pipelinerun to succeed") + }) + + It("verifies release CR completed and set succeeded.", func() { + Eventually(func() error { + releaseCR, err = dev_fw.AsKubeDeveloper.ReleaseController.GetRelease("", snapshot.Name, devNamespace) + if err != nil { + return err + } + GinkgoWriter.Println("Release CR: ", releaseCR.Name) + if !releaseCR.IsReleased() { + return fmt.Errorf("release %s/%s is not marked as finished yet", releaseCR.GetNamespace(), releaseCR.GetName()) + } + return nil + }, releaseCreationTimeout, defaultInterval).Should(Succeed()) + }) + + }) +})