Skip to content
118 changes: 81 additions & 37 deletions charts/newrelic-logging/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,66 +48,54 @@ Create the name of the fluent bit config
Return the licenseKey
*/}}
{{- define "newrelic-logging.licenseKey" -}}
{{- if .Values.global}}
{{- if .Values.licenseKey }}
{{- .Values.licenseKey -}}
{{- else if .Values.global }}
{{- if .Values.global.licenseKey }}
{{- .Values.global.licenseKey -}}
{{- else -}}
{{- .Values.licenseKey | default "" -}}
{{- .Values.global.licenseKey -}}
{{- end -}}
{{- else -}}
{{- .Values.licenseKey | default "" -}}
{{- end -}}
{{- end -}}

{{/*
Return the cluster name
*/}}
{{- define "newrelic-logging.cluster" -}}
{{- if .Values.global}}
{{- if .Values.cluster }}
{{- .Values.cluster -}}
{{- else if .Values.global }}
{{- if .Values.global.cluster }}
{{- .Values.global.cluster -}}
{{- else -}}
{{- .Values.cluster | default "" -}}
{{- end -}}
{{- else -}}
{{- .Values.cluster | default "" -}}
{{- end -}}
{{- end -}}

{{/*
Return the customSecretName
*/}}
{{- define "newrelic-logging.customSecretName" -}}
{{- if .Values.global }}
{{- if .Values.customSecretName }}
{{- .Values.customSecretName -}}
{{- else if .Values.global }}
{{- if .Values.global.customSecretName }}
{{- .Values.global.customSecretName -}}
{{- else -}}
{{- .Values.customSecretName | default "" -}}
{{- .Values.global.customSecretName -}}
{{- end -}}
{{- else -}}
{{- .Values.customSecretName | default "" -}}
{{- end -}}
{{- end -}}

{{/*
Return the customSecretLicenseKey
*/}}
{{- define "newrelic-logging.customSecretKey" -}}
{{- if .Values.global }}
{{- if .Values.customSecretLicenseKey }}
{{- .Values.customSecretLicenseKey -}}
{{- else if .Values.customSecretKey }}
{{- .Values.customSecretKey -}}
{{- else if .Values.global }}
{{- if .Values.global.customSecretLicenseKey }}
{{- .Values.global.customSecretLicenseKey -}}
{{- else -}}
{{- if .Values.global.customSecretKey }}
{{- .Values.global.customSecretKey -}}
{{- else -}}
{{- .Values.customSecretKey | default "" -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- if .Values.customSecretLicenseKey }}
{{- .Values.customSecretLicenseKey -}}
{{- else -}}
{{- .Values.customSecretKey | default "" -}}
{{- .Values.global.customSecretLicenseKey -}}
{{- else if .Values.global.customSecretKey }}
{{- .Values.global.customSecretKey -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand All @@ -116,25 +104,25 @@ Return the customSecretLicenseKey
Returns nrStaging
*/}}
{{- define "newrelic.nrStaging" -}}
{{- if .Values.global }}
{{- if .Values.nrStaging }}
{{- .Values.nrStaging -}}
{{- else if .Values.global }}
{{- if .Values.global.nrStaging }}
{{- .Values.global.nrStaging -}}
{{- end -}}
{{- else if .Values.nrStaging }}
{{- .Values.nrStaging -}}
{{- end -}}
{{- end -}}

{{/*
Returns fargate
*/}}
{{- define "newrelic.fargate" -}}
{{- if .Values.global }}
{{- if .Values.fargate }}
{{- .Values.fargate -}}
{{- else if .Values.global }}
{{- if .Values.global.fargate }}
{{- .Values.global.fargate -}}
{{- end -}}
{{- else if .Values.fargate }}
{{- .Values.fargate -}}
{{- end -}}
{{- end -}}

Expand Down Expand Up @@ -284,4 +272,60 @@ If additionalEnvVariables is set, renames to extraEnv. Returns extraEnv.
{{- end -}}
{{- end -}}

{{/*
Returns the image for the persistence init container.
Precedence: chart-specific repository > global.images.registry + default > chart default (busybox)
*/}}
{{- define "newrelic-logging.persistenceInitContainerImage" -}}
{{- $repository := .Values.fluentBit.persistenceInitContainerImage.repository -}}
{{- $defaultRepository := "busybox" -}}
{{- $registry := "" -}}
{{- if and .Values.global .Values.global.images }}
{{- $registry = .Values.global.images.registry | default "" -}}
{{- end -}}
{{- if and $registry (eq $repository $defaultRepository) -}}
{{- printf "%s/%s" $registry $defaultRepository -}}
{{- else -}}
{{- $repository -}}
{{- end -}}
{{- end -}}

{{/*
Returns the pull policy for main image.
Precedence: chart-specific value > global.images.pullPolicy > default (IfNotPresent)
*/}}
{{- define "newrelic-logging.imagePullPolicy" -}}
{{- $globalPullPolicy := "" -}}
{{- if and .Values.global .Values.global.images -}}
{{- $globalPullPolicy = .Values.global.images.pullPolicy | default "" -}}
{{- end -}}
{{- $chartPullPolicy := .Values.image.pullPolicy | default "" -}}
{{- if $chartPullPolicy -}}
{{- $chartPullPolicy -}}
{{- else if $globalPullPolicy -}}
{{- $globalPullPolicy -}}
{{- else -}}
IfNotPresent
{{- end -}}
{{- end -}}

{{/*
Returns the pull policy for persistence init container.
Precedence: chart-specific value > global.images.pullPolicy > default (IfNotPresent)
*/}}
{{- define "newrelic-logging.persistenceInitContainerImagePullPolicy" -}}
{{- $globalPullPolicy := "" -}}
{{- if and .Values.global .Values.global.images -}}
{{- $globalPullPolicy = .Values.global.images.pullPolicy | default "" -}}
{{- end -}}
{{- $chartPullPolicy := .Values.fluentBit.persistenceInitContainerImage.pullPolicy | default "" -}}
{{- if $chartPullPolicy -}}
{{- $chartPullPolicy -}}
{{- else if $globalPullPolicy -}}
{{- $globalPullPolicy -}}
{{- else -}}
IfNotPresent
{{- end -}}
{{- end -}}


