Scope Deployment cache to worker deployments#331
Open
Shivs11 wants to merge 3 commits into
Open
Conversation
Shivs11
commented
May 22, 2026
Member
Author
There was a problem hiding this comment.
just made a new file here only because the main changes were also in the "main" file
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This scopes the controller-runtime cache for
apps/v1.Deploymentobjects to only Deployments labeled withtemporal.io/deployment-name.Why
We investigated a report where one controller manager pod was using several GiB of memory while CPU was almost idle. The cluster only had one
TemporalWorkerDeployment, but it had thousands of normal KubernetesDeploymentobjects for unrelated services.The confusing part is how
Owns(&appsv1.Deployment{})behaves in controller-runtime.A useful way to think about this is that there are two separate layers:
Deploymentwatcher/cache. This layer asks the API server for Deployment objects, watches for Deployment changes, and keeps the watched objects in memory.Owns(&appsv1.Deployment{})belongs to this second layer: it makes sure only Deployments owned by aTemporalWorkerDeploymenttrigger reconciles for that owner.Before this PR, layer 2 was already narrow, but layer 1 was still broad. So the controller was only reconciling its own Deployments, but the underlying Deployment watcher/cache could still list, watch, and retain unrelated Deployments from the cluster.
That means memory could grow with all Kubernetes Deployments in the cluster, not just Temporal-managed worker Deployments.
This PR narrows the first layer too. The manager cache now only admits Deployments that have the existing
temporal.io/deployment-namelabel, which is the label we already put on worker Deployments generated by this controller.Changes
temporal.io/deployment-namelabel constant ask8s.WorkerDeploymentNameLabel.cache.Options.ByObjectforappsv1.Deploymentwith an existence selector ontemporal.io/deployment-name.Notes
This does not introduce a new Kubernetes label. Generated worker Deployments already had
temporal.io/deployment-name; this change reuses that label to scope the Deployment watcher/cache.Residual risk: a pre-existing or manually modified controller-owned Deployment missing
temporal.io/deployment-namewill no longer be visible to the cached Deployment reader/watch. Normal upgrade risk should be low because the controller-generated Deployments already used this label before the PR.Testing
go test ./cmdgo test ./internal/k8sgo test ./...git diff --check