-
Notifications
You must be signed in to change notification settings - Fork 71
fix(expectation): more appropriate use of expectation #139
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
@googlebot I fixed it. |
/assign @terrytangyuan @gaocegege |
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. Others PTAL
// Creation is expected when there is no error returned | ||
// We use `RaiseExpectations` here to accumulate expectations since `SetExpectations` has no such kind of ability | ||
expectationPodsKey := expectation.GenExpectationPodsKey(jobKey, rt) | ||
jc.Expectations.RaiseExpectations(expectationPodsKey, 1, 0) |
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.
Seems arguments to RaiseExpectation
are all 1, 0 or 0, 1. Why not to use ExpectCreations
directly?
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.
Same question 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.
ExpectCreations(key, 1)
calls SetExpectations
underneath, it will set "expectedCreation" to 1
instead of adding them(expectedCreation += 1
). We are here to expect multiple creations, am i right?
As i mentioned in first comment(No. 1).
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.
Gotcha. SGTM.
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.
expectationPodsKey
represents a group of pods. It does expect multiple creations.
} | ||
|
||
// Convert ReplicaType to lower string. | ||
expectationServicesKey := expectation.GenExpectationServicesKey(jobKey, rtype) |
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.
Seems the change is to move code snippet to below? Is there a difference? line 311-313
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 expectCreation
here, the informer will never observe this creation since error is returned(such as GetPortsFromJob
) before service is created.
As i mentioned in first comment(No. 2).
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 see, it does have some places return err
before creating the services. Nice catch
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.
Github collapse some code snippets which make the review harder. :D
@eggiter Thanks for the contribution. I am curious if you meet some problems in current expectation implementation? We can better help review the changes with more context |
Detailed explanations are replied. |
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.
It's clean. Thanks for the PR.
} | ||
|
||
// Convert ReplicaType to lower string. | ||
expectationServicesKey := expectation.GenExpectationServicesKey(jobKey, rtype) |
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 see, it does have some places return err
before creating the services. Nice catch
} | ||
|
||
// Convert ReplicaType to lower string. | ||
expectationServicesKey := expectation.GenExpectationServicesKey(jobKey, rtype) |
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.
Github collapse some code snippets which make the review harder. :D
// Creation is expected when there is no error returned | ||
// We use `RaiseExpectations` here to accumulate expectations since `SetExpectations` has no such kind of ability | ||
expectationPodsKey := expectation.GenExpectationPodsKey(jobKey, rt) | ||
jc.Expectations.RaiseExpectations(expectationPodsKey, 1, 0) |
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.
expectationPodsKey
represents a group of pods. It does expect multiple creations.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Jeffwan 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 |
Seems @terrytangyuan and @gaocegege both approve the PR. /lgtm |
More appropriate use of expectation:
RaiseExpectations
in the code to accumulate expectations sinceSetExpectations
has no such kind of ability. reset expectation in the beginning ofReconcileJobs
;More detailed comments and explanations are presented with codes.