Add Deployment informer to replace direct API calls#68
Merged
Conversation
Signed-off-by: Brian DeHamer <bdehamer@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a Deployment informer so deploymentExists() can check a local informer cache rather than issuing synchronous Kubernetes API GET calls for each pod delete event, reducing API server load during Deployment deletions/scale-downs.
Changes:
- Add a Deployment informer + lister to the controller and switch
deploymentExists()to use the lister cache. - Update integration test setup to wait for both pod and deployment informer caches to sync.
- Expand RBAC for deployments to include
list/watch(manifests, Helm chart, and README table).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/controller/controller.go | Adds deployment informer/lister, starts & syncs both informers, and switches existence checks to the lister cache. |
| internal/controller/controller_integration_test.go | Waits for both pod and deployment informer caches to sync in test setup. |
| deploy/manifest.yaml | Updates deployments RBAC verbs to include list/watch. |
| deploy/charts/deployment-tracker/templates/clusterrole.yaml | Mirrors the RBAC update in the Helm chart ClusterRole. |
| README.md | Updates RBAC permissions table to include deployments list/watch (and replicasets get). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Brian DeHamer <bdehamer@github.com>
ajbeattie
approved these changes
Mar 23, 2026
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.
What
Adds a Deployment informer alongside the existing Pod informer so that
deploymentExists()checks a local in-memory cache instead of making a liveGETcall to the Kubernetes API server.Why
Every pod delete event triggers a
clientset.AppsV1().Deployments().Get()call to determine if the parent deployment still exists (to distinguish scale-downs from true decommissions). When a deployment with N pods is deleted, this results in N synchronous API server round-trips checking the same deployment.Changes
internal/controller/controller.go— AddeddeploymentInformeranddeploymentListerfields toController. The deployment informer is created from the sameSharedInformerFactoryused for the pod informer.deploymentExists()now reads from the lister cache (in-memory) instead of calling the API server.internal/controller/controller_integration_test.go— Updatedsetup()to wait for both informer caches to sync.deploy/manifest.yaml— Addedlistandwatchverbs to the deployments RBAC rule.deploy/charts/deployment-tracker/templates/clusterrole.yaml— Same RBAC update in the Helm chart.README.md— Updated the RBAC permissions table.Tradeoffs
geton deploymentsget,list,watchon deploymentsResolves https://github.com/github/package-security/issues/4179