remove unnecessary patch requests when PodReadinessGate is enabled. #3373
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
This CR improves performance when a optional feature called PodReadinessGate is enabled by removing unnecessary patch requests to APIServer.
The workflow of PodReadinessGate ideally works as below:
target-health.elbv2.k8s.aws/k8s-echoserv-echoserv-3b3889c42c
), if a pod will be used as backend for a TargetGroup.{"type": "target-health.elbv2.k8s.aws/k8s-echoserv-echoserv-3b3889c42c", "status": "False", "reason": "Elb.RegistrationInProgress", "message": "Target registration is in progress"}
{"type": "target-health.elbv2.k8s.aws/k8s-echoserv-echoserv-3b3889c42c", "status": "True"}
This bug is for the 3rd step above, the patch were generated to be
{"type": "target-health.elbv2.k8s.aws/k8s-echoserv-echoserv-3b3889c42c", "status": "True"}
, where "reason" & "message" is omitted from patch, thus APIServer will patch the object to be{"type": "target-health.elbv2.k8s.aws/k8s-echoserv-echoserv-3b3889c42c", "status": "True", "reason": "Elb.RegistrationInProgress", "message": "Target registration is in progress"}
.Later, if there is a reconcile for the same service triggered again, our logic decides that "reason" and "message" is still not "empty", and will try to patch existing pods again. This bug didn't impact functionality since ReadinessGate only checks a condition's status and ignores "reason" and "message", but it might causes performance issues due to these extra unnecessary Pod patch requests.
This PR modify the patch generation to correct generate the patch to be
{"type": "target-health.elbv2.k8s.aws/k8s-echoserv-echoserv-3b3889c42c", "status": "True", "reason": null, "message": null}
TODO: we can further optimize this performance by move pod status updates into a dedicated work queue to prevent it block the main reconcile threads.
Checklist
README.md
, or thedocs
directory)BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