Skip to content
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
50 changes: 50 additions & 0 deletions charts/vector/templates/haproxy/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,56 @@ If release name contains chart name it will be used as a full name.
{{- printf "%s-haproxy" (include "vector.fullname" .) | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Build a valid image reference from available fields:
- tag only: repo:tag
- sha/digest only: repo@sha256:…
- tag@digest: repo:tag@sha256:…
- nothing set: repo:latest
*/}}
{{- define "haproxy.image" -}}
{{- $repo := .Values.haproxy.image.repository | default "haproxytech/haproxy-alpine" -}}
{{- $tagRaw := .Values.haproxy.image.tag | default "" -}}
{{- $shaRaw := (coalesce .Values.haproxy.image.sha .Values.haproxy.image.digest) | default "" -}}
{{- $tag := trim $tagRaw -}}
Comment thread
pront marked this conversation as resolved.

{{- /* Normalize SHA to ensure it has sha256: prefix for backward compatibility */ -}}
{{- $sha := "" -}}
{{- if $shaRaw -}}
{{- if hasPrefix "sha256:" $shaRaw -}}
{{- $sha = $shaRaw -}}
{{- else -}}
{{- $sha = printf "sha256:%s" $shaRaw -}}
{{- end -}}
{{- end -}}

{{- /* Case 1: digest field wins */ -}}
{{- if $sha -}}
{{- if $tag -}}
{{- printf "%s:%s@%s" $repo $tag $sha -}}
{{- else -}}
{{- printf "%s@%s" $repo $sha -}}
{{- end -}}

{{- /* Case 2: tag looks like a digest */ -}}
{{- else if hasPrefix "sha256:" $tag -}}
{{- printf "%s@%s" $repo $tag -}}

{{- /* Case 3: tag@digest combined syntax */ -}}
{{- else if contains "@sha256:" $tag -}}
Comment on lines +42 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid digest-valued tags in the version label

When HAProxy users set haproxy.image.tag to one of the newly supported digest forms (sha256:... here, or tag@sha256:... in the next branch), the image renders correctly but haproxy.labels still emits app.kubernetes.io/version: {{ .Values.haproxy.image.tag | quote }}. Kubernetes label values may not contain : or @, so these advertised inputs make the Deployment metadata invalid whenever HAProxy is enabled; either avoid supporting digest syntax in tag or sanitize/omit the label for those cases.

Useful? React with 👍 / 👎.

{{- $parts := splitList "@" $tag -}}
{{- printf "%s:%s@%s" $repo (index $parts 0) (index $parts 1) -}}

{{- /* Case 4: normal tag */ -}}
{{- else if $tag -}}
{{- printf "%s:%s" $repo $tag -}}

{{- /* Case 5: no tag or digest set */ -}}
{{- else -}}
{{- printf "%s:%s" $repo "latest" -}}
{{- end }}
Comment thread
LaurentGoderre marked this conversation as resolved.
{{- end }}

{{/*
Common labels
*/}}
Expand Down
2 changes: 1 addition & 1 deletion charts/vector/templates/haproxy/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:
- name: haproxy
securityContext:
{{- toYaml .Values.haproxy.securityContext | nindent 12 }}
image: "{{ .Values.haproxy.image.repository }}:{{ .Values.haproxy.image.tag }}"
image: "{{ include "haproxy.image" . }}"
imagePullPolicy: {{ .Values.haproxy.image.pullPolicy }}
args:
- -f
Expand Down
2 changes: 2 additions & 0 deletions charts/vector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ haproxy:
pullSecrets: []
# haproxy.image.tag -- The tag to use for HAProxy's image.
tag: "2.6.12"
# haproxy.image.sha -- The SHA to use for HAProxy's image.
sha:

# haproxy.rollWorkload -- Add a checksum of the generated ConfigMap to the HAProxy Deployment.
rollWorkload: true
Expand Down
Loading