Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

fix(expectation): more appropriate use of expectation #139

Merged
merged 1 commit into from
Jul 8, 2021
Merged

fix(expectation): more appropriate use of expectation #139

merged 1 commit into from
Jul 8, 2021

Conversation

eggiter
Copy link
Contributor

@eggiter eggiter commented Jul 7, 2021

More appropriate use of expectation:

  1. use RaiseExpectations in the code to accumulate expectations since SetExpectations has no such kind of ability. reset expectation in the beginning of ReconcileJobs;
  2. expected creation in more appropriate place;
  3. add "expectDeletion";

More detailed comments and explanations are presented with codes.

@google-cla
Copy link

google-cla bot commented Jul 7, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@eggiter
Copy link
Contributor Author

eggiter commented Jul 7, 2021

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Jul 7, 2021

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@eggiter
Copy link
Contributor Author

eggiter commented Jul 7, 2021

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot I fixed it.

@eggiter
Copy link
Contributor Author

eggiter commented Jul 7, 2021

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign terrytangyuan after the PR has been reviewed.
You can assign the PR to them by writing /assign @terrytangyuan in a comment when ready.

The full list of commands accepted by this bot can be found 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

/assign @terrytangyuan @gaocegege

@eggiter eggiter changed the title fix(expectation): more appropriate use of expection fix(expectation): more appropriate use of expectation Jul 7, 2021
Copy link
Member

@terrytangyuan terrytangyuan left a 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)
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

Same question here.

Copy link
Contributor Author

@eggiter eggiter Jul 8, 2021

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).

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. SGTM.

Copy link
Member

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.

@@ -277,13 +279,6 @@ func (jc *JobController) CreateNewService(job metav1.Object, rtype apiv1.Replica
return err
}

// Convert ReplicaType to lower string.
expectationServicesKey := expectation.GenExpectationServicesKey(jobKey, rtype)
Copy link
Member

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

Copy link
Contributor Author

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).

Copy link
Member

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

Copy link
Member

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

@Jeffwan
Copy link
Member

Jeffwan commented Jul 7, 2021

@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

@eggiter
Copy link
Contributor Author

eggiter commented Jul 8, 2021

@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.
The problems i encountered are, current implementation of "expectation" is reconciling or is waiting expectations are satisfied when there is no need to. reconciling when it should wait creation or deletion is observed, waiting when there is an error encountered and no object is created.

Copy link
Member

@gaocegege gaocegege left a 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.

@@ -277,13 +279,6 @@ func (jc *JobController) CreateNewService(job metav1.Object, rtype apiv1.Replica
return err
}

// Convert ReplicaType to lower string.
expectationServicesKey := expectation.GenExpectationServicesKey(jobKey, rtype)
Copy link
Member

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

@@ -277,13 +279,6 @@ func (jc *JobController) CreateNewService(job metav1.Object, rtype apiv1.Replica
return err
}

// Convert ReplicaType to lower string.
expectationServicesKey := expectation.GenExpectationServicesKey(jobKey, rtype)
Copy link
Member

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)
Copy link
Member

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.

@google-oss-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Jeffwan
Copy link
Member

Jeffwan commented Jul 8, 2021

Seems @terrytangyuan and @gaocegege both approve the PR.

/lgtm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants