Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions charts/newrelic-logging/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,52 @@ 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 .Values.global }}
{{- $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 := .Values.global.images.pullPolicy | default "" -}}
{{- $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 := .Values.global.images.pullPolicy | default "" -}}
{{- $chartPullPolicy := .Values.fluentBit.persistenceInitContainerImage.pullPolicy | default "" -}}
{{- if $chartPullPolicy -}}
{{- $chartPullPolicy -}}
{{- else if $globalPullPolicy -}}
{{- $globalPullPolicy -}}
{{- else -}}
IfNotPresent
{{- end -}}
{{- end -}}
8 changes: 5 additions & 3 deletions charts/newrelic-logging/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ spec:
{{- end }}
dnsPolicy: ClusterFirstWithHostNet
terminationGracePeriodSeconds: 10
{{- with include "newrelic.common.images.renderPullSecrets" ( dict "pullSecrets" (list .Values.image.pullSecrets) "context" .) }}
{{- $globalPullSecrets := .Values.global.images.pullSecrets | default list }}
{{- with include "newrelic.common.images.renderPullSecrets" ( dict "pullSecrets" (concat $globalPullSecrets (list .Values.image.pullSecrets)) "context" .) }}
imagePullSecrets:
{{- . | nindent 8 }}
{{- end }}
Expand All @@ -53,7 +54,8 @@ spec:
initContainers:
{{- if and (.Values.fluentBit.persistence) (eq .Values.fluentBit.persistence.mode "persistentVolume") }}
- name: init
image: busybox:1.36
image: {{ include "newrelic-logging.persistenceInitContainerImage" . }}:{{ .Values.fluentBit.persistenceInitContainerImage.tag }}
imagePullPolicy: {{ include "newrelic-logging.persistenceInitContainerImagePullPolicy" . }}
{{- with include "newrelic.common.securityContext.container" . }}
securityContext:
{{- . | nindent 12 }}
Expand All @@ -74,7 +76,7 @@ spec:
{{- . | nindent 12 }}
{{- end }}
image: {{ include "newrelic.common.images.image" ( dict "imageRoot" .Values.image "context" .) }}
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
imagePullPolicy: {{ include "newrelic-logging.imagePullPolicy" . }}
env:
- name: ENDPOINT
value: {{ include "newrelic-logging.logsEndpoint" . | quote }}
Expand Down
180 changes: 180 additions & 0 deletions charts/newrelic-logging/tests/images_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,183 @@ tests:
- equal:
path: spec.template.spec.imagePullSecrets[1].name
value: regsecret

# ---------------------------------------------------------------------------
# LICENSE_KEY env — verify secret name and key value, not just structure
# ---------------------------------------------------------------------------
- it: LICENSE_KEY env references the correct secret name and key
templates:
- templates/daemonset.yaml
set:
licenseKey: nr_license_key
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: LICENSE_KEY
valueFrom:
secretKeyRef:
name: my-release-newrelic-logging-config
key: license

- it: LICENSE_KEY env uses customSecretName and customSecretLicenseKey when set
templates:
- templates/daemonset.yaml
set:
customSecretName: my-custom-secret
customSecretLicenseKey: my-custom-key
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: LICENSE_KEY
valueFrom:
secretKeyRef:
name: my-custom-secret
key: my-custom-key

# ---------------------------------------------------------------------------
# Main image pullPolicy
# Precedence: chart-specific value > global.images.pullPolicy > default (IfNotPresent)
# ---------------------------------------------------------------------------
- it: Main image pullPolicy defaults to IfNotPresent when nothing set
templates:
- templates/daemonset.yaml
set: &main_pullpolicy_base
licenseKey: nr_license_key
image:
pullPolicy: ""
asserts:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: IfNotPresent

- it: Main image pullPolicy uses global when no chart-specific value
templates:
- templates/daemonset.yaml
set:
<<: *main_pullpolicy_base
global:
images:
pullPolicy: Always
asserts:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: Always

- it: Main image chart-specific pullPolicy overrides global
templates:
- templates/daemonset.yaml
set:
<<: *main_pullpolicy_base
image:
pullPolicy: Never
global:
images:
pullPolicy: Always
asserts:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: Never

# ---------------------------------------------------------------------------
# Persistence init container — image and pullPolicy
# Precedence: chart-specific value > global.images.* > default
# ---------------------------------------------------------------------------
- it: Init container uses default busybox image when no global registry set
templates:
- templates/daemonset.yaml
set: &pvc_base
licenseKey: nr_license_key
fluentBit:
persistence:
mode: persistentVolume
persistentVolume:
storageClass: sample-rwx
asserts:
- equal:
path: spec.template.spec.initContainers[0].image
value: busybox:1.36

- it: Init container uses global registry when set and repository is default
templates:
- templates/daemonset.yaml
set:
<<: *pvc_base
global:
images:
registry: my-registry.com
asserts:
- equal:
path: spec.template.spec.initContainers[0].image
value: my-registry.com/busybox:1.36

- it: Init container chart-specific repository overrides global registry
templates:
- templates/daemonset.yaml
set:
<<: *pvc_base
global:
images:
registry: my-registry.com
fluentBit:
persistence:
mode: persistentVolume
persistentVolume:
storageClass: sample-rwx
persistenceInitContainerImage:
repository: my-mirror.com/busybox
asserts:
- matchRegex:
path: spec.template.spec.initContainers[0].image
pattern: "^my-mirror.com/busybox:"

- it: Init container pullPolicy defaults to IfNotPresent when nothing set
templates:
- templates/daemonset.yaml
set: &init_pullpolicy_base
licenseKey: nr_license_key
fluentBit:
persistence:
mode: persistentVolume
persistentVolume:
storageClass: sample-rwx
persistenceInitContainerImage:
pullPolicy: ""
asserts:
- equal:
path: spec.template.spec.initContainers[0].imagePullPolicy
value: IfNotPresent

- it: Init container pullPolicy uses global when no chart-specific value
templates:
- templates/daemonset.yaml
set:
<<: *init_pullpolicy_base
global:
images:
pullPolicy: Always
asserts:
- equal:
path: spec.template.spec.initContainers[0].imagePullPolicy
value: Always

- it: Init container chart-specific pullPolicy overrides global
templates:
- templates/daemonset.yaml
set:
<<: *init_pullpolicy_base
fluentBit:
persistence:
mode: persistentVolume
persistentVolume:
storageClass: sample-rwx
persistenceInitContainerImage:
pullPolicy: Never
global:
images:
pullPolicy: Always
asserts:
- equal:
path: spec.template.spec.initContainers[0].imagePullPolicy
value: Never
6 changes: 6 additions & 0 deletions charts/newrelic-logging/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ fluentBit:
# - name: MY_TEMPLATIZED_ENV
# value: "templatization example {{ .Values.someValue }}"

# -- Image for the persistence init container (busybox). Defaults to busybox. If global.images.registry is set, it will be used instead.
persistenceInitContainerImage:
repository: busybox
tag: "1.36"
pullPolicy: IfNotPresent

# Indicates how fluent-bit database is persisted
persistence:
# Define the persistent mode for fluent-bit db, allowed options are `hostPath` (default), `none`, `persistentVolume`.
Expand Down