-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Define a common function to exit ReconcileKind #2805
Conversation
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.
/kind cleanup |
The following is the coverage report on the affected files.
|
This PR cannot be merged: expecting exactly one kind/ label Available
|
1 similar comment
This PR cannot be merged: expecting exactly one kind/ label Available
|
Looks good; suggest removing Release Notes section of PR but otherwise 👍 /approve |
[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 |
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) | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ...
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @afrittoli
Looks like the release notes section should get removed |
Nice catch, thanks. It should be ok now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/test tekton-pipeline-unit-tests |
/test pull-tekton-pipeline-integration-tests |
1 similar comment
/test pull-tekton-pipeline-integration-tests |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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!
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
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
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
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:
cmd
dir, please updatethe release Task to build and release this image.
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.