Skip to content

Commit 80d6835

Browse files
add ability to provide a digest for haproxy
This follows the same pattern as the image syntax for the vector container
1 parent 3cff55e commit 80d6835

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

charts/vector/templates/haproxy/_helpers.tpl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,52 @@ If release name contains chart name it will be used as a full name.
77
{{- printf "%s-haproxy" (include "vector.fullname" .) | trunc 63 | trimSuffix "-" }}
88
{{- end }}
99

10+
{{/*
11+
Build a valid image reference from available fields:
12+
- tag only: repo:tag
13+
- sha/digest only: repo@sha256:…
14+
- tag@digest: repo:tag@sha256:…
15+
- nothing set: repo:<Chart.AppVersion>
16+
*/}}
17+
{{- define "haproxy.image" -}}
18+
{{- $repo := .Values.haproxy.image.repository -}}
19+
{{- $tagRaw := .Values.haproxy.image.tag -}}
20+
{{- $shaRaw := (coalesce .Values.haproxy.image.sha .Values.haproxy.image.digest) | default "" -}}
21+
{{- $tag := trim $tagRaw -}}
22+
23+
{{- /* Normalize SHA to ensure it has sha256: prefix for backward compatibility */ -}}
24+
{{- $sha := "" -}}
25+
{{- if $shaRaw -}}
26+
{{- if hasPrefix "sha256:" $shaRaw -}}
27+
{{- $sha = $shaRaw -}}
28+
{{- else -}}
29+
{{- $sha = printf "sha256:%s" $shaRaw -}}
30+
{{- end -}}
31+
{{- end -}}
32+
33+
{{- /* Case 1: digest field wins */ -}}
34+
{{- if $sha -}}
35+
{{- if $tag -}}
36+
{{- printf "%s:%s@%s" $repo $tag $sha -}}
37+
{{- else -}}
38+
{{- printf "%s@%s" $repo $sha -}}
39+
{{- end -}}
40+
41+
{{- /* Case 2: tag looks like a digest */ -}}
42+
{{- else if hasPrefix "sha256:" $tag -}}
43+
{{- printf "%s@%s" $repo $tag -}}
44+
45+
{{- /* Case 3: tag@digest combined syntax */ -}}
46+
{{- else if contains "@sha256:" $tag -}}
47+
{{- $parts := splitList "@" $tag -}}
48+
{{- printf "%s:%s@%s" $repo (index $parts 0) (index $parts 1) -}}
49+
50+
{{- /* Case 4: normal tag */ -}}
51+
{{- else if $tag -}}
52+
{{- printf "%s:%s" $repo $tag -}}
53+
{{- end }}
54+
{{- end }}
55+
1056
{{/*
1157
Common labels
1258
*/}}

charts/vector/templates/haproxy/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ spec:
4949
- name: haproxy
5050
securityContext:
5151
{{- toYaml .Values.haproxy.securityContext | nindent 12 }}
52-
image: "{{ .Values.haproxy.image.repository }}:{{ .Values.haproxy.image.tag }}"
52+
image: "{{ include "haproxy.image" . }}"
5353
imagePullPolicy: {{ .Values.haproxy.image.pullPolicy }}
5454
args:
5555
- -f

charts/vector/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ haproxy:
535535
pullSecrets: []
536536
# haproxy.image.tag -- The tag to use for HAProxy's image.
537537
tag: "2.6.12"
538+
# haproxy.image.tag -- The SHA to use for HAProxy's image.
539+
sha:
538540

539541
# haproxy.rollWorkload -- Add a checksum of the generated ConfigMap to the HAProxy Deployment.
540542
rollWorkload: true

0 commit comments

Comments
 (0)