-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Baran Dalgic
committed
Nov 15, 2021
1 parent
77b7cf2
commit 0add676
Showing
10 changed files
with
167 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 0 additions & 103 deletions
103
pkg/reconciler/buildrun/resources/failureDetails_test.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
pkg/reconciler/buildrun/resources/failure_details_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright The Shipwright Contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package resources | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
corev1 "k8s.io/api/core/v1" | ||
"knative.dev/pkg/apis" | ||
|
||
|
||
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" | ||
buildfakes "github.com/shipwright-io/build/pkg/controller/fakes" | ||
) | ||
|
||
var _ = Describe("Surfacing errors", func() { | ||
Context("resources.UpdateBuildRunUsingTaskFailures", func() { | ||
ctx := context.Background() | ||
client := &buildfakes.FakeClient{} | ||
|
||
It("surfaces errors to BuildRun in failed TaskRun", func() { | ||
redTaskRun := pipelinev1beta1.TaskRun{} | ||
redTaskRun.Status.Conditions = append(redTaskRun.Status.Conditions, | ||
apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelinev1beta1.TaskRunReasonFailed.String()}) | ||
failedStep := pipelinev1beta1.StepState{} | ||
|
||
errorReasonValue := "PullBaseImageFailed" | ||
errorMessageValue := "Failed to pull the base image." | ||
errorReasonKey := fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultErrorReason) | ||
errorMessageKey := fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultErrorMessage) | ||
|
||
errorReason := pipelinev1beta1.PipelineResourceResult{Key: errorReasonKey, Value: errorReasonValue} | ||
errorMessage := pipelinev1beta1.PipelineResourceResult{Key: errorMessageKey, Value: errorMessageValue} | ||
unrelated := pipelinev1beta1.PipelineResourceResult{Key: "unrelated-resource-key", Value: "Unrelated resource value"} | ||
|
||
message, _ := json.Marshal([]pipelinev1beta1.PipelineResourceResult{errorReason, errorMessage, unrelated}) | ||
|
||
failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} | ||
|
||
redTaskRun.Status.Steps = append(redTaskRun.Status.Steps, failedStep) | ||
redBuild := buildv1alpha1.BuildRun{} | ||
|
||
UpdateBuildRunUsingTaskFailures(ctx, client, &redBuild, &redTaskRun) | ||
|
||
Expect(redBuild.Status.FailureDetails.Message).To(Equal(errorMessageValue)) | ||
Expect(redBuild.Status.FailureDetails.Reason).To(Equal(errorReasonValue)) | ||
}) | ||
|
||
It("does not surface unrelated Tekton resources if the TaskRun fails", func() { | ||
redTaskRun := pipelinev1beta1.TaskRun{} | ||
redTaskRun.Status.Conditions = append(redTaskRun.Status.Conditions, | ||
apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelinev1beta1.TaskRunReasonFailed.String()}) | ||
failedStep := pipelinev1beta1.StepState{} | ||
|
||
unrelated := pipelinev1beta1.PipelineResourceResult{Key: "unrelated", Value: "unrelated"} | ||
|
||
message, _ := json.Marshal([]pipelinev1beta1.PipelineResourceResult{unrelated}) | ||
|
||
failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} | ||
|
||
redTaskRun.Status.Steps = append(redTaskRun.Status.Steps, failedStep) | ||
redBuild := buildv1alpha1.BuildRun{} | ||
|
||
UpdateBuildRunUsingTaskFailures(ctx, client, &redBuild, &redTaskRun) | ||
|
||
Expect(redBuild.Status.FailureDetails.Reason).To(BeEmpty()) | ||
Expect(redBuild.Status.FailureDetails.Message).To(BeEmpty()) | ||
}) | ||
|
||
It("should not surface errors for a successful TaskRun", func() { | ||
greenTaskRun := pipelinev1beta1.TaskRun{} | ||
greenTaskRun.Status.Conditions = append(greenTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded}) | ||
greenBuildRun := buildv1alpha1.BuildRun{} | ||
|
||
UpdateBuildRunUsingTaskFailures(ctx, client, &greenBuildRun, &greenTaskRun) | ||
|
||
Expect(greenBuildRun.Status.FailureDetails).To(BeNil()) | ||
}) | ||
|
||
It("should not surface errors if the TaskRun does not have a Succeeded condition", func() { | ||
unfinishedTaskRun := pipelinev1beta1.TaskRun{} | ||
unfinishedTaskRun.Status.Conditions = append(unfinishedTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionReady}) | ||
unfinishedBuildRun := buildv1alpha1.BuildRun{} | ||
|
||
UpdateBuildRunUsingTaskFailures(ctx, client, &unfinishedBuildRun, &unfinishedTaskRun) | ||
Expect(unfinishedBuildRun.Status.FailureDetails).To(BeNil()) | ||
}) | ||
|
||
It("should not surface errors if the TaskRun is in progress", func() { | ||
unknownTaskRun := pipelinev1beta1.TaskRun{} | ||
unknownTaskRun.Status.Conditions = append(unknownTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded, Reason: "random"}) | ||
unknownBuildRun := buildv1alpha1.BuildRun{} | ||
|
||
UpdateBuildRunUsingTaskFailures(ctx, client, &unknownBuildRun, &unknownTaskRun) | ||
Expect(unknownBuildRun.Status.FailureDetails).To(BeNil()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters