Skip to content

Commit e88bb9a

Browse files
FR: Make list of namespaces used by the namespace selector configurable (#600)
* webhook scope * FR: make ignore namespaces configurable * chore: adjust ignoreNamespace selection, add tests, update changelog --------- Co-authored-by: Kayla Ondracek <112117836+kondracek-nr@users.noreply.github.com> Co-authored-by: Kayla Ondracek <kondracek@newrelic.com>
1 parent 5366d5d commit e88bb9a

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

CHANGELOG.md

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

88
## Unreleased
99

10+
### enhancement
11+
- Add default ignoredNamespace and make configurable @dpacheconr [#600](https://github.com/newrelic/k8s-metadata-injection/pull/600/)
12+
1013
## v1.36.0 - 2025-08-25
1114

1215
### 🚀 Enhancements

charts/nri-metadata-injection/ci/test-values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ ports:
1010
service:
1111
port: 443
1212
targetPort: ""
13+
14+
ignoreNamespaces: ['kube-public', 'kube-node-lease', 'kube-system']

charts/nri-metadata-injection/templates/admission-webhooks/mutatingWebhookConfiguration.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ webhooks:
2424
apiGroups: [""]
2525
apiVersions: ["v1"]
2626
resources: ["pods"]
27-
{{- if .Values.injectOnlyLabeledNamespaces }}
27+
{{- if or .Values.ignoreNamespaces .Values.injectOnlyLabeledNamespaces }}
2828
scope: Namespaced
2929
namespaceSelector:
30+
{{- if .Values.ignoreNamespaces }}
31+
matchExpressions:
32+
- key: kubernetes.io/metadata.name
33+
operator: NotIn
34+
values: {{ .Values.ignoreNamespaces | toJson }}
35+
{{- end }}
36+
{{- if .Values.injectOnlyLabeledNamespaces }}
3037
matchLabels:
3138
newrelic-metadata-injection: enabled
39+
{{- end }}
3240
{{- end }}
3341
failurePolicy: Ignore
3442
timeoutSeconds: {{ .Values.timeoutSeconds }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
suite: test mutatingwebhookconfiguraton values
2+
templates:
3+
- templates/admission-webhooks/mutatingWebhookConfiguration.yaml
4+
release:
5+
name: release
6+
namespace: ns
7+
tests:
8+
- it: default ignored namespaces are set
9+
set:
10+
cluster: my-cluster
11+
asserts:
12+
- equal:
13+
path: webhooks[0].namespaceSelector.matchExpressions[0].values
14+
value: ['kube-public', 'kube-node-lease', 'kube-system']
15+
- it: custom ignored namespaces are set
16+
set:
17+
cluster: my-cluster
18+
ignoreNamespaces: ['custom-namespace1', 'custom-namespace2']
19+
asserts:
20+
- equal:
21+
path: webhooks[0].namespaceSelector.matchExpressions[0].values
22+
value: [ 'custom-namespace1', 'custom-namespace2' ]
23+
- it: empty ignoreNamespaces results in no namespaceSelector
24+
set:
25+
cluster: my-cluster
26+
ignoreNamespaces: []
27+
asserts:
28+
- notExists:
29+
path: webhooks[0].namespaceSelector
30+
- it: injectOnlyLabeledNamespaces=true results in namespaceSelector with matchLabels
31+
set:
32+
cluster: my-cluster
33+
injectOnlyLabeledNamespaces: true
34+
asserts:
35+
- equal:
36+
path: webhooks[0].namespaceSelector.matchLabels
37+
value:
38+
newrelic-metadata-injection: enabled
39+
- equal:
40+
path: webhooks[0].namespaceSelector.matchExpressions[0].values
41+
value: [ 'kube-public', 'kube-node-lease', 'kube-system' ]

charts/nri-metadata-injection/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ tolerations: []
9292
# with 'newrelic-metadata-injection=enabled'.
9393
injectOnlyLabeledNamespaces: false
9494

95+
# -- This is a list of namespaces that will be ignored by the webhook.
96+
ignoreNamespaces: ['kube-public', 'kube-node-lease', 'kube-system']
97+
9598
# -- Use custom tls certificates for the webhook, or let the chart handle it
9699
# automatically.
97100
# Ref: https://docs.newrelic.com/docs/integrations/kubernetes-integration/link-your-applications/link-your-applications-kubernetes#configure-injection

0 commit comments

Comments
 (0)