Skip to content

Commit 483eb07

Browse files
committed
feat: add support for pre-created Kubernetes secrets in Helm chart
Allow users to install the chart with externally managed secrets via customSecretName and customSecretKey values. This enables integration with secret management tools like External Secrets Operator, Sealed Secrets, and Vault. - Add customSecretName and customSecretKey chart values - Make secret creation conditional based on customSecretName - Add helper functions for secret resolution - Update deployment to use configurable secret references - Add documentation and usage examples Also removes deprecated engine: gotpl field from Chart.yaml for Helm v3 compliance. Bump chart version to 1.18.0 (minor version for new feature).
1 parent fba0381 commit 483eb07

File tree

7 files changed

+100
-7
lines changed

7 files changed

+100
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Enhancements
11+
- Add support for using pre-created Kubernetes secrets in the Helm chart via `customSecretName` and `customSecretKey` values
12+
13+
### Fixes
14+
- Remove deprecated `engine: gotpl` field from Chart.yaml for Helm v3 compliance
15+
1016
## v0.19.6 - 2026-01-12
1117

1218
### dependency

charts/newrelic-k8s-metrics-adapter/Chart.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
apiVersion: v2
22
description: A Helm chart to deploy the New Relic Kubernetes Metrics Adapter.
33
name: newrelic-k8s-metrics-adapter
4-
version: 1.17.6
4+
version: 1.18.0
55
appVersion: 0.19.6
66
home: https://hub.docker.com/r/newrelic/newrelic-k8s-metrics-adapter
77
sources:
88
- https://github.com/newrelic/newrelic-k8s-metrics-adapter
99
- https://github.com/newrelic/newrelic-k8s-metrics-adapter/tree/main/charts/newrelic-k8s-metrics-adapter
10-
engine: gotpl
1110
icon: https://newrelic.com/assets/newrelic/source/NewRelic-logo-square.svg
1211
dependencies:
1312
- name: common-library

