Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tektoncd/pipeline
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8d24f0fb58e7c8735adde9abef24dcccd8719b66
Choose a base ref
..
head repository: tektoncd/pipeline
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a851d0c73aea0eee1b6adb94967d2a6bcb304251
Choose a head ref
Showing with 61 additions and 3 deletions.
  1. +3 −0 pkg/reconciler/taskrun/taskrun.go
  2. +58 −3 pkg/reconciler/taskrun/taskrun_test.go
3 changes: 3 additions & 0 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
@@ -341,6 +341,9 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1alpha1.TaskRun,
if k8serrors.IsNotFound(err) {
// Keep going, this will result in the Pod being created below.
} else if err != nil {
// This is considered a transient error, so we return error, do not update
// the task run condition, and return an error which will cause this key to
// be requeued for reconcile.
c.Logger.Errorf("Error getting pod %q: %v", tr.Status.PodName, err)
return err
}
61 changes: 58 additions & 3 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
@@ -1377,8 +1377,10 @@ func TestReconcilePodUpdateStatus(t *testing.T) {
defer cancel()
c := testAssets.Controller
clients := testAssets.Clients
reconciler := c.Reconciler.(*Reconciler)
fr := reconciler.Recorder.(*record.FakeRecorder)

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
if err := reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
t.Fatalf("Unexpected error when Reconcile() : %v", err)
}
newTr, err := clients.Pipeline.TektonV1alpha1().TaskRuns(taskRun.Namespace).Get(taskRun.Name, metav1.GetOptions{})
@@ -1417,6 +1419,16 @@ func TestReconcilePodUpdateStatus(t *testing.T) {
}, newTr.Status.GetCondition(apis.ConditionSucceeded), ignoreLastTransitionTime); d != "" {
t.Errorf("Did not get expected condition (-want, +got): %v", d)
}

wantEvents := []string{
"Normal Started ",
"Normal Running Not all Steps",
"Normal Succeeded",
}
err = checkEvents(fr, "test-reconcile-pod-updateStatus", wantEvents)
if !(err == nil) {
t.Errorf(err.Error())
}
}

