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

fix: detect correctly v3 version when using sha in image.tag #909

Merged
merged 10 commits into from
Aug 16, 2023
5 changes: 5 additions & 0 deletions traefik/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,8 @@ Renders a complete tree, even values that contains template.
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}

{{- define "imageVersion" -}}
{{ (split "@" (default $.Chart.AppVersion $.Values.image.tag))._0 }}
{{- end -}}

10 changes: 5 additions & 5 deletions traefik/templates/_podtemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
{{- if $config }}
- "--entrypoints.{{$name}}.address=:{{ $config.port }}/{{ default "tcp" $config.protocol | lower }}"
{{- with $config.asDefault }}
{{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }}
{{- if semverCompare "<3.0.0-0" (include "imageVersion" $) }}
{{- fail "ERROR: Default entrypoints are only available on Traefik v3. Please set `image.tag` to `v3.x`." }}
{{- end }}
- "--entrypoints.{{$name}}.asDefault={{ . }}"
Expand Down Expand Up @@ -298,7 +298,7 @@
{{- end }}

{{- with .Values.metrics.openTelemetry }}
{{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }}
{{- if semverCompare "<3.0.0-0" (include "imageVersion" $) }}
{{- fail "ERROR: OpenTelemetry features are only available on Traefik v3. Please set `image.tag` to `v3.x`." }}
{{- end }}
- "--metrics.openTelemetry=true"
Expand Down Expand Up @@ -357,7 +357,7 @@
{{- if .Values.tracing }}

{{- if .Values.tracing.openTelemetry }}
{{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }}
{{- if semverCompare "<3.0.0-0" (include "imageVersion" $) }}
{{- fail "ERROR: OpenTelemetry features are only available on Traefik v3. Please set `image.tag` to `v3.x`." }}
{{- end }}
- "--tracing.openTelemetry=true"
Expand Down Expand Up @@ -591,10 +591,10 @@
{{- end }}
{{- if $config.http3 }}
{{- if $config.http3.enabled }}
{{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag)}}
{{- if semverCompare "<3.0.0-0" (include "imageVersion" $)}}
- "--experimental.http3=true"
{{- end }}
{{- if semverCompare ">=2.6.0-0" (default $.Chart.AppVersion $.Values.image.tag)}}
{{- if semverCompare ">=2.6.0-0" (include "imageVersion" $)}}
- "--entrypoints.{{ $entrypoint }}.http3"
{{- else }}
- "--entrypoints.{{ $entrypoint }}.enableHTTP3=true"
Expand Down
2 changes: 1 addition & 1 deletion traefik/templates/ingressclass.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.ingressClass.enabled -}}
{{- if (semverCompare "<2.3.0" (.Chart.AppVersion)) -}}
{{- if (semverCompare "<2.3.0" (include "imageVersion" $)) -}}
{{- fail "ERROR: IngressClass cannot be used with Traefik < 2.3.0" -}}
{{- end -}}
{{- if semverCompare ">=1.19.0-0" .Capabilities.KubeVersion.Version -}}
Expand Down
4 changes: 2 additions & 2 deletions traefik/templates/rbac/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ rules:
{{- if .Values.providers.kubernetesCRD.enabled }}
- apiGroups:
- traefik.io
{{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }}
{{- if semverCompare "<3.0.0-0" (include "imageVersion" $) }}
- traefik.containo.us
{{- end }}
resources:
Expand All @@ -58,7 +58,7 @@ rules:
- tlsstores
- traefikservices
- serverstransports
{{- if semverCompare ">=3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }}
{{- if semverCompare ">=3.0.0-0" (include "imageVersion" $) }}
- serverstransporttcps
{{- end }}
verbs:
Expand Down
4 changes: 2 additions & 2 deletions traefik/templates/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rules:
{{- if (and (has . $CRDNamespaces) $.Values.providers.kubernetesCRD.enabled) }}
- apiGroups:
- traefik.io
{{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }}
{{- if semverCompare "<3.0.0-0" (include "imageVersion" $) }}
- traefik.containo.us
{{- end }}
resources:
Expand All @@ -57,7 +57,7 @@ rules:
- tlsstores
- traefikservices
- serverstransports
{{- if semverCompare ">=3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }}
{{- if semverCompare ">=3.0.0-0" (include "imageVersion" $) }}
- serverstransporttcps
{{- end }}
verbs:
Expand Down
24 changes: 24 additions & 0 deletions traefik/tests/tracing-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ tests:
- contains:
path: spec.template.spec.containers[0].args
content: "--tracing.openTelemetry.address=localhost:4318"
- it: Should work with sha set
set:
image:
tag: v3.0.0-beta3@sha256:a56dcbeb82281b0ac99297d226195215f747242daa5a2213de02d8a09a6d9cfd
tracing:
openTelemetry:
address: localhost:4318
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: "--tracing.openTelemetry=true"
- contains:
path: spec.template.spec.containers[0].args
content: "--tracing.openTelemetry.address=localhost:4318"
- it: Address is required
set:
image:
Expand All @@ -70,3 +84,13 @@ tests:
asserts:
- failedTemplate:
errorMessage: "OpenTelemetry features are only available on Traefik v3. Please set `image.tag` to `v3.x`."
- it: should throw and error when open telemetry is enabled without traefik v3, even with sha set
set:
image:
tag: v2.10.1@sha256:a56dcbeb82281b0ac99297d226195215f747242daa5a2213de02d8a09a6d9cfd
tracing:
openTelemetry:
address: "localhost:4318"
asserts:
- failedTemplate:
errorMessage: "OpenTelemetry features are only available on Traefik v3. Please set `image.tag` to `v3.x`."