Skip to content

Commit

Permalink
feat(worker): support env vars from multiple ConfigMaps, Secrets (#422)
Browse files Browse the repository at this point in the history
* Add extraEnvVarsCMs for multiple ConfigMaps

Adds support for definining multiple ConfigMaps in the Worker
Deployment.

Related to #421

* Add extraEnvVarsSecrets for multiple Secrets

Adds support for defining multiple Secrets in the Worker Deployment.

Related to #421
  • Loading branch information
mitchnielsen authored Jan 9, 2025
1 parent 1f49164 commit 5df23fe
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
6 changes: 4 additions & 2 deletions charts/prefect-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,10 @@ worker:
| worker.extraArgs | list | `[]` | array with extra Arguments for the worker container to start with |
| worker.extraContainers | list | `[]` | additional sidecar containers |
| worker.extraEnvVars | list | `[]` | array with extra environment variables to add to worker nodes |
| worker.extraEnvVarsCM | string | `""` | name of existing ConfigMap containing extra env vars to add to worker nodes |
| worker.extraEnvVarsSecret | string | `""` | name of existing Secret containing extra env vars to add to worker nodes |
| worker.extraEnvVarsCM | string | `""` | name of existing ConfigMap containing extra env vars to add to worker nodes (deprecated, use extraEnvVarsCMs) |
| worker.extraEnvVarsCMs | list | `[]` | names of existing ConfigMaps containing extra env vars to add to worker nodes |
| worker.extraEnvVarsSecret | string | `""` | name of existing Secret containing extra env vars to add to worker nodes (deprecated, use extraEnvVarsSecrets) |
| worker.extraEnvVarsSecrets | list | `[]` | names of existing Secrets containing extra env vars to add to worker nodes |
| worker.extraVolumeMounts | list | `[]` | array with extra volumeMounts for the worker pod |
| worker.extraVolumes | list | `[]` | array with extra volumes for the worker pod |
| worker.image.debug | bool | `false` | enable worker image debug mode |
Expand Down
8 changes: 8 additions & 0 deletions charts/prefect-worker/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,18 @@ spec:
- configMapRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.worker.extraEnvVarsCM "context" $) }}
{{- end }}
{{- range .Values.worker.extraEnvVarsCMs }}
- configMapRef:
name: {{ include "common.tplvalues.render" (dict "value" . "context" $) }}
{{- end }}
{{- if .Values.worker.extraEnvVarsSecret }}
- secretRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.worker.extraEnvVarsSecret "context" $) }}
{{- end }}
{{- range .Values.worker.extraEnvVarsSecrets }}
- secretRef:
name: {{ include "common.tplvalues.render" (dict "value" . "context" $) }}
{{- end }}
{{- if .Values.worker.resources }}
resources: {{- toYaml .Values.worker.resources | nindent 12 }}
{{- end }}
Expand Down
52 changes: 52 additions & 0 deletions charts/prefect-worker/tests/worker_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,58 @@ tests:
path: .spec.template.spec.containers[0].envFrom[0].configMapRef.name
value: my-config-map

- it: Should set extra environment variables from ConfigMaps
set:
worker:
extraEnvVarsCMs:
- my-config-map
- my-other-config-map
asserts:
- template: deployment.yaml
contains:
path: .spec.template.spec.containers[0].envFrom
content:
configMapRef:
name: my-config-map
- template: deployment.yaml
contains:
path: .spec.template.spec.containers[0].envFrom
content:
configMapRef:
name: my-other-config-map

- it: Should set extra environment variables from Secret
set:
worker:
extraEnvVarsSecret: my-secret
asserts:
- template: deployment.yaml
contains:
path: .spec.template.spec.containers[0].envFrom
content:
secretRef:
name: my-secret

- it: Should set extra environment variables from Secrets
set:
worker:
extraEnvVarsSecrets:
- my-secret
- my-other-secret
asserts:
- template: deployment.yaml
contains:
path: .spec.template.spec.containers[0].envFrom
content:
secretRef:
name: my-secret
- template: deployment.yaml
contains:
path: .spec.template.spec.containers[0].envFrom
content:
secretRef:
name: my-other-secret

- it: Should set extra volumes
set:
worker:
Expand Down
14 changes: 12 additions & 2 deletions charts/prefect-worker/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,22 @@
"extraEnvVarsCM": {
"type": "string",
"title": "Extra Env Vars ConfigMap",
"description": "name of existing ConfigMap containing extra env vars to add to worker nodes"
"description": "name of existing ConfigMap containing extra env vars to add to worker nodes (deprecated, use extraEnvVarsCMs)"
},
"extraEnvVarsCMs": {
"type": "array",
"title": "Extra Env Vars ConfigMaps",
"description": "names of existing ConfigMaps containing extra env vars to add to worker nodes"
},
"extraEnvVarsSecret": {
"type": "string",
"title": "Extra Env Vars Secret",
"description": "name of existing Secret containing extra env vars to add to worker nodes"
"description": "name of existing Secret containing extra env vars to add to worker nodes (deprecated, use extraEnvVarsSecrets)"
},
"extraEnvVarsSecrets": {
"type": "array",
"title": "Extra Env Vars Secrets",
"description": "names of existing Secrets containing extra env vars to add to worker nodes"
},
"extraContainers": {
"type": "array",
Expand Down
10 changes: 8 additions & 2 deletions charts/prefect-worker/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,18 @@ worker:
# -- array with extra environment variables to add to worker nodes
extraEnvVars: []

# -- name of existing ConfigMap containing extra env vars to add to worker nodes
# -- name of existing ConfigMap containing extra env vars to add to worker nodes (deprecated, use extraEnvVarsCMs)
extraEnvVarsCM: ""

# -- name of existing Secret containing extra env vars to add to worker nodes
# -- names of existing ConfigMaps containing extra env vars to add to worker nodes
extraEnvVarsCMs: []

# -- name of existing Secret containing extra env vars to add to worker nodes (deprecated, use extraEnvVarsSecrets)
extraEnvVarsSecret: ""

# -- names of existing Secrets containing extra env vars to add to worker nodes
extraEnvVarsSecrets: []

# -- additional sidecar containers
extraContainers: []

Expand Down

0 comments on commit 5df23fe

Please sign in to comment.