refactor: split controller.go into focused files by concern#69
Open
refactor: split controller.go into focused files by concern#69
Conversation
Split the 682-line controller.go into four files organized by responsibility: - controller.go (~160 lines): types, interfaces, Controller struct, New(), Run() - handlers.go (~170 lines): event handler registration, worker loop - reconcile.go (~270 lines): event processing, deployment recording, caching - pod.go (~130 lines): pod utility functions, informer factory Extract registerEventHandlers() from New() as a Controller method and newAPIClient() as a package-level helper to simplify the constructor. No behavioral changes — pure structural refactoring. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Kubernetes deployment-tracker controller by splitting the previous monolithic internal/controller/controller.go into smaller files organized by responsibility, aiming to keep behavior unchanged while improving readability and maintainability.
Changes:
- Extracted event handler registration and worker lifecycle logic into
handlers.go. - Extracted reconciliation / posting logic into
reconcile.go. - Extracted pod/informer helper utilities into
pod.goand simplifiedcontroller.goto core wiring (New,Run, API client construction).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/controller/controller.go | Slimmed down to core types + constructor + API client creation + Run(), delegating handlers/workers elsewhere. |
| internal/controller/handlers.go | New file containing informer event handlers and queue worker processing logic. |
| internal/controller/reconcile.go | New file containing processEvent/recordContainer and caching logic for posts. |
| internal/controller/pod.go | New file containing informer factory creation + pod/container helper functions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
…tone support (#70) * Initial plan * fix: use DeletionHandlingMetaNamespaceKeyFunc in DeleteFunc for tombstone support Co-authored-by: bdehamer <398027+bdehamer@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/deployment-tracker/sessions/620a8570-c815-4b5f-95cd-25d107fcd82a --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bdehamer <398027+bdehamer@users.noreply.github.com>
bdehamer
commented
Mar 24, 2026
| return | ||
| } | ||
|
|
||
| key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj) |
Contributor
Author
There was a problem hiding this comment.
This was a nice bug fix picked-up by Copilot during this refactor. Even if we decide not to merge this PR, we should apply this change (using DeletionHandlingMetaNamespaceKeyFunc in place of MetaNamespaceKeyFunc)
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
Splits the 682-line
internal/controller/controller.gointo four focused files organized by responsibility. No behavioral changes — pure structural refactoring.New file layout
controller.goControllerstruct,New(),newAPIClient(),Run()handlers.goregisterEventHandlers(),runWorker(),processNextItem(),startWorkers()reconcile.goprocessEvent(),recordContainer(),deploymentExists(),getCacheKey()pod.gocreateInformerFactory(),getARDeploymentName(),getContainerDigest(),getDeploymentName(),podToPartialMetadata()config.goKey changes
registerEventHandlers()extracted fromNew()as aControllermethod — the event handler closures now usec.workqueueinstead of closing over a localqueuevariable.newAPIClient()extracted as a package-level helper to isolate API client construction from the controller constructor.startWorkers()extracted fromRun()for clarity.Testing
All existing unit and integration tests pass without modification. No test changes needed since all files remain in the same package.