Skip to content

Commit

Permalink
minor cleanup, integration test update redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
gabemontero committed Jul 5, 2021
1 parent cf56b96 commit 9227e9f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/buildrun.md
Expand Up @@ -189,6 +189,7 @@ The following table illustrates the different states a BuildRun can have under i
| Unknown | Running | No | The BuildRun has been validate and started to perform its work. |l
| Unknown | Running | No | The BuildRun has been validate and started to perform its work. |
| Unknown | BuildRunCanceled | No | The user requested the BuildRun to be canceled. This results in the BuildRun controller requesting the TaskRun be canceled. Cancellation has not been done yet. |
| True | Succeeded | Yes | The BuildRun Pod is done. |
| False | Failed | Yes | The BuildRun failed in one of the steps. |
| False | BuildRunTimeout | Yes | The BuildRun timed out. |
| False | UnknownStrategyKind | Yes | The Build specified strategy Kind is unknown. (_options: ClusterBuildStrategy or BuildStrategy_) |
Expand Down
5 changes: 1 addition & 4 deletions pkg/reconciler/buildrun/controller.go
Expand Up @@ -66,17 +66,14 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo

// Avoid reconciling when for updates on the BuildRun the following takes place
// - the build.shipwright.io/name label is set
// - when a BuildRun already have a referenced TaskRun, but the latest version is not cancelled
// - when a BuildRun already have a referenced TaskRun, but the latest version is not canceled
// - when a BuildRun have a completionTime set
switch {
case o.GetLabels()[buildv1alpha1.LabelBuild] == "":
ctxlog.Info(ctx, "abort 1")
return false
case o.Status.LatestTaskRunRef != nil && !n.IsCanceled():
ctxlog.Info(ctx, "abort 2")
return false
case o.Status.CompletionTime != nil:
ctxlog.Info(ctx, "abort 3")
return false
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/buildrun/resources/conditions.go
Expand Up @@ -46,10 +46,12 @@ func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Clie
case v1beta1.TaskRunReasonRunning:
if buildRun.IsCanceled() {
status = corev1.ConditionUnknown // in practice the taskrun status is already unknown in this case, but we are making sure here
reason = buildv1alpha1.BuildRunStateOverrideCanceled
message = "The user requested the BuildRun to be canceled. This BuildRun controller has requested the TaskRun be canceled. That request has not been process by Tekton's TaskRun controller yet."
}
case v1beta1.TaskRunReasonCancelled:
if buildRun.IsCanceled() {
status = corev1.ConditionFalse // in practice the taskrun status is already false in this case, bue we are making sure here
reason = buildv1alpha1.BuildRunStateOverrideCanceled
message = "The BuildRun and underlying TaskRun were canceled successfully."
}
Expand Down
21 changes: 18 additions & 3 deletions test/integration/buildruns_to_sa_test.go
Expand Up @@ -6,10 +6,13 @@ package integration_test

import (
"fmt"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/test"
Expand Down Expand Up @@ -148,11 +151,23 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() {
Expect(contains(sa.Secrets, buildObject.Spec.Output.Credentials.Name)).To(BeTrue())

// cancel the br
bro.Spec.StateOverride = v1alpha1.BuildRunStateOverrideCanceled
err = tb.UpdateBR(bro)
err = wait.PollImmediate(1*time.Second, 4*time.Second, func() (done bool, err error) {
bro, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
GinkgoT().Logf("error on br get: %s\n", err.Error())
return false, nil
}

bro.Spec.StateOverride = v1alpha1.BuildRunStateOverrideCanceled
err = tb.UpdateBR(bro)
if err != nil {
GinkgoT().Logf("error on br update: %s\n", err.Error())
return false, nil
}
return true, nil
})
Expect(err).To(BeNil())

// confirm cancelled set
expectedReason := v1alpha1.BuildRunStateOverrideCanceled
actualReason, err := tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired BuildRun reason; expected %s, got %s", expectedReason, actualReason))
Expand Down
20 changes: 16 additions & 4 deletions test/integration/buildruns_to_taskruns_test.go
Expand Up @@ -14,8 +14,10 @@ import (

"github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/build/test"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
)

Expand Down Expand Up @@ -406,11 +408,21 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {

Expect(tb.CreateBR(buildRunObject)).To(BeNil())

bro, err := tb.GetBRTillStartTime(buildRunObject.Name)
Expect(err).To(BeNil())
err := wait.PollImmediate(1*time.Second, 4*time.Second, func() (done bool, err error) {
bro, err := tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
GinkgoT().Logf("error on br get: %s\n", err.Error())
return false, nil
}

bro.Spec.StateOverride = v1alpha1.BuildRunStateOverrideCanceled
err = tb.UpdateBR(bro)
bro.Spec.StateOverride = v1alpha1.BuildRunStateOverrideCanceled
err = tb.UpdateBR(bro)
if err != nil {
GinkgoT().Logf("error on br update: %s\n", err.Error())
return false, nil
}
return true, nil
})
Expect(err).To(BeNil())

expectedReason := "TaskRunCancelled"
Expand Down

0 comments on commit 9227e9f

Please sign in to comment.