Skip to content

Add metadata package#42

Merged
piceri merged 3 commits intomainfrom
metadata-service
Feb 20, 2026
Merged

Add metadata package#42
piceri merged 3 commits intomainfrom
metadata-service

Conversation

@piceri
Copy link
Contributor

@piceri piceri commented Feb 20, 2026

Refactored metadata logic to its own metadata package and added testing

@piceri piceri marked this pull request as ready for review February 20, 2026 18:09
@piceri piceri requested a review from a team as a code owner February 20, 2026 18:09
Copilot AI review requested due to automatic review settings February 20, 2026 18:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Aggregator to 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-tracker wiring 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.New now accepts a podMetadataAggregator, but the constructor doesn't validate it is non-nil. If a nil is passed, processEvent will panic when calling c.metadataAggregator.AggregatePodMetadata. Consider returning an error from New when metadataAggregator is 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_value and new_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
ajbeattie previously approved these changes Feb 20, 2026
Copy link

@ajbeattie ajbeattie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice 💯. One small request if you're amenable to it!

Copy link

@ajbeattie ajbeattie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@piceri piceri merged commit 8d5b304 into main Feb 20, 2026
6 checks passed
@piceri piceri deleted the metadata-service branch February 20, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants