From fe065ee56c98bb0edbaccb1c5d8e5c67722e6b3d Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 11:37:09 +0700 Subject: [PATCH 01/10] Move version compare to templates --- traefik/templates/_helpers.tpl | 13 +++++++++++++ traefik/templates/_podtemplate.tpl | 8 ++++---- traefik/templates/rbac/clusterrole.yaml | 4 ++-- traefik/templates/rbac/role.yaml | 4 ++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/traefik/templates/_helpers.tpl b/traefik/templates/_helpers.tpl index a6c8b9fa4..f54e4c813 100644 --- a/traefik/templates/_helpers.tpl +++ b/traefik/templates/_helpers.tpl @@ -124,3 +124,16 @@ Renders a complete tree, even values that contains template. {{- tpl (.value | toYaml) .context }} {{- end }} {{- end -}} + +{{- define "imageVersion" -}} +{{ default $.Chart.AppVersion $.Values.image.tag | split "@" | mustFirst }} +{{- end -}} + +{{- define "isV3" -}} +semverCompare ">=3.0.0-0" (include "imageVersion" .) +{{- end -}} + +{{- define "isV2" -}} +semverCompare "<3.0.0-0" (include "imageVersion" .) +{{- end -}} + diff --git a/traefik/templates/_podtemplate.tpl b/traefik/templates/_podtemplate.tpl index 8e2de9a3d..b05f4932d 100644 --- a/traefik/templates/_podtemplate.tpl +++ b/traefik/templates/_podtemplate.tpl @@ -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 (include "isV2" .) }} {{- fail "ERROR: Default entrypoints are only available on Traefik v3. Please set `image.tag` to `v3.x`." }} {{- end }} - "--entrypoints.{{$name}}.asDefault={{ . }}" @@ -298,7 +298,7 @@ {{- end }} {{- with .Values.metrics.openTelemetry }} - {{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }} + {{- if (include "isV2" .) }} {{- fail "ERROR: OpenTelemetry features are only available on Traefik v3. Please set `image.tag` to `v3.x`." }} {{- end }} - "--metrics.openTelemetry=true" @@ -357,7 +357,7 @@ {{- if .Values.tracing }} {{- if .Values.tracing.openTelemetry }} - {{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }} + {{- if (include "isV2" .) }} {{- fail "ERROR: OpenTelemetry features are only available on Traefik v3. Please set `image.tag` to `v3.x`." }} {{- end }} - "--tracing.openTelemetry=true" @@ -591,7 +591,7 @@ {{- end }} {{- if $config.http3 }} {{- if $config.http3.enabled }} - {{- if semverCompare "<3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag)}} + {{- if (include "isV2" .)}} - "--experimental.http3=true" {{- end }} {{- if semverCompare ">=2.6.0-0" (default $.Chart.AppVersion $.Values.image.tag)}} diff --git a/traefik/templates/rbac/clusterrole.yaml b/traefik/templates/rbac/clusterrole.yaml index 43038d542..2d8af2a16 100644 --- a/traefik/templates/rbac/clusterrole.yaml +++ b/traefik/templates/rbac/clusterrole.yaml @@ -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 (include "isV2" .) }} - traefik.containo.us {{- end }} resources: @@ -58,7 +58,7 @@ rules: - tlsstores - traefikservices - serverstransports - {{- if semverCompare ">=3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }} + {{- if (include "isV3" .) }} - serverstransporttcps {{- end }} verbs: diff --git a/traefik/templates/rbac/role.yaml b/traefik/templates/rbac/role.yaml index be0f90f71..bd13e3387 100644 --- a/traefik/templates/rbac/role.yaml +++ b/traefik/templates/rbac/role.yaml @@ -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 (include "isV2" .) }} - traefik.containo.us {{- end }} resources: @@ -57,7 +57,7 @@ rules: - tlsstores - traefikservices - serverstransports - {{- if semverCompare ">=3.0.0-0" (default $.Chart.AppVersion $.Values.image.tag) }} + {{- if (include "isV3" .) }} - serverstransporttcps {{- end }} verbs: From d67704f378eefb202a755c55ddb7a111ccfef952 Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 11:40:29 +0700 Subject: [PATCH 02/10] missing brackets --- traefik/templates/_helpers.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/traefik/templates/_helpers.tpl b/traefik/templates/_helpers.tpl index f54e4c813..064427e54 100644 --- a/traefik/templates/_helpers.tpl +++ b/traefik/templates/_helpers.tpl @@ -130,10 +130,10 @@ Renders a complete tree, even values that contains template. {{- end -}} {{- define "isV3" -}} -semverCompare ">=3.0.0-0" (include "imageVersion" .) +{{ semverCompare ">=3.0.0-0" (include "imageVersion" .) }} {{- end -}} {{- define "isV2" -}} -semverCompare "<3.0.0-0" (include "imageVersion" .) +{{ semverCompare "<3.0.0-0" (include "imageVersion" .) }} {{- end -}} From 1ba2200960d87a58b4f861e041ec9cd47920cfa3 Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 11:45:31 +0700 Subject: [PATCH 03/10] try different syntax --- traefik/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traefik/templates/_helpers.tpl b/traefik/templates/_helpers.tpl index 064427e54..51143c2b2 100644 --- a/traefik/templates/_helpers.tpl +++ b/traefik/templates/_helpers.tpl @@ -126,7 +126,7 @@ Renders a complete tree, even values that contains template. {{- end -}} {{- define "imageVersion" -}} -{{ default $.Chart.AppVersion $.Values.image.tag | split "@" | mustFirst }} +{{ (split (default $.Chart.AppVersion $.Values.image.tag) "@")._0 }} {{- end -}} {{- define "isV3" -}} From cf967bff4228a75010bd4c2b882afe3ea9e957d8 Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 11:49:50 +0700 Subject: [PATCH 04/10] and obviously args needs to be in right order --- traefik/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traefik/templates/_helpers.tpl b/traefik/templates/_helpers.tpl index 51143c2b2..69ff07adb 100644 --- a/traefik/templates/_helpers.tpl +++ b/traefik/templates/_helpers.tpl @@ -126,7 +126,7 @@ Renders a complete tree, even values that contains template. {{- end -}} {{- define "imageVersion" -}} -{{ (split (default $.Chart.AppVersion $.Values.image.tag) "@")._0 }} +{{ (split "@" (default $.Chart.AppVersion $.Values.image.tag))._0 }} {{- end -}} {{- define "isV3" -}} From ae15a4f550ae15ffa43bbd93891815982533da8a Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 11:51:36 +0700 Subject: [PATCH 05/10] this work? --- traefik/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traefik/templates/_helpers.tpl b/traefik/templates/_helpers.tpl index 69ff07adb..44b8fb86b 100644 --- a/traefik/templates/_helpers.tpl +++ b/traefik/templates/_helpers.tpl @@ -126,7 +126,7 @@ Renders a complete tree, even values that contains template. {{- end -}} {{- define "imageVersion" -}} -{{ (split "@" (default $.Chart.AppVersion $.Values.image.tag))._0 }} +{{ (split "@" (default .Chart.AppVersion .Values.image.tag))._0 }} {{- end -}} {{- define "isV3" -}} From 0b4f193acc18d88e300a941d298e1256f2b7922c Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 12:00:16 +0700 Subject: [PATCH 06/10] guess if and define doesnt work well together --- traefik/templates/_helpers.tpl | 10 +--------- traefik/templates/_podtemplate.tpl | 10 +++++----- traefik/templates/ingressclass.yaml | 2 +- traefik/templates/rbac/clusterrole.yaml | 4 ++-- traefik/templates/rbac/role.yaml | 4 ++-- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/traefik/templates/_helpers.tpl b/traefik/templates/_helpers.tpl index 44b8fb86b..0459333bf 100644 --- a/traefik/templates/_helpers.tpl +++ b/traefik/templates/_helpers.tpl @@ -126,14 +126,6 @@ Renders a complete tree, even values that contains template. {{- end -}} {{- define "imageVersion" -}} -{{ (split "@" (default .Chart.AppVersion .Values.image.tag))._0 }} -{{- end -}} - -{{- define "isV3" -}} -{{ semverCompare ">=3.0.0-0" (include "imageVersion" .) }} -{{- end -}} - -{{- define "isV2" -}} -{{ semverCompare "<3.0.0-0" (include "imageVersion" .) }} +{{ (split "@" (default $.Chart.AppVersion $.Values.image.tag))._0 }} {{- end -}} diff --git a/traefik/templates/_podtemplate.tpl b/traefik/templates/_podtemplate.tpl index b05f4932d..433bc3526 100644 --- a/traefik/templates/_podtemplate.tpl +++ b/traefik/templates/_podtemplate.tpl @@ -142,7 +142,7 @@ {{- if $config }} - "--entrypoints.{{$name}}.address=:{{ $config.port }}/{{ default "tcp" $config.protocol | lower }}" {{- with $config.asDefault }} - {{- if (include "isV2" .) }} + {{- 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={{ . }}" @@ -298,7 +298,7 @@ {{- end }} {{- with .Values.metrics.openTelemetry }} - {{- if (include "isV2" .) }} + {{- 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" @@ -357,7 +357,7 @@ {{- if .Values.tracing }} {{- if .Values.tracing.openTelemetry }} - {{- if (include "isV2" .) }} + {{- 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" @@ -591,10 +591,10 @@ {{- end }} {{- if $config.http3 }} {{- if $config.http3.enabled }} - {{- if (include "isV2" .)}} + {{- 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" (tpl "imageVersion" .)}} - "--entrypoints.{{ $entrypoint }}.http3" {{- else }} - "--entrypoints.{{ $entrypoint }}.enableHTTP3=true" diff --git a/traefik/templates/ingressclass.yaml b/traefik/templates/ingressclass.yaml index 364e1dacf..964624503 100644 --- a/traefik/templates/ingressclass.yaml +++ b/traefik/templates/ingressclass.yaml @@ -1,5 +1,5 @@ {{- if .Values.ingressClass.enabled -}} - {{- if (semverCompare "<2.3.0" (.Chart.AppVersion)) -}} + {{- if (semverCompare "<2.3.0" (tpl "imageVersion" .)) -}} {{- fail "ERROR: IngressClass cannot be used with Traefik < 2.3.0" -}} {{- end -}} {{- if semverCompare ">=1.19.0-0" .Capabilities.KubeVersion.Version -}} diff --git a/traefik/templates/rbac/clusterrole.yaml b/traefik/templates/rbac/clusterrole.yaml index 2d8af2a16..48ac64ee1 100644 --- a/traefik/templates/rbac/clusterrole.yaml +++ b/traefik/templates/rbac/clusterrole.yaml @@ -45,7 +45,7 @@ rules: {{- if .Values.providers.kubernetesCRD.enabled }} - apiGroups: - traefik.io - {{- if (include "isV2" .) }} + {{- if semverCompare "<3.0.0-0" (include "imageVersion" .) }} - traefik.containo.us {{- end }} resources: @@ -58,7 +58,7 @@ rules: - tlsstores - traefikservices - serverstransports - {{- if (include "isV3" .) }} + {{- if semverCompare ">=3.0.0-0" (include "imageVersion" .) }} - serverstransporttcps {{- end }} verbs: diff --git a/traefik/templates/rbac/role.yaml b/traefik/templates/rbac/role.yaml index bd13e3387..90f6d99e6 100644 --- a/traefik/templates/rbac/role.yaml +++ b/traefik/templates/rbac/role.yaml @@ -44,7 +44,7 @@ rules: {{- if (and (has . $CRDNamespaces) $.Values.providers.kubernetesCRD.enabled) }} - apiGroups: - traefik.io - {{- if (include "isV2" .) }} + {{- if semverCompare "<3.0.0-0" (include "imageVersion" .) }} - traefik.containo.us {{- end }} resources: @@ -57,7 +57,7 @@ rules: - tlsstores - traefikservices - serverstransports - {{- if (include "isV3" .) }} + {{- if semverCompare ">=3.0.0-0" (include "imageVersion" .) }} - serverstransporttcps {{- end }} verbs: From 05577efdb3c8175d93661e3ce2fb6423e7b5edea Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 12:04:10 +0700 Subject: [PATCH 07/10] inside a with statement, need to use proper context --- traefik/templates/_podtemplate.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traefik/templates/_podtemplate.tpl b/traefik/templates/_podtemplate.tpl index 433bc3526..70a70dacf 100644 --- a/traefik/templates/_podtemplate.tpl +++ b/traefik/templates/_podtemplate.tpl @@ -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" (include "imageVersion" .) }} + {{- 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={{ . }}" From 7b5b0dcbdf112aec9f77e51c1e8d266234caa18b Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 12:09:39 +0700 Subject: [PATCH 08/10] always use root context for this --- traefik/templates/_podtemplate.tpl | 6 +++--- traefik/templates/rbac/clusterrole.yaml | 4 ++-- traefik/templates/rbac/role.yaml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/traefik/templates/_podtemplate.tpl b/traefik/templates/_podtemplate.tpl index 70a70dacf..ef96dfc42 100644 --- a/traefik/templates/_podtemplate.tpl +++ b/traefik/templates/_podtemplate.tpl @@ -298,7 +298,7 @@ {{- end }} {{- with .Values.metrics.openTelemetry }} - {{- if semverCompare "<3.0.0-0" (include "imageVersion" .) }} + {{- 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" @@ -357,7 +357,7 @@ {{- if .Values.tracing }} {{- if .Values.tracing.openTelemetry }} - {{- if semverCompare "<3.0.0-0" (include "imageVersion" .) }} + {{- 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" @@ -591,7 +591,7 @@ {{- end }} {{- if $config.http3 }} {{- if $config.http3.enabled }} - {{- if semverCompare "<3.0.0-0" (include "imageVersion" .)}} + {{- if semverCompare "<3.0.0-0" (include "imageVersion" $)}} - "--experimental.http3=true" {{- end }} {{- if semverCompare ">=2.6.0-0" (tpl "imageVersion" .)}} diff --git a/traefik/templates/rbac/clusterrole.yaml b/traefik/templates/rbac/clusterrole.yaml index 48ac64ee1..f15ce5923 100644 --- a/traefik/templates/rbac/clusterrole.yaml +++ b/traefik/templates/rbac/clusterrole.yaml @@ -45,7 +45,7 @@ rules: {{- if .Values.providers.kubernetesCRD.enabled }} - apiGroups: - traefik.io - {{- if semverCompare "<3.0.0-0" (include "imageVersion" .) }} + {{- if semverCompare "<3.0.0-0" (include "imageVersion" $) }} - traefik.containo.us {{- end }} resources: @@ -58,7 +58,7 @@ rules: - tlsstores - traefikservices - serverstransports - {{- if semverCompare ">=3.0.0-0" (include "imageVersion" .) }} + {{- if semverCompare ">=3.0.0-0" (include "imageVersion" $) }} - serverstransporttcps {{- end }} verbs: diff --git a/traefik/templates/rbac/role.yaml b/traefik/templates/rbac/role.yaml index 90f6d99e6..35589ecc5 100644 --- a/traefik/templates/rbac/role.yaml +++ b/traefik/templates/rbac/role.yaml @@ -44,7 +44,7 @@ rules: {{- if (and (has . $CRDNamespaces) $.Values.providers.kubernetesCRD.enabled) }} - apiGroups: - traefik.io - {{- if semverCompare "<3.0.0-0" (include "imageVersion" .) }} + {{- if semverCompare "<3.0.0-0" (include "imageVersion" $) }} - traefik.containo.us {{- end }} resources: @@ -57,7 +57,7 @@ rules: - tlsstores - traefikservices - serverstransports - {{- if semverCompare ">=3.0.0-0" (include "imageVersion" .) }} + {{- if semverCompare ">=3.0.0-0" (include "imageVersion" $) }} - serverstransporttcps {{- end }} verbs: From a7719b1821699b9bf1c01efb9d99a267ba2d06a4 Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 12:12:02 +0700 Subject: [PATCH 09/10] missed a few places --- traefik/templates/_podtemplate.tpl | 2 +- traefik/templates/ingressclass.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/traefik/templates/_podtemplate.tpl b/traefik/templates/_podtemplate.tpl index ef96dfc42..8b1f81c05 100644 --- a/traefik/templates/_podtemplate.tpl +++ b/traefik/templates/_podtemplate.tpl @@ -594,7 +594,7 @@ {{- if semverCompare "<3.0.0-0" (include "imageVersion" $)}} - "--experimental.http3=true" {{- end }} - {{- if semverCompare ">=2.6.0-0" (tpl "imageVersion" .)}} + {{- if semverCompare ">=2.6.0-0" (include "imageVersion" $)}} - "--entrypoints.{{ $entrypoint }}.http3" {{- else }} - "--entrypoints.{{ $entrypoint }}.enableHTTP3=true" diff --git a/traefik/templates/ingressclass.yaml b/traefik/templates/ingressclass.yaml index 964624503..2c207c6d2 100644 --- a/traefik/templates/ingressclass.yaml +++ b/traefik/templates/ingressclass.yaml @@ -1,5 +1,5 @@ {{- if .Values.ingressClass.enabled -}} - {{- if (semverCompare "<2.3.0" (tpl "imageVersion" .)) -}} + {{- 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 -}} From 182a0ab7d6e2e79693089a6021e114f03964aa1e Mon Sep 17 00:00:00 2001 From: Dennis Haney Date: Sun, 13 Aug 2023 12:18:28 +0700 Subject: [PATCH 10/10] add unittest for this bug fix --- traefik/tests/tracing-config_test.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/traefik/tests/tracing-config_test.yaml b/traefik/tests/tracing-config_test.yaml index df6804c2c..cb1fc79c6 100644 --- a/traefik/tests/tracing-config_test.yaml +++ b/traefik/tests/tracing-config_test.yaml @@ -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: @@ -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`."