Skip to content

Commit

Permalink
Merge pull request #960 from SaschaSchwarze0/sascha-error-events
Browse files Browse the repository at this point in the history
Fail in case there is an error event
  • Loading branch information
openshift-merge-robot authored Dec 10, 2021
2 parents 05251c4 + 435996f commit 973ef83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
kubernetes:
- v1.20.7
- v1.21.2
max-parallel: 1
max-parallel: 2
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down
102 changes: 25 additions & 77 deletions test/integration/buildruns_to_taskruns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {

var seq = []*v1alpha1.Condition{}
for event := range buildRunWitcher.ResultChan() {
if event.Type == watch.Error {
Fail(fmt.Sprintf("Unexpected error event: %v.", event.Object))
}
condition := event.Object.(*v1alpha1.BuildRun).Status.GetCondition(v1alpha1.Succeeded)
if condition != nil {
condition.LastTransitionTime = metav1.Time{Time: fakeTime}
Expand Down Expand Up @@ -152,106 +155,51 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {

Context("when condition status is false", func() {
It("reflects a timeout", func() {
buildRunWitcher, build, buildRun := setupBuildAndBuildRun([]byte(test.BuildCBSWithShortTimeOut), []byte(test.MinimalBuildRun))

var timeout = time.After(tb.TimeOut)
go func() {
<-timeout
buildRunWitcher.Stop()
}()
_, build, buildRun := setupBuildAndBuildRun([]byte(test.BuildCBSWithShortTimeOut), []byte(test.MinimalBuildRun))

var seq = []*v1alpha1.Condition{}
for event := range buildRunWitcher.ResultChan() {
condition := event.Object.(*v1alpha1.BuildRun).Status.GetCondition(v1alpha1.Succeeded)
if condition != nil {
seq = append(seq, condition)
}
buildRun, err := tb.GetBRTillCompletion(buildRun.Name)
Expect(err).ToNot(HaveOccurred())

// Pending -> Running
if condition != nil && condition.Status == corev1.ConditionFalse {
buildRunWitcher.Stop()
}
}

lastIdx := len(seq) - 1
Expect(lastIdx).To(BeNumerically(">", 0))
Expect(seq[lastIdx].Type).To(Equal(v1alpha1.Succeeded))
Expect(seq[lastIdx].Status).To(Equal(corev1.ConditionFalse))
Expect(seq[lastIdx].Reason).To(Equal("BuildRunTimeout"))
Expect(seq[lastIdx].Message).To(Equal(fmt.Sprintf("BuildRun %s failed to finish within %v", buildRun.Name, build.Spec.Timeout.Duration)))
condition := buildRun.Status.GetCondition(v1alpha1.Succeeded)
Expect(condition.Status).To(Equal(corev1.ConditionFalse))
Expect(condition.Reason).To(Equal("BuildRunTimeout"))
Expect(condition.Message).To(Equal(fmt.Sprintf("BuildRun %s failed to finish within %v", buildRun.Name, build.Spec.Timeout.Duration)))
})

It("reflects a failed reason", func() {
WithCustomClusterBuildStrategy([]byte(test.ClusterBuildStrategySingleStepKanikoError), func() {
buildRunWitcher, _, buildRun := setupBuildAndBuildRun([]byte(test.BuildCBSMinimal), []byte(test.MinimalBuildRun), STRATEGY+tb.Namespace+"custom")

var timeout = time.After(tb.TimeOut)
go func() {
<-timeout
buildRunWitcher.Stop()
}()

var seq = []*v1alpha1.Condition{}
for event := range buildRunWitcher.ResultChan() {
condition := event.Object.(*v1alpha1.BuildRun).Status.GetCondition(v1alpha1.Succeeded)
if condition != nil {
seq = append(seq, condition)
}

if condition != nil && condition.Status == corev1.ConditionFalse {
buildRunWitcher.Stop()
}
}
_, _, buildRun := setupBuildAndBuildRun([]byte(test.BuildCBSMinimal), []byte(test.MinimalBuildRun), STRATEGY+tb.Namespace+"custom")

buildRun, err = tb.GetBR(buildRun.Name)
buildRun, err := tb.GetBRTillCompletion(buildRun.Name)
Expect(err).ToNot(HaveOccurred())
Expect(buildRun.Status.CompletionTime).ToNot(BeNil())

taskRun, err := tb.GetTaskRunFromBuildRun(buildRun.Name)
Expect(err).ToNot(HaveOccurred())

Expect(buildRun.Status.FailedAt.Pod).To(Equal(taskRun.Status.PodName))
Expect(buildRun.Status.FailedAt.Container).To(Equal("step-" + "step-build-and-push"))

lastIdx := len(seq) - 1
Expect(lastIdx).To(BeNumerically(">", 0))
Expect(seq[lastIdx].Type).To(Equal(v1alpha1.Succeeded))
Expect(seq[lastIdx].Status).To(Equal(corev1.ConditionFalse))
Expect(seq[lastIdx].Reason).To(Equal("Failed"))
Expect(seq[lastIdx].Message).To(ContainSubstring("buildrun step %s failed in pod %s", "step-step-build-and-push", taskRun.Status.PodName))
Expect(buildRun.Status.FailedAt.Container).To(Equal("step-step-build-and-push"))

condition := buildRun.Status.GetCondition(v1alpha1.Succeeded)
Expect(condition.Status).To(Equal(corev1.ConditionFalse))
Expect(condition.Reason).To(Equal("Failed"))
Expect(condition.Message).To(ContainSubstring("buildrun step %s failed in pod %s", "step-step-build-and-push", taskRun.Status.PodName))
})
})
})

Context("when condition status true", func() {
It("should reflect the taskrun succeeded reason in the buildrun condition", func() {
WithCustomClusterBuildStrategy([]byte(test.ClusterBuildStrategyNoOp), func() {
buildRunWitcher, _, _ := setupBuildAndBuildRun([]byte(test.BuildCBSMinimal), []byte(test.MinimalBuildRun), STRATEGY+tb.Namespace+"custom")
_, _, buildRun := setupBuildAndBuildRun([]byte(test.BuildCBSMinimal), []byte(test.MinimalBuildRun), STRATEGY+tb.Namespace+"custom")

var timeout = time.After(tb.TimeOut)
go func() {
<-timeout
buildRunWitcher.Stop()
}()

var seq = []*v1alpha1.Condition{}
for event := range buildRunWitcher.ResultChan() {
condition := event.Object.(*v1alpha1.BuildRun).Status.GetCondition(v1alpha1.Succeeded)
if condition != nil {
seq = append(seq, condition)
}

if condition != nil && condition.Status == corev1.ConditionTrue {
buildRunWitcher.Stop()
}
}
buildRun, err := tb.GetBRTillCompletion(buildRun.Name)
Expect(err).ToNot(HaveOccurred())

lastIdx := len(seq) - 1
Expect(lastIdx).To(BeNumerically(">", 0))
Expect(seq[lastIdx].Type).To(Equal(v1alpha1.Succeeded))
Expect(seq[lastIdx].Status).To(Equal(corev1.ConditionTrue))
Expect(seq[lastIdx].Reason).To(Equal("Succeeded"))
Expect(seq[lastIdx].Message).To(ContainSubstring("All Steps have completed executing"))
condition := buildRun.Status.GetCondition(v1alpha1.Succeeded)
Expect(condition.Status).To(Equal(corev1.ConditionTrue))
Expect(condition.Reason).To(Equal("Succeeded"))
Expect(condition.Message).To(ContainSubstring("All Steps have completed executing"))
})
})
})
Expand Down

0 comments on commit 973ef83

Please sign in to comment.