Skip to content

Commit

Permalink
Allow using image digest in place of tag in grafana-agent Helm chart (
Browse files Browse the repository at this point in the history
  • Loading branch information
hainenber authored Sep 13, 2023
1 parent fdac7a0 commit c8d6fcf
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Main (unreleased)

- Flow: improve river config validation step in `prometheus.scrape` by comparing `scrape_timeout` with `scrape_interval`. (@wildum)


### Other changes

- Use Go 1.21.1 for builds. (@rfratto)
Expand Down
4 changes: 4 additions & 0 deletions operations/helm/charts/grafana-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ internal API changes are not present.
Unreleased
----------

### Enhancements

- An image's digest can now be used in place of a tag. (@hainenber)

0.24.0 (2023-09-08)
-------------------

Expand Down
2 changes: 2 additions & 0 deletions operations/helm/charts/grafana-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use the older mode (called "static mode"), set the `agent.mode` value to
| agent.storagePath | string | `"/tmp/agent"` | Path to where Grafana Agent stores data (for example, the Write-Ahead Log). By default, data is lost between reboots. |
| configReloader.customArgs | list | `[]` | Override the args passed to the container. |
| configReloader.enabled | bool | `true` | Enables automatically reloading when the agent config changes. |
| configReloader.image.digest | string | `""` | SHA256 digest of image to use for config reloading (either in format "sha256:XYZ" or "XYZ"). When set, will override `configReloader.image.tag` |
| configReloader.image.registry | string | `"docker.io"` | Config reloader image registry (defaults to docker.io) |
| configReloader.image.repository | string | `"jimmidyson/configmap-reload"` | Repository to get config reloader image from. |
| configReloader.image.tag | string | `"v0.8.0"` | Tag of image to use for config reloading. |
Expand Down Expand Up @@ -92,6 +93,7 @@ use the older mode (called "static mode"), set the `agent.mode` value to
| global.image.pullSecrets | list | `[]` | Optional set of global image pull secrets. |
| global.image.registry | string | `""` | Global image registry to use if it needs to be overriden for some specific use cases (e.g local registries, custom images, ...) |
| global.podSecurityContext | object | `{}` | Security context to apply to the Grafana Agent pod. |
| image.digest | string | `nil` | Grafana Agent image's SHA256 digest (either in format "sha256:XYZ" or "XYZ"). When set, will override `image.tag`. |
| image.pullPolicy | string | `"IfNotPresent"` | Grafana Agent image pull policy. |
| image.pullSecrets | list | `[]` | Optional set of image pull secrets. |
| image.registry | string | `"docker.io"` | Grafana Agent image registry (defaults to docker.io) |
Expand Down
35 changes: 29 additions & 6 deletions operations/helm/charts/grafana-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,36 @@ Create the name of the service account to use
{{- end }}

{{/*
Calculate name of image tag to use.
Calculate name of image ID to use for "grafana-agent".
*/}}
{{- define "grafana-agent.imageTag" -}}
{{- if .Values.image.tag -}}
{{- .Values.image.tag }}
{{- else -}}
{{- .Chart.AppVersion }}
{{- define "grafana-agent.imageId" -}}
{{- if .Values.image.digest }}
{{- $digest := .Values.image.digest }}
{{- if not (hasPrefix "sha256:" $digest) }}
{{- $digest = printf "sha256:%s" $digest }}
{{- end }}
{{- printf "@%s" $digest }}
{{- else if .Values.image.tag }}
{{- printf ":%s" .Values.image.tag }}
{{- else }}
{{- printf ":%s" .Chart.AppVersion }}
{{- end }}
{{- end }}

{{/*
Calculate name of image ID to use for "config-reloader".
*/}}
{{- define "config-reloader.imageId" -}}
{{- if .Values.configReloader.image.digest }}
{{- $digest := .Values.configReloader.digest }}
{{- if not (hasPrefix "sha256:" $digest) }}
{{- $digest = printf "sha256:%s" $digest }}
{{- end }}
{{- printf "@%s" $digest }}
{{- else if .Values.configReloader.image.tag }}
{{- printf ":%s" .Values.configReloader.image.tag }}
{{- else }}
{{- printf ":%s" "v0.8.0" }}
{{- end }}
{{- end }}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- define "grafana-agent.container" -}}
- name: grafana-agent
image: {{ .Values.global.image.registry | default .Values.image.registry }}/{{ .Values.image.repository }}:{{ include "grafana-agent.imageTag" . }}
image: {{ .Values.global.image.registry | default .Values.image.registry }}/{{ .Values.image.repository }}{{ include "grafana-agent.imageId" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
{{- if eq .Values.agent.mode "flow"}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- define "grafana-agent.watch-container" -}}
{{- if .Values.configReloader.enabled -}}
- name: config-reloader
image: {{ .Values.global.image.registry | default .Values.configReloader.image.registry }}/{{ .Values.configReloader.image.repository }}:{{ .Values.configReloader.image.tag }}
image: {{ .Values.global.image.registry | default .Values.configReloader.image.registry }}/{{ .Values.configReloader.image.repository }}{{ include "config-reloader.imageId" . }}
{{- if .Values.configReloader.customArgs }}
args:
{{- toYaml .Values.configReloader.customArgs | nindent 4 }}
Expand Down
4 changes: 4 additions & 0 deletions operations/helm/charts/grafana-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ image:
# -- (string) Grafana Agent image tag. When empty, the Chart's appVersion is
# used.
tag: null
# -- Grafana Agent image's SHA256 digest (either in format "sha256:XYZ" or "XYZ"). When set, will override `image.tag`.
digest: null
# -- Grafana Agent image pull policy.
pullPolicy: IfNotPresent
# -- Optional set of image pull secrets.
Expand Down Expand Up @@ -128,6 +130,8 @@ configReloader:
repository: jimmidyson/configmap-reload
# -- Tag of image to use for config reloading.
tag: v0.8.0
# -- SHA256 digest of image to use for config reloading (either in format "sha256:XYZ" or "XYZ"). When set, will override `configReloader.image.tag`
digest: ""
# -- Override the args passed to the container.
customArgs: []
# -- Resource requests and limits to apply to the config reloader container.
Expand Down

0 comments on commit c8d6fcf

Please sign in to comment.