Skip to content

newrelic-k8s-metrics-adapter: Add Comprehensive Global Value Inheritance Test Coverage#448

Open
dpacheconr wants to merge 3 commits intonewrelic:mainfrom
dpacheconr:test/comprehensive-global-inheritance-validation
Open

newrelic-k8s-metrics-adapter: Add Comprehensive Global Value Inheritance Test Coverage#448
dpacheconr wants to merge 3 commits intonewrelic:mainfrom
dpacheconr:test/comprehensive-global-inheritance-validation

Conversation

@dpacheconr
Copy link
Contributor

@dpacheconr dpacheconr commented Dec 2, 2025

Overview

This PR adds comprehensive test coverage validating global value inheritance for all applicable values from the nri-bundle global values contract and fixes a bug where `global.verboseLog` was not being inherited. It also fixes a bug in the `createSecret` helper introduced in main where the string `"false"` was returned for the falsy case — in Go templates, any non-empty string is truthy, so the secret creation guard never worked correctly when `customSecretName` was set.

Changes

Bug Fixes

  • Fixed `templates/_helpers.tpl` `createSecret` helper: returned string `"false"` is truthy in Go templates; fixed to return empty string for the falsy case so `customSecretName` correctly suppresses secret creation
  • Fixed `templates/deployment.yaml` to use `newrelic.common.verboseLog` helper for proper `global.verboseLog` inheritance
  • Changed `values.yaml` `verboseLog` default from `false` to null to enable global inheritance (Local > Global > Default)

Added Test Suite

New File: `tests/global-inheritance_test.yaml`

  • 36 tests covering all applicable global values with explicit inheritance and precedence validation
  • YAML anchors (`&base`/`<<: *base`) used across tests for shared base values
  • Asserts actual `personalAPIKey` value in secret (`stringData.personalAPIKey`), not just structure
  • Tests `customSecretName` suppresses secret creation (`hasDocuments: count: 0`)
  • Tests `verboseLog` via `--v=10`/`--v=1` args (global inheritance + local override)

Test Results

```
Charts: 1 passed, 1 total
Test Suites: 13 passed, 13 total
Tests: 69 passed, 69 total
Pass Rate: 100%
```

Global Values Coverage

All 27 global values from the nri-bundle global contract assessed:

Legend:

  • Applicable: Whether this global value applies to this chart type (Metrics Adapter Deployment)
  • Tested: Test coverage status
    • `Yes` - Explicit helm-unittest test coverage with dedicated test cases and assertions
    • `No` - Value not applicable to this chart type
Global Value Applicable Tested Notes
cluster Yes Yes `global-inheritance_test.yaml` - Required field, CLUSTER_NAME env var
licenseKey No No Uses personalAPIKey instead
customSecretName Yes Yes `global-inheritance_test.yaml` - Suppresses secret creation when set
customSecretLicenseKey No No Uses personalAPIKey/customSecretKey mechanism
insightsKey No No Deprecated value
provider No No Not used by metrics adapter
labels Yes Yes `global-inheritance_test.yaml` - Object labels
podLabels Yes Yes `global-inheritance_test.yaml` - Pod-specific label inheritance
images.registry Yes Yes `global-inheritance_test.yaml` - Container registry precedence
images.pullSecrets Yes Yes `global-inheritance_test.yaml` - Global + local merge behavior
images.pullPolicy Yes Yes `deployment_test.yaml` - Pull policy inheritance
serviceAccount.create Yes Yes `rbac_test.yaml` - Service account creation control
serviceAccount.name Yes Yes `global-inheritance_test.yaml` - Service account naming
serviceAccount.annotations No No Metrics adapter doesn't require IAM annotations
hostNetwork Yes Yes `global-inheritance_test.yaml` - Global + override + default false
dnsConfig Yes Yes `global-inheritance_test.yaml` - DNS configuration inheritance
proxy Yes Yes `global-inheritance_test.yaml` - HTTPS_PROXY env var precedence
priorityClassName Yes Yes `global-inheritance_test.yaml` - Pod priority class
nodeSelector Yes Yes `global-inheritance_test.yaml` - Includes default `kubernetes.io/os: linux`
tolerations Yes Yes `global-inheritance_test.yaml` - Global + override
affinity Yes Yes `global-inheritance_test.yaml` - Complete node affinity tested
podSecurityContext Yes Yes `global-inheritance_test.yaml` - Pod-level security context
containerSecurityContext Yes Yes `global-inheritance_test.yaml` - Container-level security context
privileged No No Not required for metrics adapter (Deployment)
customAttributes No No Not applicable to metrics adapter
lowDataMode No No Not applicable to metrics adapter
fargate No No Not applicable to metrics adapter
nrStaging Yes Yes `configmap_test.yaml` - Staging region configuration
verboseLog Yes Yes `global-inheritance_test.yaml` - `--v=10`/`--v=1` args (fixed in this PR)
fedramp.enabled No No Not applicable to metrics adapter
TOTAL 18/27 applicable 18/18 (100% coverage) All applicable global values fully tested

Files Modified

Template Files

  • `templates/_helpers.tpl` - Fixed `createSecret` helper to return empty string (not `"false"`) for falsy case
  • `templates/deployment.yaml` - Use `newrelic.common.verboseLog` helper for global inheritance

Configuration Files

  • `values.yaml` - Changed `verboseLog` default from `false` to null; added `customSecretName`/`customSecretKey` defaults

New Test Files

  • `tests/global-inheritance_test.yaml` - 36 tests for all 18 applicable global values (with YAML anchors)

Tests: 69/69 passing (100%)
Lint: Passing (helm lint)
Coverage: 18/18 applicable global values (100%)

@dpacheconr dpacheconr requested a review from a team as a code owner December 2, 2025 15:25
@mangulonr
Copy link
Contributor

Added to backlog

dpacheconr and others added 3 commits March 11, 2026 11:06
…heritance tests

- Added 30 new test cases validating global value inheritance
- Covers cluster, images, scheduling, security contexts, labels
- All 63 tests passing (33 existing + 30 new)
- Bumped chart version 1.13.6 → 1.13.7
- Updated CHANGELOG.md with test suite entry

Test coverage includes:
- Global value propagation when local values not set
- Local value override precedence
- Default behavior validation
- Chart-specific edge cases (kubernetes.io/os: linux default)

Known limitation documented: global.verboseLog not inherited
(chart doesn't use common-library helper)

All applicable global values tested with 100% pass rate.
- Changed deployment.yaml to use newrelic.common.verboseLog helper
- Changed values.yaml verboseLog default from false to null for global inheritance
- Added 4 comprehensive tests validating default, inheritance, and precedence
- All 67 tests passing (Local > Global > Default precedence verified)
…ecretName test, and fix createSecret helper

- Rebase onto main
- Fix createSecret helper: returned string "false" which is truthy in Go templates; now returns empty string for the falsy case
- Add YAML anchors (&base/<<: *base) to new test file
- Add test asserting actual personalAPIKey value in secret
- Add test verifying customSecretName suppresses secret creation
@dpacheconr
Copy link
Contributor Author

dpacheconr commented Mar 11, 2026

Rebased onto main. Fixed a bug in the createSecret helper (returned string "false" which is truthy in Go templates, fixed to return empty string). Added YAML anchors (&base/<<: *base) to the new test file, a test asserting the actual personalAPIKey value in the secret, and a test verifying customSecretName suppresses secret creation.

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.

2 participants