Skip to content

Commit

Permalink
remove simple build dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tisutisu committed Jul 31, 2024
1 parent 9c117bd commit 39d1862
Show file tree
Hide file tree
Showing 24 changed files with 625 additions and 803 deletions.
2 changes: 1 addition & 1 deletion magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (ci CI) UnregisterSprayproxy() {
}

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 && release-pipelines")

rctx := rulesengine.NewRuleCtx()
rctx.Parallel = true
Expand Down
168 changes: 34 additions & 134 deletions tests/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,16 +1040,13 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser
var componentObj appservice.ComponentSpec
var component *appservice.Component

var timeout, interval time.Duration
invalidAnnotation := "foo"

BeforeAll(func() {
f, err = framework.NewFramework(utils.GetGeneratedNamespace("build-e2e"))
Expect(err).ShouldNot(HaveOccurred())
testNamespace = f.UserNamespace

timeout = 5 * time.Minute
interval = 5 * time.Second

applicationName = fmt.Sprintf("build-suite-test-application-%s", util.GenerateRandomString(4))
_, err = f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -1066,8 +1063,11 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser

})

When("component is created", func() {
var lastBuildStartTime string
When("component is created with invalid build request annotations", func() {

invalidBuildAnnotation := map[string]string{
controllers.BuildRequestAnnotationName: invalidAnnotation,
}

BeforeAll(func() {
componentObj = appservice.ComponentSpec{
Expand All @@ -1084,138 +1084,21 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser
},
}

component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, constants.DefaultDockerBuildPipelineBundle)
component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, utils.MergeMaps(invalidBuildAnnotation, constants.DefaultDockerBuildPipelineBundle))
Expect(component).ToNot(BeNil())
Expect(err).ShouldNot(HaveOccurred())
})

It("triggers a pipeline run", func() {
Eventually(func() error {
pr, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "")
if err != nil {
GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, componentName)
return err
}
if !pr.HasStarted() {
return fmt.Errorf("pipelinerun %s/%s hasn't started yet", pr.GetNamespace(), pr.GetName())
}
return nil
}, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", testNamespace, componentName))
})

It("component build status annotation is set correctly", func() {
var buildStatus *controllers.BuildStatus

Eventually(func() (bool, error) {
component, err := f.AsKubeAdmin.HasController.GetComponent(componentName, testNamespace)
if err != nil {
GinkgoWriter.Printf("cannot get the component: %v\n", err)
return false, err
}

buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName]
GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue)
statusBytes := []byte(buildStatusAnnotationValue)

err = json.Unmarshal(statusBytes, &buildStatus)
if err != nil {
GinkgoWriter.Printf("cannot unmarshal build status: %v\n", err)
return false, err
}

if buildStatus.Simple != nil {
GinkgoWriter.Printf("buildStartTime: %s\n", buildStatus.Simple.BuildStartTime)
lastBuildStartTime = buildStatus.Simple.BuildStartTime
} else {
GinkgoWriter.Println("build status does not have simple field")
}

return buildStatus.Simple != nil && buildStatus.Simple.BuildStartTime != "", nil
}, timeout, interval).Should(BeTrue(), "build status has unexpected content")

//Expect pipelinerun count to be 1
Eventually(func() error {
pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace)
if err != nil {
GinkgoWriter.Println("PiplelineRun has not been created yet")
return err
}
if len(pipelineRuns.Items) != 1 {
return fmt.Errorf("pipelinerun count in the namespace %s is not one, got pipelineruns %v", testNamespace, pipelineRuns.Items)
}
return nil
}, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), "timeout while waiting for first pipelinerun to start")
})

Specify("simple build can be triggered manually", func() {
// Wait 1 second before sending the second build request, so that we get different buildStatus.Simple.BuildStartTime timestamp
time.Sleep(1 * time.Second)
Expect(f.AsKubeAdmin.HasController.SetComponentAnnotation(componentName, controllers.BuildRequestAnnotationName, controllers.BuildRequestTriggerSimpleBuildAnnotationValue, testNamespace)).To(Succeed())
})

It("another pipelineRun is triggered", func() {
//Expect pipelinerun count to be 2
Eventually(func() error {
pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace)
if err != nil {
GinkgoWriter.Println("Second piplelineRun has not been created yet")
return err
}
if len(pipelineRuns.Items) != 2 {
return fmt.Errorf("pipelinerun count in the namespace %s is not two, got pipelineruns %v", testNamespace, pipelineRuns.Items)
}
return nil
}, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), "timeout while waiting for second pipelinerun to start")
})

It("component build annotation is correct", func() {
var buildStatus *controllers.BuildStatus

Eventually(func() (bool, error) {
component, err := f.AsKubeAdmin.HasController.GetComponent(componentName, testNamespace)
if err != nil {
GinkgoWriter.Printf("cannot get the component: %v\n", err)
return false, err
}

buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName]
GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue)
statusBytes := []byte(buildStatusAnnotationValue)

err = json.Unmarshal(statusBytes, &buildStatus)
if err != nil {
GinkgoWriter.Printf("cannot unmarshal build status: %v\n", err)
return false, err
}

if buildStatus.Simple != nil {
GinkgoWriter.Printf("buildStartTime: %s\n", buildStatus.Simple.BuildStartTime)
} else {
GinkgoWriter.Println("build status does not have simple field")
}

return buildStatus.Simple != nil && buildStatus.Simple.BuildStartTime != lastBuildStartTime, nil
}, timeout, interval).Should(BeTrue(), "build status has unexpected content")
})

It("handles invalid request annotation", func() {

invalidAnnotation := "foo"
expectedInvalidAnnotationMessage := fmt.Sprintf("unexpected build request: %s", invalidAnnotation)

Expect(f.AsKubeAdmin.HasController.SetComponentAnnotation(componentName, controllers.BuildRequestAnnotationName, invalidAnnotation, testNamespace)).To(Succeed())

// Waiting for 2 minute to see if any more pipelinerun is triggered
Consistently(func() (bool, error) {
pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace)
if err != nil {
return false, err
}
if len(pipelineRuns.Items) != 2 {
return false, fmt.Errorf("pipelinerun count in the namespace %s is not two, got pipelineruns %v", testNamespace, pipelineRuns.Items)
}
return true, nil
}, time.Minute*2, constants.PipelineRunPollingInterval).Should(BeTrue(), "timeout while checking if any more pipelinerun is triggered")
// Waiting for 1 minute to see if any pipelinerun is triggered
Consistently(func() bool {
_, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "")
Expect(err).To(HaveOccurred())
return strings.Contains(err.Error(), "no pipelinerun found")
}, time.Minute*1, constants.PipelineRunPollingInterval).Should(BeTrue(), "timeout while checking if any pipelinerun is triggered")

buildStatus := &controllers.BuildStatus{}
Eventually(func() error {
Expand Down Expand Up @@ -1286,7 +1169,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser

Describe("A secret with dummy quay.io credentials is created in the testing namespace", Ordered, func() {

var applicationName, componentName, testNamespace string
var applicationName, componentName, testNamespace, pacBranchName, componentBaseBranchName string
var timeout time.Duration
var err error
var pr *pipeline.PipelineRun
Expand Down Expand Up @@ -1332,19 +1215,25 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser
Expect(err).ToNot(HaveOccurred())

componentName = "build-suite-test-secret-overriding"
pacBranchName = constants.PaCPullRequestBranchPrefix + componentName
componentBaseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6))
err = f.AsKubeAdmin.CommonController.Github.CreateRef(helloWorldComponentGitSourceCloneRepoName, "main", helloWorldComponentCloneRevision, componentBaseBranchName)
Expect(err).ShouldNot(HaveOccurred())

componentObj := appservice.ComponentSpec{
ComponentName: componentName,
Application: applicationName,
Source: appservice.ComponentSource{
ComponentSourceUnion: appservice.ComponentSourceUnion{
GitSource: &appservice.GitSource{
URL: helloWorldComponentGitSourceURL,
URL: helloWorldComponentGitSourceCloneURL,
Revision: componentBaseBranchName,
DockerfileURL: constants.DockerFilePath,
},
},
},
}
_, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, constants.DefaultDockerBuildPipelineBundle)
_, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.DefaultDockerBuildPipelineBundle))
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -1355,6 +1244,17 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser
Expect(f.AsKubeAdmin.TektonController.DeleteAllPipelineRunsInASpecificNamespace(testNamespace)).To(Succeed())
Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue())
}
// Delete new branches created by PaC and a testing branch used as a component's base branch
err = f.AsKubeAdmin.CommonController.Github.DeleteRef(helloWorldComponentGitSourceCloneRepoName, pacBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
err = f.AsKubeAdmin.CommonController.Github.DeleteRef(helloWorldComponentGitSourceCloneRepoName, componentBaseBranchName)
if err != nil {
Expect(err.Error()).To(ContainSubstring("Reference does not exist"))
}
// Delete created webhook from GitHub
cleanupWebhooks(f, helloWorldComponentGitSourceCloneRepoName)
})

It("should override the shared secret", func() {
Expand All @@ -1372,7 +1272,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser

pr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "")
Expect(err).ShouldNot(HaveOccurred())
Expect(pr.Spec.Workspaces).To(HaveLen(1))
Expect(pr.Spec.Workspaces).To(HaveLen(2))
})

It("should not be possible to push to quay.io repo (PipelineRun should fail)", func() {
Expand Down
Loading

0 comments on commit 39d1862

Please sign in to comment.