charts/newrelic-k8s-metrics-adapter/README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ A Helm chart to deploy the New Relic Kubernetes Metrics Adapter.
3232
| config.nrdbClientTimeoutSeconds | int | 30 | Defines the NRDB client timeout. The maximum allowed value is 120. |
3333
| config.region | string | Automatically detected from `licenseKey`. | New Relic account region. If not set, it will be automatically derived from the License Key. |
3434
| containerSecurityContext | string | `nil` | Configure containerSecurityContext |
35+
| customSecretKey | string | `personalAPIKey` | The key in the `customSecretName` secret that contains the New Relic Personal API Key. Only used when `customSecretName` is set. |
36+
| customSecretName | string | `""` | Name of a pre-created secret containing the New Relic Personal API Key. When set, the chart will not create a secret and will use this one instead. The secret must exist in the same namespace and contain the key specified by `customSecretKey`. When set, the `personalAPIKey` value is ignored. |
3537
| extraEnv | list | `[]` | Array to add extra environment variables |
3638
| extraEnvFrom | list | `[]` | Array to add extra envFrom |
3739
| extraVolumeMounts | list | `[]` | Add extra volume mounts |
@@ -40,7 +42,7 @@ A Helm chart to deploy the New Relic Kubernetes Metrics Adapter.
4042
| image | object | See `values.yaml`. | Registry, repository, tag, and pull policy for the container image. |
4143
| image.pullSecrets | list | `[]` | The image pull secrets. |
4244
| nodeSelector | object | `{}` | Node label to use for scheduling. |
43-
| personalAPIKey | string | `nil` | New Relic [Personal API Key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#user-api-key) (stored in a secret). Used to connect to NerdGraph in order to fetch the configured metrics. (**Required**) |
45+
| personalAPIKey | string | `nil` | New Relic [Personal API Key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#user-api-key) (stored in a secret). Used to connect to NerdGraph in order to fetch the configured metrics. (**Required when `customSecretName` is not set**) |
4446
| podAnnotations | string | `nil` | Additional annotations to apply to the pod(s). |
4547
| podSecurityContext | string | `nil` | Configure podSecurityContext |
4648
| proxy | string | `nil` | Configure proxy for the metrics-adapter. |
@@ -74,6 +76,43 @@ Then, to install this chart, run the following command:
7476
helm upgrade --install [release-name] newrelic-k8s-metrics-adapter/newrelic-k8s-metrics-adapter --values [values file path]
7577
```
7678

79+
### Using a Pre-Created Secret
80+
81+
Instead of providing the API key directly in the values file, you can use a pre-created Kubernetes Secret. This is useful when using secret management tools like:
82+
83+
- [External Secrets Operator](https://external-secrets.io/)
84+
- [Sealed Secrets](https://github.com/bitnami-labs/sealed-secrets)
85+
- [Vault](https://www.vaultproject.io/)
86+
- Manual secret creation
87+
88+
To use a pre-created secret, first create it in your Kubernetes cluster:
89+
90+
```sh
91+
kubectl create secret generic newrelic-api-key \
92+
--from-literal=personalAPIKey=<your-api-key> \
93+
--namespace=<your-namespace>
94+
```
95+
96+
Then, configure the chart to use this secret by setting `customSecretName`:
97+
98+
```yaml
99+
customSecretName: newrelic-api-key
100+
customSecretKey: personalAPIKey
101+
config:
102+
accountID: <Account ID>
103+
externalMetrics:
104+
nginx_average_requests:
105+
query: "FROM Metric SELECT average(nginx.server.net.requestsPerSecond) SINCE 2 MINUTES AGO"
106+
```
107+
108+
And install the chart:
109+
110+
```sh
111+
helm upgrade --install [release-name] newrelic-k8s-metrics-adapter/newrelic-k8s-metrics-adapter --values [values file path]
112+
```
113+
114+
**Note:** When using `customSecretName`, you must ensure the secret exists in the target namespace before installing the Helm chart.
115+
77116
Once deployed the metric `nginx_average_requests` will be available to use by any HPA. This is and example of an HPA yaml using this metric:
78117

79118
```yaml

charts/newrelic-k8s-metrics-adapter/templates/_helpers.tpl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,36 @@ Naming helpers
5555
{{- define "newrelic-k8s-metrics-adapter.name.hpa-controller" -}}
5656
{{ include "newrelic.common.naming.truncateToDNSWithSuffix" (dict "name" (include "newrelic.common.naming.fullname" .) "suffix" "hpa-controller") }}
5757
{{- end -}}
58+
59+
{{/*
60+
Determine the secret name to use - either custom or generated
61+
*/}}
62+
{{- define "newrelic-k8s-metrics-adapter.secretName" -}}
63+
{{- if .Values.customSecretName -}}
64+
{{- .Values.customSecretName -}}
65+
{{- else -}}
66+
{{- include "newrelic.common.naming.fullname" . -}}
67+
{{- end -}}
68+
{{- end -}}
69+
70+
{{/*
71+
Determine the secret key to use - custom or default
72+
*/}}
73+
{{- define "newrelic-k8s-metrics-adapter.secretKey" -}}
74+
{{- if .Values.customSecretKey -}}
75+
{{- .Values.customSecretKey -}}
76+
{{- else -}}
77+
{{- "personalAPIKey" -}}
78+
{{- end -}}
79+
{{- end -}}
80+
81+
{{/*
82+
Determine whether to create the secret - false if customSecretName is set
83+
*/}}
84+
{{- define "newrelic-k8s-metrics-adapter.createSecret" -}}
85+
{{- if .Values.customSecretName -}}
86+
{{- false -}}
87+
{{- else -}}
88+
{{- true -}}
89+
{{- end -}}
90+
{{- end -}}

charts/newrelic-k8s-metrics-adapter/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ spec:
6262
- name: NEWRELIC_API_KEY
6363
valueFrom:
6464
secretKeyRef:
65-
name: {{ include "newrelic.common.naming.fullname" . }}
66-
key: personalAPIKey
65+
name: {{ include "newrelic-k8s-metrics-adapter.secretName" . }}
66+
key: {{ include "newrelic-k8s-metrics-adapter.secretKey" . }}
6767
{{- with (include "newrelic.common.proxy" .) }}
6868
- name: HTTPS_PROXY
6969
value: {{ . }}

charts/newrelic-k8s-metrics-adapter/templates/secret.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{{- if not .Values.customSecretName }}
2+
{{- if not .Values.personalAPIKey }}
3+
{{ fail "personalAPIKey must be set when customSecretName is not provided" }}
4+
{{- end }}
15
apiVersion: v1
26
kind: Secret
37
metadata:
@@ -7,4 +11,5 @@ metadata:
711
{{- include "newrelic.common.labels" . | nindent 4 }}
812
type: Opaque
913
stringData:
10-
personalAPIKey: {{ .Values.personalAPIKey | required "personalAPIKey must be set" | quote }}
14+
personalAPIKey: {{ .Values.personalAPIKey | quote }}
15+
{{- end }}

charts/newrelic-k8s-metrics-adapter/values.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@
1111
# cluster:
1212
# nrStaging:
1313

14-
# -- New Relic [Personal API Key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#user-api-key) (stored in a secret). Used to connect to NerdGraph in order to fetch the configured metrics. (**Required**)
14+
# -- New Relic [Personal API Key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#user-api-key) (stored in a secret). Used to connect to NerdGraph in order to fetch the configured metrics. (**Required when `customSecretName` is not set**)
1515
personalAPIKey:
1616

17+
# -- Name of a pre-created secret containing the New Relic Personal API Key. When set, the chart will not create a secret and will use this one instead.
18+
# The secret must exist in the same namespace and contain the key specified by `customSecretKey`.
19+
# When set, the `personalAPIKey` value is ignored.
20+
# @default -- `""`
21+
customSecretName: ""
22+
23+
# -- The key in the `customSecretName` secret that contains the New Relic Personal API Key.
24+
# Only used when `customSecretName` is set.
25+
# @default -- `personalAPIKey`
26+
customSecretKey: personalAPIKey
27+
1728
# -- Enable metrics adapter verbose logs.
1829
verboseLog: false
1930

0 commit comments

Comments
 (0)