Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a common function to exit ReconcileKind #2805

Merged

Conversation

afrittoli
Copy link
Member

@afrittoli afrittoli commented Jun 11, 2020

Changes

Similar to what we did on the taskrun reconciler, define a function
finishReconcileUpdateEmitEvents that is always invoked when exiting
from ReconcileKind.

The function is responsible for dealing with label/annotation
updates as well as emitting events related to status changes.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Similar to what we did on the taskrun reconciler, define a function
finishReconcileUpdateEmitEvents that is always invoked when exiting
from ReconcileKind.

The function is responsible for dealing with label/annotation
updates as well as emitting events related to status changes.
@tekton-robot tekton-robot requested review from bobcatfish and a user June 11, 2020 14:24
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 11, 2020
@afrittoli
Copy link
Member Author

/kind cleanup

@tekton-robot tekton-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jun 11, 2020
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/pipelinerun.go 82.0% 83.0% 1.0
pkg/reconciler/taskrun/taskrun.go 77.7% 77.6% -0.1

@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

1 similar comment
@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@afrittoli afrittoli added this to the Pipelines v0.14 milestone Jun 15, 2020
@ghost
Copy link

ghost commented Jun 16, 2020

Looks good; suggest removing Release Notes section of PR but otherwise 👍

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 16, 2020
if err != nil {
// This should not fail. Return the error so we can re-try later.
logger.Errorf("Error while syncing the pipelinerun status: %v", err.Error())
return c.finishReconcileUpdateEmitEvents(ctx, pr, before, err)
}

Copy link
Member

@pritidesai pritidesai Jun 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @afrittoli, I am still trying to understand these changes, compared to taskRun, we are missing before here before reconciling ... this before condition is used while updating emit events, would it cause any conflicting events? 🤔

	// Store the condition before reconcile
	before := tr.Status.GetCondition(apis.ConditionSucceeded)

	// Reconcile this copy of the task run and then write back any status
	// updates regardless of whether the reconciliation errored out.
	if err = c.reconcile(ctx, tr, taskSpec, rtr); err != nil {
		logger.Errorf("Reconcile error: %v", err.Error())
	}
	// Emit events (only when ConditionSucceeded was changed)
	return c.finishReconcileUpdateEmitEvents(ctx, tr, before, err)

please feel free to ignore if its not relevant here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a before here, but it's earlier in the reconciler code. The reason being is that the code for sending the start even is not yet in for pipelineruns. Once I add that, I will need to move L133 further down in the reconcile code, similar to what taskrun does.

afterCondition := pr.Status.GetCondition(apis.ConditionSucceeded)
events.Emit(recorder, beforeCondition, afterCondition, pr)
_, err := c.updateLabelsAndAnnotations(pr)
if err != nil {
Copy link
Member

@pritidesai pritidesai Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no issues here with these changes but this same check is missing from the taskrun finishReconcileUpdateEmitEvents:

	_, err := c.updateLabelsAndAnnotations(tr)
	events.EmitError(recorder, err, tr)

taskrun emits error event without checking if err is nil, we can create a separate PR for adding that check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just read the comments from the taskrun PR, if EmitError has check for nil, should we drop the check from here like taskrun reconciler? Or do we still want to keep it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we drop nil check from here, no need for the logger as well ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the check here because @bobcatfish mentioned before that she didn't like the check to be in EmitError only, so I was planning on changing that in the task run controller too (but in a different PR)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @afrittoli

@bobcatfish
Copy link
Collaborator

Looks like the release notes section should get removed

@afrittoli
Copy link
Member Author

Nice catch, thanks. It should be ok now

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 19, 2020
@afrittoli
Copy link
Member Author

/test tekton-pipeline-unit-tests

@afrittoli
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests

1 similar comment
@afrittoli
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests

@tekton-robot tekton-robot merged commit e2577a4 into tektoncd:master Jun 19, 2020
Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm late to the party, but this is great! 🎉

@@ -88,6 +88,8 @@ var _ taskrunreconciler.Interface = (*Reconciler)(nil)
func (c *Reconciler) ReconcileKind(ctx context.Context, tr *v1beta1.TaskRun) pkgreconciler.Event {
logger := logging.FromContext(ctx)
recorder := controller.GetEventRecorder(ctx)
// Read the initial condition
before := tr.Status.GetCondition(apis.ConditionSucceeded)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, no reason to be fetching that so many times if we can do it once :D

return c.finishReconcileUpdateEmitEvents(ctx, pr, before, err)
}

func (c *Reconciler) finishReconcileUpdateEmitEvents(ctx context.Context, pr *v1beta1.PipelineRun, beforeCondition *apis.Condition, previousError error) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really like having one function to handle this!

afrittoli added a commit to afrittoli/pipeline that referenced this pull request Jun 24, 2020
When finishReconcileUpdateEmitEvents was introduced in PR tektoncd#2805,
I forgot to remove one of the original event.Emit, so one event
was sent twice. The fake recorder sometimes probably recognised
the duplicate and filtered it out, causing flackiness in tests,
as unit tests expect a fixed number of events.

Thanks @GregDritschler for troubleshooting this!

Fixes: tektoncd#2857
@afrittoli afrittoli mentioned this pull request Jun 24, 2020
4 tasks
afrittoli added a commit to afrittoli/pipeline that referenced this pull request Jun 24, 2020
When finishReconcileUpdateEmitEvents was introduced in PR tektoncd#2805,
I forgot to remove one of the original event.Emit, so one event
was sent twice. The fake recorder sometimes probably recognised
the duplicate and filtered it out, causing flackiness in tests,
as unit tests expect a fixed number of events.

Thanks @GregDritschler for troubleshooting this!

Fixes: tektoncd#2857
tekton-robot pushed a commit that referenced this pull request Jun 24, 2020
When finishReconcileUpdateEmitEvents was introduced in PR #2805,
I forgot to remove one of the original event.Emit, so one event
was sent twice. The fake recorder sometimes probably recognised
the duplicate and filtered it out, causing flackiness in tests,
as unit tests expect a fixed number of events.

Thanks @GregDritschler for troubleshooting this!

Fixes: #2857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants