Skip to content

Implement metadata injection inside operator#556

Open
ramkrishankumarN wants to merge 1 commit intomainfrom
ramk/operator-merge-with-metadata-injection
Open

Implement metadata injection inside operator#556
ramkrishankumarN wants to merge 1 commit intomainfrom
ramk/operator-merge-with-metadata-injection

Conversation

@ramkrishankumarN
Copy link
Copy Markdown
Contributor

Description

(https://newrelic.atlassian.net/wiki/spaces/KOT/pages/5428150500/Using+k8s+agent+operator+for+Metadata+Injection)
Problem Statement
New Relic currently maintains two separate Kubernetes operators:

k8s-metadata-injection: Injects Kubernetes metadata (cluster, node, namespace, pod, container names) as environment variables to enable APM-to-infrastructure correlation

k8s-agents-operator: Auto-instruments pods with New Relic APM agents via init containers

Maintaining two separate webhooks creates operational complexity, potential conflicts, and duplicated effort. Especially with trivy tickets and other update related to go packages.

This project consolidates both functionalities into the k8s-agents-operator, allowing customers to use a single operator for both metadata injection and agent instrumentation.

User Requirements
Opt-in model: Metadata injection disabled by default, explicitly enabled via environment variable

Environment variable configuration: Cluster name configured via K8S_CLUSTER_NAME environment variable

Complete replacement: k8s-metadata-injection repository will be deprecated after this implementation

Backward compatibility: Existing agent injection functionality must remain unchanged

Namespace filtering: Support ignore lists and label-based filtering

Independent operation: Metadata injection should work with or without agent injection

Metadata Environment Variables
The following 7 environment variables will be injected (matching k8s-metadata-injection):

NEW_RELIC_METADATA_KUBERNETES_CLUSTER_NAME (from config)
NEW_RELIC_METADATA_KUBERNETES_NODE_NAME (downward API: spec.nodeName)
NEW_RELIC_METADATA_KUBERNETES_NAMESPACE_NAME (downward API: metadata.namespace)
NEW_RELIC_METADATA_KUBERNETES_POD_NAME (downward API: metadata.name)
NEW_RELIC_METADATA_KUBERNETES_DEPLOYMENT_NAME (derived from generateName)
NEW_RELIC_METADATA_KUBERNETES_CONTAINER_NAME (static: container name)
NEW_RELIC_METADATA_KUBERNETES_CONTAINER_IMAGE_NAME (static: container image)
Architecture Approach
New PodMutator Implementation
Create a separate MetadataInjectionPodMutator that implements the existing PodMutator interface. This provides:

Clean separation of concerns (metadata vs agent injection)

Ability to enable/disable independently

Runs first in the mutator chain (before agent injection)

No CRD dependencies (configuration via environment variables only)

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • New feature / enhancement (non-breaking change which adds functionality)
  • Security fix
  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • Documentation has been updated
  • This change requires changes in testing:
    • unit tests
    • E2E tests

@ramkrishankumarN ramkrishankumarN requested a review from a team as a code owner April 9, 2026 20:29
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Thank you for opening this pull request. We require pull request titles to follow the Conventional Commits specification.

Your proposed title needs to be adjusted:

No release type found in pull request title "Implement metadata injection inside operator". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 12.72727% with 144 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.11%. Comparing base (5189aac) to head (8656cea).

Files with missing lines Patch % Lines
internal/metadata/mutator.go 0.00% 107 Missing ⚠️
internal/webhook/podmutationhandler.go 51.72% 11 Missing and 3 partials ⚠️
internal/metadata/config.go 33.33% 10 Missing and 2 partials ⚠️
cmd/main.go 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #556      +/-   ##
==========================================
- Coverage   68.74%   66.11%   -2.64%     
==========================================
  Files          53       55       +2     
  Lines        3513     3665     +152     
==========================================
+ Hits         2415     2423       +8     
- Misses        863     1002     +139     
- Partials      235      240       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant