Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fluentd): add image reference by digest #362

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion charts/fluentd/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: fluentd
description: A Helm chart for Kubernetes
# type: application
version: 0.4.3
version: 0.4.4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this

appVersion: v1.15.2
icon: https://www.fluentd.org/images/miscellany/fluentd-logo_2x.png
home: https://www.fluentd.org/
Expand Down
9 changes: 9 additions & 0 deletions charts/fluentd/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ Name of the configMap used for additional configuration files; allows users to o
{{ printf "%s-%s" "fluentd-config" ( include "fluentd.shortReleaseName" . ) }}
{{- end -}}
{{- end -}}

{{/*
Fluentd image with tag/digest
*/}}
{{- define "fluentd.image" -}}
{{- $tag := ternary "" (printf ":%s" (toString .tag)) (or (empty .tag) (eq "-" (toString .tag))) -}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tags and hashes can coexist, where hash will always takes precedence over the tag, even if they dont match.

With this info you should be able to simplify this. Although it works as it is...

{{- $digest := ternary "" (printf "@%s" .digest) (empty .digest) -}}
{{- printf "%s%s%s" .repository $tag $digest -}}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/fluentd/templates/_pod.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 6 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default $defaultTag }}"
image: {{ include "fluentd.image" (merge .Values.image (dict "tag" (default $defaultTag .Values.image.tag))) }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.plugins }}
command:
Expand Down
11 changes: 9 additions & 2 deletions charts/fluentd/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.testFramework.enabled }}
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -9,7 +10,13 @@ metadata:
spec:
containers:
- name: wget
image: busybox
image: {{ include "fluentd.image" .Values.testFramework.image }}
imagePullPolicy: {{ .Values.testFramework.image.pullPolicy }}
command: ['wget']
args: ['{{ include "fluentd.fullname" . }}:{{ .Values.service.port }}']
args: ['{{ include "fluentd.fullname" . }}:24231/metrics']
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 4 }}
{{- end }}
restartPolicy: Never
{{- end }}
11 changes: 10 additions & 1 deletion charts/fluentd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ kind: "DaemonSet"
image:
repository: "fluent/fluentd-kubernetes-daemonset"
pullPolicy: "IfNotPresent"
tag: ""
tag: "" # Set to "-" to not use the default value
Copy link
Collaborator

@dioguerra dioguerra Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I just tested and everything works fine.

Just drop the comment in front of tag which is not required...

helm template fluentd . -n kube-system -s templates/daemonset.yaml --set image.repository=myrepo/myimage --set image.tag=1.1.1 --set image.digest=sha256:4a1c4b21597c1b4415bdbecb28a3296c6b5e23ca4f9feeb599860a1dac6a0108

digest: ""

testFramework:
enabled: true
image:
repository: busybox
pullPolicy: Always
tag: latest
digest: ""

## Optional array of imagePullSecrets containing private registry credentials
## Ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
Expand Down