Skip to content

Commit

Permalink
dbg
Browse files Browse the repository at this point in the history
  • Loading branch information
gabemontero committed Jul 5, 2021
1 parent 4e81332 commit bd79905
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 9 deletions.
11 changes: 11 additions & 0 deletions pkg/reconciler/buildrun/buildrun.go
Expand Up @@ -101,6 +101,13 @@ func (r *ReconcileBuildRun) Reconcile(request reconcile.Request) (reconcile.Resu
getTaskRunErr = r.client.Get(ctx, types.NamespacedName{Name: *buildRun.Status.LatestTaskRunRef, Namespace: request.Namespace}, lastTaskRun)
}

brBuf, _ := json.MarshalIndent(buildRun, "", " ")
trBuf, _ := json.MarshalIndent(lastTaskRun, "", " ")
ctxlog.Info(ctx, fmt.Sprintf("GGM reconcile top level br obj %s", string(brBuf)))
ctxlog.Info(ctx, fmt.Sprintf("GGM reconcile top level br obj err %#v", getBuildRunErr))
ctxlog.Info(ctx, fmt.Sprintf("GGM reconcile top level tr obj %s", string(trBuf)))
ctxlog.Info(ctx, fmt.Sprintf("GGM reconcile top level tr obj err %#v", getTaskRunErr))

