Skip to content

Commit

Permalink
fix(Env Variables)!: allow extending env without overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mloiseleur authored Oct 11, 2024
1 parent 37f9f12 commit 20f54b6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 67 deletions.
2 changes: 1 addition & 1 deletion traefik/VALUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Kubernetes: `>=1.22.0-0`
| deployment.runtimeClassName | string | `""` | Set a runtimeClassName on pod |
| deployment.shareProcessNamespace | bool | `false` | Use process namespace sharing |
| deployment.terminationGracePeriodSeconds | int | `60` | Amount of time (in seconds) before Kubernetes will send the SIGKILL signal if Traefik does not shut down |
| env | list | See _values.yaml_ | Environment variables to be passed to Traefik's binary |
| env | list | See _values.yaml_ | Additional Environment variables to be passed to Traefik's binary |
| envFrom | list | `[]` | Environment variables to be passed to Traefik's binary from configMaps or secrets |
| experimental.kubernetesGateway.enabled | bool | `false` | Enable traefik experimental GatewayClass CRD |
| experimental.plugins | object | `{}` | Enable traefik experimental plugins |
Expand Down
8 changes: 8 additions & 0 deletions traefik/templates/_podtemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,14 @@
{{- end }}
{{- end }}
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- if ($.Values.resources.limits).cpu }}
- name: GOMAXPROCS
valueFrom:
Expand Down
64 changes: 29 additions & 35 deletions traefik/tests/pod-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,28 @@ tests:
limits:
cpu: "4"
asserts:
- equal:
path: spec.template.spec.containers[0].env[0].name
value: GOMAXPROCS
- equal:
path: spec.template.spec.containers[0].env[0].valueFrom.resourceFieldRef.resource
value: limits.cpu
- equal:
path: spec.template.spec.containers[0].env[0].valueFrom.resourceFieldRef.divisor
value: "1"
- contains:
path: spec.template.spec.containers[0].env
content:
name: GOMAXPROCS
valueFrom:
resourceFieldRef:
resource: limits.cpu
divisor: "1"
- it: should have set GOMEMLIMIT with cpu limit
set:
resources:
limits:
memory: "4"
asserts:
- equal:
path: spec.template.spec.containers[0].env[0].name
value: GOMEMLIMIT
- equal:
path: spec.template.spec.containers[0].env[0].valueFrom.resourceFieldRef.resource
value: limits.memory
- equal:
path: spec.template.spec.containers[0].env[0].valueFrom.resourceFieldRef.divisor
value: "1"
- contains:
path: spec.template.spec.containers[0].env
content:
name: GOMEMLIMIT
valueFrom:
resourceFieldRef:
resource: limits.memory
divisor: "1"
- it: should have not set GOMAXPROCS without cpu limit
asserts:
- notEqual:
Expand All @@ -45,28 +43,24 @@ tests:
- notEqual:
path: spec.template.spec.containers[0].env[0].name
value: GOMEMLIMIT
- it: should have env with specified values
- it: should have expected env + additional env with specified values
set:
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_TEST
value: powpow
asserts:
- equal:
path: spec.template.spec.containers[0].env[0].name
value: POD_NAME
- equal:
path: spec.template.spec.containers[0].env[0].valueFrom.fieldRef.fieldPath
value: metadata.name
- equal:
path: spec.template.spec.containers[0].env[1].name
value: POD_TEST
- equal:
path: spec.template.spec.containers[0].env[1].value
value: powpow
- contains:
path: spec.template.spec.containers[0].env
content:
name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- contains:
path: spec.template.spec.containers[0].env
content:
name: POD_TEST
value: powpow
- it: should have envFrom with specified values
set:
envFrom:
Expand Down
21 changes: 0 additions & 21 deletions traefik/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,6 @@
"type": "object"
},
"env": {
"items": {
"properties": {
"name": {
"type": "string"
},
"valueFrom": {
"properties": {
"fieldRef": {
"properties": {
"fieldPath": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
},
"type": "array"
},
"envFrom": {
Expand Down
12 changes: 2 additions & 10 deletions traefik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -566,17 +566,9 @@ additionalArguments: []
# - "--providers.kubernetesingress.ingressclass=traefik-internal"
# - "--log.level=DEBUG"

# -- Environment variables to be passed to Traefik's binary
# -- Additional Environment variables to be passed to Traefik's binary
# @default -- See _values.yaml_
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
env: []

# -- Environment variables to be passed to Traefik's binary from configMaps or secrets
envFrom: []
Expand Down

0 comments on commit 20f54b6

Please sign in to comment.