Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors Kubernetes annotation/ownership metadata aggregation out of the controller into a dedicated internal/metadata package, and adds unit tests around extraction and aggregation behavior.
Changes:
- Introduces
internal/metadata.Aggregatorto traverse pod owner references and collect runtime risks + custom tags. - Adds focused tests for metadata extraction rules (limits, validation) and ownership traversal (chain, cycles, missing owners, fetch errors).
- Updates the controller and
cmd/deployment-trackerwiring to use the new aggregator instead of directly using the metadata client.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/metadata/metadata.go | New metadata aggregation implementation (BFS traversal, extraction of runtime risks and tags). |
| internal/metadata/metadata_test.go | New unit tests covering extraction rules and owner-chain aggregation behavior. |
| internal/controller/controller.go | Removes inline metadata aggregation and injects a metadata aggregator dependency. |
| cmd/deployment-tracker/main.go | Instantiates the Kubernetes metadata client + new aggregator and passes it to the controller. |
Comments suppressed due to low confidence (2)
internal/controller/controller.go:72
controller.Newnow accepts apodMetadataAggregator, but the constructor doesn't validate it is non-nil. If a nil is passed,processEventwill panic when callingc.metadataAggregator.AggregatePodMetadata. Consider returning an error fromNewwhenmetadataAggregatoris nil (fail fast) to avoid a runtime nil dereference.
// New creates a new deployment tracker controller.
func New(clientset kubernetes.Interface, metadataAggregator podMetadataAggregator, namespace string, excludeNamespaces string, cfg *Config) (*Controller, error) {
// Create informer factory
factory := createInformerFactory(clientset, namespace, excludeNamespaces)
podInformer := factory.Core().V1().Pods().Informer()
internal/metadata/metadata.go:200
- This debug log for duplicate tags includes both
existing_valueandnew_value. For the same reason as above (annotation values may be sensitive), consider omitting raw values from logs and logging only the tag key (and possibly lengths).
if _, exists := aggPodMetadata.Tags[tagKey]; exists {
slog.Debug("Duplicate tag key found, skipping",
"object_name", obj.GetName(),
"kind", obj.Kind,
"tag_key", tagKey,
"existing_value", aggPodMetadata.Tags[tagKey],
"new_value", tagValue,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ajbeattie
previously approved these changes
Feb 20, 2026
ajbeattie
left a comment
There was a problem hiding this comment.
Very nice 💯. One small request if you're amenable to it!
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.
Refactored metadata logic to its own metadata package and added testing