Skip to content

Commit a1c5253

Browse files
committed
chore: allow overriding privilged for windows
1 parent 7011942 commit a1c5253

5 files changed

Lines changed: 91 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## Unreleased
99

1010
### enhancement
11-
- Introduce HostProcess Windows containers and "privileged" mode support to collect host metrics on Windows nodes. @kondracek-nr [#1361](https://github.com/newrelic/nri-kubernetes/pull/1361)
11+
- Introduce HostProcess Windows containers and "privileged" mode support to collect host metrics on Windows nodes. Inherits global or chart-specific "privileged" setting by default, but also allows users to override this for their Windows nodes - see values.yaml. @kondracek-nr [#1361](https://github.com/newrelic/nri-kubernetes/pull/1361)
1212

1313
## v3.51.1 - 2025-12-15
1414

charts/newrelic-infrastructure/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ readOnlyRootFilesystem: true
132132
{{- end -}}
133133
{{- end -}}
134134

135+
{{/*
136+
Windows-specific privileged mode check.
137+
Returns the privileged mode for Windows nodes, checking windows.privileged first,
138+
then falling back to the global privileged setting.
139+
Outputs "true" when privileged, outputs nothing (empty string) when unprivileged.
140+
*/}}
141+
{{- define "nriKubernetes.windows.privileged" -}}
142+
{{- if kindIs "bool" .Values.windows.privileged -}}
143+
{{- if .Values.windows.privileged -}}
144+
{{- .Values.windows.privileged -}}
145+
{{- end -}}
146+
{{- else -}}
147+
{{- include "nriKubernetes.privileged" . -}}
148+
{{- end -}}
149+
{{- end -}}
150+
135151
{{- /* Windows image string processing */ -}}
136152
{{- /* Windows Agent is more complicated because of how we've set up agent build automation. */ -}}
137153
{{- /* This may be simplified once infrastructure-bundle accommodates Windows. */ -}}

charts/newrelic-infrastructure/templates/kubelet/daemonset-windows.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
namespace: {{ $.Release.Namespace }}
77
labels:
88
kubernetes.io/os: windows
9-
{{- if include "nriKubernetes.privileged" $ }}
9+
{{- if include "nriKubernetes.windows.privileged" $ }}
1010
mode: privileged
1111
{{- else }}
1212
mode: unprivileged
@@ -39,7 +39,7 @@ spec:
3939
{{- end }}
4040
labels:
4141
app.kubernetes.io/component: kubelet
42-
{{- if include "nriKubernetes.privileged" $ }}
42+
{{- if include "nriKubernetes.windows.privileged" $ }}
4343
mode: privileged
4444
{{- else }}
4545
mode: unprivileged
@@ -61,7 +61,7 @@ spec:
6161
priorityClassName: {{ . }}
6262
{{- end }}
6363
serviceAccountName: {{ include "newrelic.common.serviceAccount.name" $ }}
64-
{{- if include "nriKubernetes.privileged" $ }}
64+
{{- if include "nriKubernetes.windows.privileged" $ }}
6565
hostNetwork: true
6666
{{- end }}
6767

@@ -76,15 +76,15 @@ spec:
7676
image: {{ default (include "nriKubernetes.windowsIntegrationImage" $) .integrationImage }}
7777
{{- end }}
7878
imagePullPolicy: {{ $.Values.images.windowsIntegration.pullPolicy }}
79-
{{- if include "nriKubernetes.privileged" $ }}
79+
{{- if include "nriKubernetes.windows.privileged" $ }}
8080
command:
8181
- "powershell.exe"
8282
- "-Command"
8383
- "& $env:CONTAINER_SANDBOX_MOUNT_POINT\\app\\nri-kubernetes.exe"
8484
{{- end }}
8585
securityContext:
8686
windowsOptions:
87-
{{- if include "nriKubernetes.privileged" $ }}
87+
{{- if include "nriKubernetes.windows.privileged" $ }}
8888
hostProcess: true
8989
runAsUserName: "NT AUTHORITY\\Local service"
9090
{{- else }}
@@ -134,15 +134,15 @@ spec:
134134
image: {{ default (include "nriKubernetes.windowsAgentImage" $) .integrationImage }}
135135
{{- end }}
136136
imagePullPolicy: {{ $.Values.images.windowsAgent.pullPolicy }}
137-
{{- if include "nriKubernetes.privileged" $ }}
137+
{{- if include "nriKubernetes.windows.privileged" $ }}
138138
command:
139139
- "powershell.exe"
140140
- "-Command"
141141
- "$env:CONTAINER_SANDBOX_MOUNT_POINT\\start.ps1"
142142
{{- end }}
143143
securityContext:
144144
windowsOptions:
145-
{{- if include "nriKubernetes.privileged" $ }}
145+
{{- if include "nriKubernetes.windows.privileged" $ }}
146146
hostProcess: true
147147
runAsUserName: "NT AUTHORITY\\SYSTEM"
148148
{{- else }}
@@ -173,7 +173,7 @@ spec:
173173
# Override NRIA_OVERRIDE_HOST_ROOT to empty if unprivileged. This must be done as an env var as the
174174
# `k8s-events-forwarder` and `infrastructure-bundle` images ship this very same env var set to /host.
175175
# Windows runs in unprivileged mode when privileged is set to false.
176-
{{- if not (include "nriKubernetes.privileged" $) }}
176+
{{- if not (include "nriKubernetes.windows.privileged" $) }}
177177
- name: "NRIA_OVERRIDE_HOST_ROOT"
178178
value: ""
179179
{{- end }}
@@ -203,7 +203,7 @@ spec:
203203
value: "CLUSTER_NAME"
204204

205205
{{- /* Needed for autodiscovery when hostNetwork=false (unprivileged mode) */}}
206-
{{- if not (include "nriKubernetes.privileged" $) }}
206+
{{- if not (include "nriKubernetes.windows.privileged" $) }}
207207
- name: "NRIA_HOST"
208208
valueFrom:
209209
fieldRef:

charts/newrelic-infrastructure/tests/windows_hostprocess_test.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,62 @@ tests:
265265
fieldPath: "status.hostIP"
266266
template: templates/kubelet/daemonset-windows.yaml
267267

268+
# Windows-specific privileged override tests
269+
- it: should respect windows.privileged=false override when global privileged=true
270+
set:
271+
licenseKey: test
272+
cluster: test
273+
kubelet.enabled: true
274+
enableWindows: true
275+
privileged: true
276+
windows:
277+
privileged: false
278+
documentIndex: 0
279+
asserts:
280+
- equal:
281+
path: spec.template.spec.containers[0].securityContext.windowsOptions.hostProcess
282+
value: false
283+
template: templates/kubelet/daemonset-windows.yaml
284+
- equal:
285+
path: spec.template.spec.containers[1].securityContext.windowsOptions.hostProcess
286+
value: false
287+
template: templates/kubelet/daemonset-windows.yaml
288+
- isNull:
289+
path: spec.template.spec.hostNetwork
290+
template: templates/kubelet/daemonset-windows.yaml
291+
- equal:
292+
path: metadata.labels.mode
293+
value: unprivileged
294+
template: templates/kubelet/daemonset-windows.yaml
295+
296+
- it: should respect windows.privileged=true override when global privileged=false
297+
set:
298+
licenseKey: test
299+
cluster: test
300+
kubelet.enabled: true
301+
enableWindows: true
302+
privileged: false
303+
windows:
304+
privileged: true
305+
documentIndex: 0
306+
asserts:
307+
- equal:
308+
path: spec.template.spec.containers[0].securityContext.windowsOptions.hostProcess
309+
value: true
310+
template: templates/kubelet/daemonset-windows.yaml
311+
- equal:
312+
path: spec.template.spec.containers[1].securityContext.windowsOptions.hostProcess
313+
value: true
314+
template: templates/kubelet/daemonset-windows.yaml
315+
- equal:
316+
path: spec.template.spec.hostNetwork
317+
value: true
318+
template: templates/kubelet/daemonset-windows.yaml
319+
- equal:
320+
path: metadata.labels.mode
321+
value: privileged
322+
template: templates/kubelet/daemonset-windows.yaml
323+
268324
# Common tests
269325
- it: should set Windows OS spec
270326
set:

charts/newrelic-infrastructure/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ windowsOsList:
8484
# @ignored
8585
integrationImage: ""
8686

87+
# Windows-specific configuration
88+
windows:
89+
# -- (bool) Override privileged mode for Windows nodes.
90+
# When null, inherits from global 'privileged' setting.
91+
# Set to false to disable HostProcess mode on Windows while keeping Linux privileged.
92+
# HostProcess containers run directly on the Windows host (not in a container) and require hostNetwork: true.
93+
# @default -- Inherits from `privileged` setting
94+
privileged:
95+
8796
# -- Config that applies to all instances of the solution: kubelet, ksm, control plane and sidecars.
8897
# @default -- See `values.yaml`
8998
common:

0 commit comments

Comments
 (0)