-
Notifications
You must be signed in to change notification settings - Fork 40.8k
Job controller optimization: reduce work duration time & minimize cache locking #132305
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
Merged
+33
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
How the orphan pods get populated in the index, can you provide some reference?
Uh oh!
There was an error while loading. Please reload this page.
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.
Orphan pods are automatically indexed through the
AddPodControllerUIDIndexer
function inpkg/controller/controller_utils.go:1092-1105
.When a pod has no ControllerRef, it gets indexed under OrphanPodIndexKey instead of a specific controller UID.
This allows controllers to discover and potentially adopt pods that match their selectors but temporarily lack owner references.
Reference:
Similar pattern used by StatefulSet, ReplicaSet, and DaemonSet controllers.
Uh oh!
There was an error while loading. Please reload this page.
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.
Interesting, thank you for explaining.
Does it mean that we now list orphaned Pods from all namespaces?
If so, then it seems this may actually hurt performance of some environments with many namespaces and orphaned Pods (for example when Pods are managed by external systems directly), as before we would only list Pods from a single namespace.
@hakuna-matatah @xigang Is such a situation covered by the benchmarks, or is it not a concern for us?
Maybe as a mitigation we could filter early the Pods by the namespace as we iterate over them anyway, wdyt @soltysh @wojtek-t @atiratree ? If we change the semantics of the function to return also Pods from other namespaces, then we need to assume that the downstream code can cope with it. I'm not sure how well tested such scenarios are, so extra filtering by namespace seems useful anyway to maintain semantics.
Or maybe, even better there could be different keys for orphans in the indexer depending on namespace?
As a follow up I argue we should commonize the functions (probably in
pkg/controller/controller_utils.go
), as this seems a non-trivial code duplication.Uh oh!
There was an error while loading. Please reload this page.
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.
To distinguish orphan Pods based on namespace, the index can be built like this:
However, this approach requires changes to the code of other controllers, such as ReplicaSet and DaemonSet.
Before:
After:
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, to have a peace of mind that we are not worsening the scenario I would suggest to go this way, and commonized the function in controller_utils, but let's see what others say.
I'm ok to merge the PR as is if we follow up, but keep it open yet for visibility.
I'm also ok to turn this PR to also adjust the previous controllers and expose the utility function in controllers_utils
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.
Let’s wait and see what others suggest first.
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 not super worried about too many orphaned pods, but I also like the change to the indexing suggested above. Given it's purely in-memory indexing we can change that at any point in time.
So let's follow-up on changing the value to also include the namespace - I would suggest merging the PR as is, and then switching all controllers to the new index in one shot.
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.
Okay, I can take care of the follow-up work on the new index.
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.
sgtm. I would also like the following up to ensure that there is no risk for the downstream code to now deal with pods coming from other namespaces. the code may or may not be ready for 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.
+1, sounds like a nice improvement for all the controllers.
A small suggestion; we could make a function for constructing the orphan key
controller.OrphanPodIndexKey + "/" + rs.Namespace