Skip to content

Commit

Permalink
Use informer cache in reconciler to get pipeline
Browse files Browse the repository at this point in the history
Reconciler now uses informer cache to get pipelines. This is to have
no traffic to the API server if no changes are needed because of the
reconcilation, e.g. reconcilation on completed pipelineruns.

Fixes: tektoncd#2740

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
  • Loading branch information
adshmh committed Jun 4, 2020
1 parent 8ff3169 commit 31ab61b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
23 changes: 10 additions & 13 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,11 @@ func (c *Reconciler) Reconcile(ctx context.Context, key string) error {
}

func (c *Reconciler) updatePipelineResults(ctx context.Context, pr *v1beta1.PipelineRun) {

// TODO: Use factory func instead of hard-coding this once OCI images are supported.
resolver := &resources.LocalPipelineRefResolver{
Namespace: pr.Namespace,
Tektonclient: c.PipelineClientSet,
}
pipelineMeta, pipelineSpec, err := resources.GetPipelineData(ctx, pr, resolver.GetPipeline)
pipelineMeta, pipelineSpec, err := resources.GetPipelineData(ctx, pr,
func(name string) (v1beta1.PipelineInterface, error) {
return c.pipelineLister.Pipelines(pr.Namespace).Get(name)
},
)
if err != nil {
if ce, ok := err.(*v1beta1.CannotConvertError); ok {
pr.Status.MarkResourceNotConvertible(ce)
Expand Down Expand Up @@ -336,12 +334,11 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun) err
// and may not have had all of the assumed default specified.
pr.SetDefaults(contexts.WithUpgradeViaDefaulting(ctx))

// TODO: Use factory func instead of hard-coding this once OCI images are supported.
resolver := &resources.LocalPipelineRefResolver{
Namespace: pr.Namespace,
Tektonclient: c.PipelineClientSet,
}
pipelineMeta, pipelineSpec, err := resources.GetPipelineData(ctx, pr, resolver.GetPipeline)
pipelineMeta, pipelineSpec, err := resources.GetPipelineData(ctx, pr,
func(name string) (v1beta1.PipelineInterface, error) {
return c.pipelineLister.Pipelines(pr.Namespace).Get(name)
},
)
if err != nil {
if ce, ok := err.(*v1beta1.CannotConvertError); ok {
pr.Status.MarkResourceNotConvertible(ce)
Expand Down
24 changes: 12 additions & 12 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestReconcile(t *testing.T) {
}

// Check that the expected TaskRun was created
actual := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject()
actual := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject()
expectedTaskRun := tb.TaskRun("test-pipeline-run-success-unit-test-1-mz4c7",
tb.TaskRunNamespace("foo"),
tb.TaskRunOwnerReference("PipelineRun", "test-pipeline-run-success",
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestReconcile_PipelineSpecTaskSpec(t *testing.T) {
}

// Check that the expected TaskRun was created
actual := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject()
actual := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject()
expectedTaskRun := tb.TaskRun("test-pipeline-run-success-unit-test-task-spec-9l9zj",
tb.TaskRunNamespace("foo"),
tb.TaskRunOwnerReference("PipelineRun", "test-pipeline-run-success",
Expand Down Expand Up @@ -826,11 +826,11 @@ func TestReconcileOnCompletedPipelineRun(t *testing.T) {
t.Fatalf("Error reconciling: %s", err)
}

if len(clients.Pipeline.Actions()) != 2 {
if len(clients.Pipeline.Actions()) != 1 {
t.Fatalf("Expected client to have updated the TaskRun status for a completed PipelineRun, but it did not")
}

_, ok := clients.Pipeline.Actions()[1].(ktesting.UpdateAction).GetObject().(*v1beta1.PipelineRun)
_, ok := clients.Pipeline.Actions()[0].(ktesting.UpdateAction).GetObject().(*v1beta1.PipelineRun)
if !ok {
t.Errorf("Expected a PipelineRun to be updated, but it wasn't.")
}
Expand Down Expand Up @@ -974,7 +974,7 @@ func TestReconcileWithTimeout(t *testing.T) {
}

// Check that the expected TaskRun was created
actual := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
actual := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
if actual == nil {
t.Fatalf("Expected a TaskRun to be created, but it wasn't.")
}
Expand Down Expand Up @@ -1189,7 +1189,7 @@ func TestReconcilePropagateLabels(t *testing.T) {
}

// Check that the expected TaskRun was created
actual := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
actual := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
if actual == nil {
t.Errorf("Expected a TaskRun to be created, but it wasn't.")
}
Expand Down Expand Up @@ -1420,7 +1420,7 @@ func TestReconcilePropagateAnnotations(t *testing.T) {
}

// Check that the expected TaskRun was created
actual := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
actual := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
if actual == nil {
t.Errorf("Expected a TaskRun to be created, but it wasn't.")
}
Expand Down Expand Up @@ -1585,7 +1585,7 @@ func TestReconcileAndPropagateCustomPipelineTaskRunSpec(t *testing.T) {
}

// Check that the expected TaskRun was created
actual := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
actual := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
if actual == nil {
t.Errorf("Expected a TaskRun to be created, but it wasn't.")
}
Expand Down Expand Up @@ -1690,8 +1690,8 @@ func TestReconcileWithConditionChecks(t *testing.T) {
}

// Check that the expected TaskRun was created
condCheck0 := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
condCheck1 := clients.Pipeline.Actions()[2].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
condCheck0 := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
condCheck1 := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
if condCheck0 == nil || condCheck1 == nil {
t.Errorf("Expected two ConditionCheck TaskRuns to be created, but it wasn't.")
}
Expand Down Expand Up @@ -1797,7 +1797,7 @@ func TestReconcileWithFailingConditionChecks(t *testing.T) {
}

// Check that the expected TaskRun was created
actual := clients.Pipeline.Actions()[1].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
actual := clients.Pipeline.Actions()[0].(ktesting.CreateAction).GetObject().(*v1beta1.TaskRun)
if actual == nil {
t.Errorf("Expected a ConditionCheck TaskRun to be created, but it wasn't.")
}
Expand Down Expand Up @@ -2642,7 +2642,7 @@ func TestReconcileOutOfSyncPipelineRun(t *testing.T) {
t.Fatalf("Error reconciling: %s", err)
}

_, ok := clients.Pipeline.Actions()[1].(ktesting.UpdateAction).GetObject().(*v1beta1.PipelineRun)
_, ok := clients.Pipeline.Actions()[0].(ktesting.UpdateAction).GetObject().(*v1beta1.PipelineRun)
if !ok {
t.Errorf("Expected a PipelineRun to be updated, but it wasn't.")
}
Expand Down

0 comments on commit 31ab61b

Please sign in to comment.