Fix poll jittering in Object controller #274
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR fixes Object controller which sometimes returns a negative poll interval if the reconciled Object instance is not ready, which is then ignored by controller-runtime internals.
In my case this has been observed in a situation in which the k8s object from
spec.forProvider.manifest
takes a while to get ready, but under 10m which is the defaultpollInterval
.The logic which calculates the pollInterval does not take into account that the base
pollInterval
has been updated to 30 seconds if the reconciled resource is not ready. It took the base value ofpollJitter
which is 1 minute, and calculated next poll interval using this formula:I guess that most users run provider-kubernetes without adjusting default poll interval, so if my math is right if
rand.Float64
returns anything less then0.25
(its documentations states: "// Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0)"), the returned value is less then 0. 25% chance to run into this bug. And if I understand the c-r source code right, it ignores negative RequeueAfter.The solution is to recalculate the pollInterval taking into account the
pollJitterPercentage
- this means that with default value of poll jitter precentage the poll interval would be in half-open interval [27.0, 33.0) (seconds).I have:
make reviewable test
to ensure this PR is ready for review.How has this code been tested