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
46 changes: 46 additions & 0 deletions charts/vector/templates/haproxy/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,52 @@ 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:<Chart.AppVersion>
*/}}
{{- define "haproxy.image" -}}
{{- $repo := .Values.haproxy.image.repository -}}
{{- $tagRaw := .Values.haproxy.image.tag -}}
{{- $shaRaw := (coalesce .Values.haproxy.image.sha .Values.haproxy.image.digest) | default "" -}}
{{- $tag := trim $tagRaw -}}

{{- /* 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 -}}
{{- $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 -}}
{{- end }}
Comment on lines +51 to +53
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 Add fallback image tag when no tag or digest is set

This helper stops at else if $tag and never handles the case where both haproxy.image.tag and haproxy.image.sha/digest are empty, so it returns an empty string. Because deployment.yaml now uses this helper for image, that path renders image: "", which Kubernetes rejects for a container spec. The comment above this function also states a repo:<Chart.AppVersion> fallback, so the current implementation breaks that advertised behavior.

Useful? React with 👍 / 👎.

{{- 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 @@ -50,7 +50,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 @@ -553,6 +553,8 @@ haproxy:
pullSecrets: []
# haproxy.image.tag -- The tag to use for HAProxy's image.
tag: "2.6.12"
# haproxy.image.tag -- 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