// for existing TaskRuns update the BuildRun Status, if there is no TaskRun, then create one
if getTaskRunErr != nil {
if apierrors.IsNotFound(getTaskRunErr) {
Expand Down Expand Up @@ -253,6 +260,10 @@ func (r *ReconcileBuildRun) Reconcile(request reconcile.Request) (reconcile.Resu
} else if apierrors.IsNotFound(getBuildRunErr) {
// this is a TR event, try getting the br from the label on the tr
err := r.GetBuildRunObject(ctx, lastTaskRun.Labels[buildv1alpha1.LabelBuildRun], request.Namespace, buildRun)
brBuf, _ := json.MarshalIndent(buildRun, "", " ")
ctxlog.Info(ctx, fmt.Sprintf("GGM task exist path br %s", string(brBuf)))
ctxlog.Info(ctx, fmt.Sprintf("GGM task exist path br err %#v", err))

if err != nil && !apierrors.IsNotFound(err) {
return reconcile.Result{}, err
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/reconciler/buildrun/controller.go
Expand Up @@ -65,18 +65,15 @@ func add(ctx context.Context, mgr manager.Manager, r reconcile.Reconciler, maxCo
n := e.ObjectNew.(*buildv1alpha1.BuildRun)

// Avoid reconciling when for updates on the BuildRun the following takes place
// - the build.shipwright.io/name label is set
// - the build.shipwright.io/name label is not set
// - when a BuildRun already have a referenced TaskRun, but the latest version is not cancelled
// - 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
56 changes: 56 additions & 0 deletions test/integration/build_to_buildruns_test.go
Expand Up @@ -112,6 +112,12 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

br, err := tb.GetBRTillCompletion(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

}
Expect(err).To(BeNil())
Expect(br.Status.GetCondition(v1alpha1.Succeeded).Status).To(Equal(corev1.ConditionFalse))
Expect(br.Status.GetCondition(v1alpha1.Succeeded).Reason).To(Equal("BuildRunTimeout"))
Expand All @@ -135,6 +141,12 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(tb.CreateBR(buildRun)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRun.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRun.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

}
Expect(err).To(BeNil())

tr, err := tb.GetTaskRunFromBuildRun(buildRun.Name)
Expand Down Expand Up @@ -163,6 +175,11 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {

// Wait for BR to get an Starttime
_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

//Delete Build
Expand Down Expand Up @@ -192,6 +209,12 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

}
Expect(err).To(BeNil())

Expect(tb.DeleteBuild(BUILD + tb.Namespace)).To(BeNil())
Expand Down Expand Up @@ -326,9 +349,19 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(tb.CreateBR(buildRun02)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRun01.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRun01.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRun02.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRun02.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

tr01, err := tb.GetTaskRunFromBuildRun(buildRun01.Name)
Expand Down Expand Up @@ -372,6 +405,12 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(tb.CreateBR(autoDeleteBuildRun)).To(BeNil())

_, err = tb.GetBRTillStartTime(autoDeleteBuildRun.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(autoDeleteBuildRun.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

}
Expect(err).To(BeNil())

br, err := tb.GetBRTillOwner(BUILDRUN+tb.Namespace, buildObject.Name)
Expand Down Expand Up @@ -404,6 +443,11 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(tb.CreateBR(autoDeleteBuildRun)).To(BeNil())

_, err = tb.GetBRTillStartTime(autoDeleteBuildRun.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(autoDeleteBuildRun.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

// we modify the annotation so automatic delete does not take place
Expand Down Expand Up @@ -436,6 +480,12 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(tb.CreateBR(autoDeleteBuildRun)).To(BeNil())

_, err = tb.GetBRTillStartTime(autoDeleteBuildRun.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(autoDeleteBuildRun.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

}
Expect(err).To(BeNil())

// we remove the annotation so automatic delete does not take place, "/" is escaped by "~1" in a JSON pointer
Expand Down Expand Up @@ -477,6 +527,12 @@ var _ = Describe("Integration tests Build and BuildRuns", func() {
Expect(patchedBuild.Annotations[v1alpha1.AnnotationBuildRunDeletion]).To(Equal("false"))

_, err = tb.GetBRTillStartTime(autoDeleteBuildRun.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(autoDeleteBuildRun.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

}
Expect(err).To(BeNil())

// we modify the annotation one more time, to validate that the build should be deleted this time
Expand Down
15 changes: 15 additions & 0 deletions test/integration/buildruns_to_sa_test.go
Expand Up @@ -90,6 +90,11 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

sa, err := tb.GetSA(fmt.Sprintf("%s-sa", buildRunObject.Name))
Expand Down Expand Up @@ -197,6 +202,11 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

tr, err := tb.GetTaskRunFromBuildRun(buildRunObject.Name)
Expand All @@ -217,6 +227,11 @@ var _ = Describe("Integration tests BuildRuns and Service-accounts", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

tr, err := tb.GetTaskRunFromBuildRun(buildRunObject.Name)
Expand Down
32 changes: 27 additions & 5 deletions test/integration/buildruns_to_taskruns_test.go
Expand Up @@ -260,6 +260,11 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
_, _, buildRunObject := setupBuildAndBuildRun([]byte(test.BuildCBSMinimal), []byte(test.MinimalBuildRun), STRATEGY+tb.Namespace+"custom")

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

// Pending is an intermediate state where a certain amount of luck is needed to capture it with a polling interval of 3s.
Expand All @@ -276,11 +281,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
*/

expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

expectedReason = "Running"
actualReason, err = tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason)
actualReason, err := tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
})
})
Expand Down Expand Up @@ -374,6 +375,11 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

tr, err := tb.GetTaskRunFromBuildRun(buildRunObject.Name)
Expand Down Expand Up @@ -407,6 +413,11 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

bro, err := tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

bro.Spec.StateOverride = v1alpha1.BuildRunStateOverrideCanceled
Expand Down Expand Up @@ -440,6 +451,11 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

tr, err := tb.GetTaskRunFromBuildRun(buildRunObject.Name)
Expand All @@ -460,6 +476,12 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() {
_, _, buildRunObject := setupBuildAndBuildRun([]byte(test.BuildCBSMinimal), []byte(test.MinimalBuildRun), STRATEGY+tb.Namespace+"custom")

_, err = tb.GetBRTillCompletion(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

}
Expect(err).To(BeNil())

reason, err := tb.GetBRReason(buildRunObject.Name)
Expand Down
15 changes: 15 additions & 0 deletions test/integration/buildstrategy_to_taskruns_test.go
Expand Up @@ -5,6 +5,7 @@
package integration_test

import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
Expand Down Expand Up @@ -74,6 +75,11 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() {
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

taskRun, err := tb.GetTaskRunFromBuildRun(buildRunObject.Name)
Expand Down Expand Up @@ -134,6 +140,11 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() {

// Wait until the BuildRun is registered
_, err = tb.GetBRTillStartTime(br.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(br.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

}
Expand Down Expand Up @@ -321,6 +332,10 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() {

constructBuildRunObjectAndWait(buildRunObject)

expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
Expect(err).To(BeNil())

Expand Down
6 changes: 6 additions & 0 deletions test/integration/clusterbuildstrategy_to_taskruns_test.go
Expand Up @@ -5,6 +5,7 @@
package integration_test

import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -73,6 +74,11 @@ var _ = Describe("Integration tests ClusterBuildStrategies and TaskRuns", func()
Expect(tb.CreateBR(buildRunObject)).To(BeNil())

_, err = tb.GetBRTillStartTime(buildRunObject.Name)
if err != nil {
expectedReason := "Running"
actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason)
Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason))
}
Expect(err).To(BeNil())

taskRun, err := tb.GetTaskRunFromBuildRun(buildRunObject.Name)
Expand Down

0 comments on commit bd79905

Please sign in to comment.