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

feat: add file provider #937

Merged
merged 8 commits into from
Nov 7, 2023
Merged
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
17 changes: 17 additions & 0 deletions traefik/templates/_podtemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
- name: plugins
mountPath: "/plugins-storage"
{{- end }}
{{- if .Values.providers.file.enabled }}
- name: traefik-extra-config
mountPath: "/etc/traefik/dynamic"
{{- end }}
{{- if .Values.additionalVolumeMounts }}
{{- toYaml .Values.additionalVolumeMounts | nindent 10 }}
{{- end }}
Expand Down Expand Up @@ -564,6 +568,14 @@
- "--providers.kubernetesingress.namespaces={{ template "providers.kubernetesIngress.namespaces" $ }}"
{{- end }}
{{- end }}
{{- with .Values.providers.file }}
{{- if .enabled }}
- "--providers.file.directory=/etc/traefik/dynamic"
{{- if .watch }}
- "--providers.file.watch=true"
{{- end }}
{{- end }}
{{- end }}
{{- range $entrypoint, $config := $.Values.ports }}
{{- if $config }}
{{- if $config.redirectTo }}
Expand Down Expand Up @@ -728,6 +740,11 @@
- name: plugins
emptyDir: {}
{{- end }}
{{- if .Values.providers.file.enabled }}
- name: traefik-extra-config
configMap:
name: {{ template "traefik.fullname" . }}-file-provider
{{- end }}
{{- if .Values.affinity }}
affinity:
{{- tpl (toYaml .Values.affinity) . | nindent 8 }}
Expand Down
3 changes: 3 additions & 0 deletions traefik/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- if and .Values.providers.file.enabled (not .Values.providers.file.watch) }}
checksum/traefik-dynamic-conf: {{ include (print $.Template.BasePath "/provider-file-cm.yaml") . | sha256sum }}
{{- end }}
{{- with .Values.deployment.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions traefik/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
{{- if and .Values.providers.file.enabled (not .Values.providers.file.watch) }}
checksum/traefik-dynamic-conf: {{ include (print $.Template.BasePath "/provider-file-cm.yaml") . | sha256sum }}
{{- end }}
{{- with .Values.deployment.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
12 changes: 12 additions & 0 deletions traefik/templates/provider-file-cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.providers.file.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "traefik.fullname" . }}-file-provider
namespace: {{ template "traefik.namespace" . }}
labels:
{{- include "traefik.labels" . | nindent 4 }}
data:
config.yml: |
{{ .Values.providers.file.content | nindent 4 }}
{{- end -}}
124 changes: 124 additions & 0 deletions traefik/tests/provider-file_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
suite: File provider
templates:
- provider-file-cm.yaml
- deployment.yaml
- daemonset.yaml
tests:
- it: should create a configMap and a volume
set:
providers:
file:
enabled: true
asserts:
- template: provider-file-cm.yaml
isKind:
of: ConfigMap
- template: provider-file-cm.yaml
equal:
path: metadata.name
value: "RELEASE-NAME-traefik-file-provider"
- template: deployment.yaml
contains:
path: spec.template.spec.volumes
content:
name: traefik-extra-config
configMap:
name: "RELEASE-NAME-traefik-file-provider"
- template: deployment.yaml
contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: traefik-extra-config
mountPath: "/etc/traefik/dynamic"

- it: should add cli options with watch option
set:
providers:
file:
enabled: true
watch: true
asserts:
- template: deployment.yaml
contains:
path: spec.template.spec.containers[0].args
content: "--providers.file.directory=/etc/traefik/dynamic"
- template: deployment.yaml
contains:
path: spec.template.spec.containers[0].args
content: "--providers.file.watch=true"
- template: deployment.yaml
isNull:
path: metadata.annotations["checksum/traefik-dynamic-conf"]

- it: should add checksum annotations and no watch cli option
set:
providers:
file:
enabled: true
watch: false
asserts:
- template: deployment.yaml
contains:
path: spec.template.spec.containers[0].args
content: "--providers.file.directory=/etc/traefik/dynamic"
- template: deployment.yaml
notContains:
path: spec.template.spec.containers[0].args
content: "--providers.file.watch=true"
- template: deployment.yaml
isNotEmpty:
path: metadata.annotations["checksum/traefik-dynamic-conf"]

- it: should add content to configMap
set:
providers:
file:
enabled: true
watch: false
content: &x-providers-file-content |
middlewares:
Middleware00:
addPrefix:
prefix: foobar
asserts:
- template: provider-file-cm.yaml
equal:
path: data["config.yml"]
value: *x-providers-file-content
- template: deployment.yaml
isNotEmpty:
path: metadata.annotations["checksum/traefik-dynamic-conf"]

- it: should add checksum annotations for daemonset
set:
deployment:
kind: DaemonSet
providers:
file:
enabled: true
watch: false
asserts:
- template: daemonset.yaml
isNotEmpty:
path: metadata.annotations["checksum/traefik-dynamic-conf"]

- it: should not provide ConfigMap, add extra volume and extra CLI args by default
asserts:
- template: provider-file-cm.yaml
hasDocuments:
count: 0
- template: deployment.yaml
notContains:
path: spec.template.spec.volumes
content:
name: traefik-extra-config
configMap:
name: "RELEASE-NAME-traefik-file-provider"
- template: deployment.yaml
notContains:
path: spec.template.spec.containers[0].args
content: "--providers.file.directory=/etc/traefik/dynamic"
- template: deployment.yaml
notContains:
path: spec.template.spec.containers[0].args
content: "--providers.file.watch=true"
17 changes: 17 additions & 0 deletions traefik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,23 @@ providers:
# By default this Traefik service
# pathOverride: ""

file:
# -- Create a file provider
enabled: false
# -- Allows Traefik to automatically watch for file changes
watch: true
# -- File content (YAML format, go template supported) (see https://doc.traefik.io/traefik/providers/file/)
content: ""
mloiseleur marked this conversation as resolved.
Show resolved Hide resolved
# http:
# routers:
# router0:
# entryPoints:
# - web
# middlewares:
# - my-basic-auth
# service: service-foo
# rule: Path(`/foo`)

#
# -- Add volumes to the traefik pod. The volume name will be passed to tpl.
# This can be used to mount a cert pair or a configmap that holds a config.toml file.
Expand Down