func TestReconcileOnCompletedTaskRun(t *testing.T) {
@@ -1472,8 +1484,10 @@ func TestReconcileOnCancelledTaskRun(t *testing.T) {
defer cancel()
c := testAssets.Controller
clients := testAssets.Clients
reconciler := c.Reconciler.(*Reconciler)
fr := reconciler.Recorder.(*record.FakeRecorder)

if err := c.Reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
if err := reconciler.Reconcile(context.Background(), getRunName(taskRun)); err != nil {
t.Fatalf("Unexpected error when reconciling completed TaskRun : %v", err)
}
newTr, err := clients.Pipeline.TektonV1alpha1().TaskRuns(taskRun.Namespace).Get(taskRun.Name, metav1.GetOptions{})
@@ -1490,12 +1504,22 @@ func TestReconcileOnCancelledTaskRun(t *testing.T) {
if d := cmp.Diff(expectedStatus, newTr.Status.GetCondition(apis.ConditionSucceeded), ignoreLastTransitionTime); d != "" {
t.Fatalf("Did not get expected condition (-want, +got): %v", d)
}

wantEvents := []string{
"Normal Started",
"Warning Failed TaskRun \"test-taskrun-run-cancelled\" was cancelled",
}
err = checkEvents(fr, "test-reconcile-on-cancelled-taskrun", wantEvents)
if !(err == nil) {
t.Errorf(err.Error())
}
}

func TestReconcileTimeouts(t *testing.T) {
type testCase struct {
taskRun *v1alpha1.TaskRun
expectedStatus *apis.Condition
wantEvents []string
}

testcases := []testCase{
@@ -1517,6 +1541,9 @@ func TestReconcileTimeouts(t *testing.T) {
Reason: "TaskRunTimeout",
Message: `TaskRun "test-taskrun-timeout" failed to finish within "10s"`,
},
wantEvents: []string{
"Warning Failed ",
},
}, {
taskRun: tb.TaskRun("test-taskrun-default-timeout-60-minutes",
tb.TaskRunNamespace("foo"),
@@ -1534,6 +1561,9 @@ func TestReconcileTimeouts(t *testing.T) {
Reason: "TaskRunTimeout",
Message: `TaskRun "test-taskrun-default-timeout-60-minutes" failed to finish within "1h0m0s"`,
},
wantEvents: []string{
"Warning Failed ",
},
}, {
taskRun: tb.TaskRun("test-taskrun-nil-timeout-default-60-minutes",
tb.TaskRunNamespace("foo"),
@@ -1552,6 +1582,9 @@ func TestReconcileTimeouts(t *testing.T) {
Reason: "TaskRunTimeout",
Message: `TaskRun "test-taskrun-nil-timeout-default-60-minutes" failed to finish within "1h0m0s"`,
},
wantEvents: []string{
"Warning Failed ",
},
}}

for _, tc := range testcases {
@@ -1563,6 +1596,8 @@ func TestReconcileTimeouts(t *testing.T) {
defer cancel()
c := testAssets.Controller
clients := testAssets.Clients
reconciler := c.Reconciler.(*Reconciler)
fr := reconciler.Recorder.(*record.FakeRecorder)

if err := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun)); err != nil {
t.Fatalf("Unexpected error when reconciling completed TaskRun : %v", err)
@@ -1575,6 +1610,10 @@ func TestReconcileTimeouts(t *testing.T) {
if d := cmp.Diff(tc.expectedStatus, condition, ignoreLastTransitionTime); d != "" {
t.Fatalf("Did not get expected condition (-want, +got): %v", d)
}
err = checkEvents(fr, tc.taskRun.Name, tc.wantEvents)
if !(err == nil) {
t.Errorf(err.Error())
}
}
}

@@ -2242,6 +2281,7 @@ func TestReconcileTaskResourceResolutionAndValidation(t *testing.T) {
desc string
d test.Data
wantFailedReason string
wantEvents []string
}{{
desc: "Fail ResolveTaskResources",
d: test.Data{
@@ -2263,6 +2303,10 @@ func TestReconcileTaskResourceResolutionAndValidation(t *testing.T) {
PipelineResources: nil,
},
wantFailedReason: podconvert.ReasonFailedResolution,
wantEvents: []string{
"Normal Started ",
"Warning Failed",
},
}, {
desc: "Fail ValidateResolvedTaskResources",
d: test.Data{
@@ -2281,14 +2325,20 @@ func TestReconcileTaskResourceResolutionAndValidation(t *testing.T) {
PipelineResources: nil,
},
wantFailedReason: podconvert.ReasonFailedValidation,
wantEvents: []string{
"Normal Started ",
"Warning Failed",
},
}} {
t.Run(tt.desc, func(t *testing.T) {
names.TestingSeed()
testAssets, cancel := getTaskRunController(t, tt.d)
defer cancel()
clients := testAssets.Clients
reconciler := testAssets.Controller.Reconciler.(*Reconciler)
fr := reconciler.Recorder.(*record.FakeRecorder)

if err := testAssets.Controller.Reconciler.Reconcile(context.Background(), getRunName(tt.d.TaskRuns[0])); err != nil {
if err := reconciler.Reconcile(context.Background(), getRunName(tt.d.TaskRuns[0])); err != nil {
t.Errorf("expected no error reconciling valid TaskRun but got %v", err)
}

@@ -2302,6 +2352,11 @@ func TestReconcileTaskResourceResolutionAndValidation(t *testing.T) {
t.Errorf("Expected TaskRun to \"%s\" but it did not. Final conditions were:\n%#v", tt.wantFailedReason, tr.Status.Conditions)
}
}

err = checkEvents(fr, tt.desc, tt.wantEvents)
if !(err == nil) {
t.Errorf(err.Error())
}
})
}
}