67 changes: 49 additions & 18 deletions charts/newrelic-logging/templates/daemonset-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
namespace: {{ $.Release.Namespace }}
labels:
kubernetes.io/os: windows
{{ include "newrelic-logging.labels" $ | indent 4 }}
{{- include "newrelic.common.labels" $ | nindent 4 }}
name: {{ template "newrelic-logging.fullname" $ }}-windows-{{ .version }}
annotations:
{{- if $.Values.daemonSet.annotations }}
Expand All @@ -17,8 +17,7 @@ spec:
type: {{ $.Values.updateStrategy }}
selector:
matchLabels:
app: {{ template "newrelic-logging.name" $ }}
release: {{ $.Release.Name }}
{{- include "newrelic.common.labels.selectorLabels" $ | nindent 6 }}
kubernetes.io/os: windows
template:
metadata:
Expand All @@ -28,13 +27,8 @@ spec:
{{ toYaml $.Values.podAnnotations | indent 8}}
{{- end }}
labels:
app: {{ template "newrelic-logging.name" $ }}
release: {{ $.Release.Name }}
kubernetes.io/os: windows
app.kubernetes.io/name: {{ template "newrelic-logging.name" $ }}
{{- if $.Values.podLabels}}
{{ toYaml $.Values.podLabels | indent 8 }}
{{- end }}
{{- include "newrelic.common.labels.podLabels" $ | nindent 8 }}
spec:
serviceAccountName: {{ include "newrelic.common.serviceAccount.name" $ }}
{{- with include "newrelic.common.dnsConfig" $ }}
Expand All @@ -47,8 +41,16 @@ spec:
imagePullSecrets:
{{- . | nindent 8 }}
{{- end }}
{{- if $.Values.hostNetwork }}
hostNetwork: {{ $.Values.hostNetwork }}
{{- $hostNetwork := false }}
{{- if not (kindIs "invalid" $.Values.hostNetwork) }}
{{- $hostNetwork = $.Values.hostNetwork }}
{{- else if $.Values.global }}
{{- if not (kindIs "invalid" $.Values.global.hostNetwork) }}
{{- $hostNetwork = $.Values.global.hostNetwork }}
{{- end }}
{{- end }}
{{- if $hostNetwork }}
hostNetwork: {{ $hostNetwork }}
{{- end }}
{{- if $.Values.windows.initContainers }}
initContainers:
Expand Down Expand Up @@ -78,8 +80,18 @@ spec:
{{- end }}
- name: CLUSTER_NAME
value: {{ include "newrelic-logging.cluster" $ }}
{{- $verboseLog := include "newrelic.common.verboseLog" $ -}}
{{- $logLevel := $.Values.fluentBit.logLevel | default "" -}}
{{- if $logLevel }}
- name: LOG_LEVEL
value: {{ $logLevel | quote }}
{{- else if $verboseLog }}
- name: LOG_LEVEL
value: {{ $.Values.fluentBit.logLevel | quote }}
value: "debug"
{{- else }}
- name: LOG_LEVEL
value: "info"
{{- end }}
- name: LOG_PARSER
{{- if $.Values.fluentBit.criEnabled }}
value: "cri,docker"
Expand Down Expand Up @@ -115,7 +127,18 @@ spec:
value: {{ $.Values.fluentBit.sendMetrics | default "false" | quote }}
- name: METRICS_HOST
value: {{ include "newrelic-logging.metricsHost" $ | quote }}
- name: FLUENTBIT_METRICS_TIER
{{- $globalProxy := "" }}
{{- if $.Values.global }}
{{- $globalProxy = $.Values.global.proxy | default "" }}
{{- end }}
{{- $proxy := $.Values.proxy | default $globalProxy | default "" }}
{{- if $proxy }}
- name: HTTP_PROXY
value: {{ $proxy | quote }}
- name: HTTPS_PROXY
value: {{ $proxy | quote }}
{{- end }}
- name: FLUENTBIT_METRICS_TIER
value: {{ $.Values.fluentBit.fluentBitMetrics | default "basic" | quote }}
{{- include "newrelic-logging.extraEnv" $ | nindent 12 }}
- name: DAEMONSET_NAME
Expand Down Expand Up @@ -181,20 +204,28 @@ spec:
- name: progdata
hostPath:
path: C:\ProgramData
{{- if $.Values.priorityClassName }}
priorityClassName: {{ $.Values.priorityClassName }}
{{- with include "newrelic.common.priorityClassName" $ }}
priorityClassName: {{ . }}
{{- end }}
{{- with include "newrelic.common.affinity" $ }}
affinity:
{{- . | nindent 8 }}
{{- end }}
{{- $nodeSelector := include "newrelic.common.nodeSelector" $ }}
nodeSelector:
{{- if $nodeSelector }}
{{- $nodeSelector | nindent 8 }}
{{- end }}
{{- if $.Values.windowsNodeSelector }}
{{ toYaml $.Values.windowsNodeSelector | indent 8 }}
{{- toYaml $.Values.windowsNodeSelector | nindent 8 }}
{{- else }}
kubernetes.io/os: windows
# Windows containers can only be executed on hosts running the exact same Windows version and build number
node.kubernetes.io/windows-build: {{ .buildNumber }}
{{- end }}
{{- if $.Values.tolerations }}
{{- with include "newrelic.common.tolerations" $ }}
tolerations:
{{ toYaml $.Values.tolerations | indent 8 }}
{{- . | nindent 8 }}
{{- end }}
---
{{- end }}
Expand Down
Loading