Skip to content

Commit

Permalink
Incorporate windows security context in same block
Browse files Browse the repository at this point in the history
  • Loading branch information
Vihas Splunk committed Jun 14, 2023
1 parent 33a6274 commit 3b2e20e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
14 changes: 5 additions & 9 deletions helm-charts/splunk-otel-collector/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -430,25 +430,21 @@ Whether clusterReceiver should be enabled
{{- end -}}

{{/*
Build the securityContext for Windows
Build the securityContext for Linux and Windows
*/}}
{{- define "splunk-otel-collector.windowsSecurityContext" -}}
{{- define "splunk-otel-collector.securityContext" -}}
{{- if .isWindows }}
{{- $_ := unset .securityContext "runAsUser" }}
{{- if not (hasKey .securityContext "windowsOptions")}}
{{- $_ := set .securityContext "windowsOptions" dict }}
{{- end }}
{{- if and (not (hasKey .securityContext.windowsOptions "runAsUserName")) (.setRunAsUser) }}
{{- $_ := set .securityContext.windowsOptions "runAsUserName" "ContainerAdministrator"}}
{{- end }}
{{- toYaml .securityContext }}
{{- end -}}

{{/*
Build the securityContext for Linux
*/}}
{{- define "splunk-otel-collector.securityContext" -}}
{{- else }}
{{- if and (eq (toString .securityContext.runAsUser) "<nil>") (.setRunAsUser) }}
{{- $_ := set .securityContext "runAsUser" 0 }}
{{- end }}
{{- end }}
{{- toYaml .securityContext }}
{{- end -}}
6 changes: 1 addition & 5 deletions helm-charts/splunk-otel-collector/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ spec:
imagePullPolicy: {{ .Values.image.otelcol.pullPolicy }}
{{- if or $agent.securityContext (and (eq (include "splunk-otel-collector.logsEnabled" $) "true") (eq .Values.logsEngine "otel")) }}
securityContext:
{{- if .Values.isWindows}}
{{- include "splunk-otel-collector.windowsSecurityContext" (dict "securityContext" $agent.securityContext "setRunAsUser" true) | nindent 10 }}
{{- else }}
{{- include "splunk-otel-collector.securityContext" (dict "securityContext" $agent.securityContext "setRunAsUser" true) | nindent 10 }}
{{- end}}
{{- include "splunk-otel-collector.securityContext" (dict "isWindows" .Values.isWindows "securityContext" $agent.securityContext "setRunAsUser" true) | nindent 10 }}
{{- end }}
env:
- name: SPLUNK_MEMORY_TOTAL_MIB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ spec:
{{- end }}
{{- if $clusterReceiver.securityContext }}
securityContext:
{{- if .Values.isWindows }}
{{- include "splunk-otel-collector.windowsSecurityContext" (dict "securityContext" $clusterReceiver.securityContext) | nindent 8 }}
{{- else }}
{{- include "splunk-otel-collector.securityContext" (dict "securityContext" $clusterReceiver.securityContext) | nindent 8 }}
{{- end }}
{{- include "splunk-otel-collector.securityContext" (dict "isWindows" .Values.isWindows "securityContext" $clusterReceiver.securityContext) | nindent 8 }}
{{- end }}
{{- if eq (include "splunk-otel-collector.distribution" .) "eks/fargate" }}
initContainers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ spec:
{{- end }}
{{- if $gateway.securityContext }}
securityContext:
{{- if .Values.isWindows }}
{{- include "splunk-otel-collector.windowsSecurityContext" (dict "securityContext" $gateway.securityContext) | nindent 8 }}
{{- else }}
{{- include "splunk-otel-collector.securityContext" (dict "securityContext" $gateway.securityContext) | nindent 8 }}
{{- end }}
{{- include "splunk-otel-collector.securityContext" (dict "isWindows" .Values.isWindows "securityContext" $gateway.securityContext) | nindent 8 }}
{{- end }}
containers:
- name: otel-collector
Expand Down

0 comments on commit 3b2e20e

Please sign in to comment.