Skip to content
Snippets Groups Projects
Commit 9cf2fc1e authored by Steffen Vogel's avatar Steffen Vogel
Browse files

support additional environment variables in hub deployment

parent fbd7e4a2
Branches
Tags
No related merge requests found
......@@ -866,6 +866,38 @@ properties:
description: |
Deprecated and no longer does anything. Use the user-scheduler instead
in order to accomplish a good packing of the user pods.
extraEnv:
type: object
description: |
Extra environment variables that should be set for the user pods.
String literals with `$(ENV_VAR_NAME)` will be expanded by Kubelet which
is a part of Kubernetes. Note that the user pods will already have
access to a set of environment variables that you can use, like
`JUPYTERHUB_USER` and `JUPYTERHUB_HOST`. For more information about these
inspect [this source
code](https://github.com/jupyterhub/jupyterhub/blob/cc8e7806530466dce8968567d1bbd2b39a7afa26/jupyterhub/spawner.py#L763).
```yaml
singleuser:
extraEnv:
# basic notation (for literal values only)
MY_ENV_VARS_NAME1: "my env var value 1"
# explicit notation (the "name" field takes precedence)
USER_NAMESPACE:
name: USER_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# implicit notation (the "name" field is implied)
PREFIXED_USER_NAMESPACE:
value: "my-prefix-$(USER_NAMESPACE)"
SECRET_VALUE:
valueFrom:
secretKeyRef:
name: my-k8s-secret
key: password
```
For more information, see the [Kubernetes EnvVar
specification](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#envvar-v1-core).
extraTolerations:
type: list
description: |
......
......@@ -267,3 +267,42 @@ limits:
{{- end }}
{{- end }}
{{- end }}
{{- /*
jupyterhub.extraEnv:
Output YAML formatted EnvVar entries for use in a containers env field.
*/}}
{{- define "jupyterhub.extraEnv" -}}
{{- include "jupyterhub.extraEnv.withTrailingNewLine" . | trimSuffix "\n" }}
{{- end }}
{{- define "jupyterhub.extraEnv.withTrailingNewLine" -}}
{{- if . }}
{{- /* If extraEnv is a list, we inject it as it is. */}}
{{- if eq (typeOf .) "[]interface {}" }}
{{- . | toYaml }}
{{- /* If extraEnv is a map, we differentiate two cases: */}}
{{- else if eq (typeOf .) "map[string]interface {}" }}
{{- range $key, $value := . }}
{{- /*
- If extraEnv.someKey has a map value, then we add the value as a YAML
parsed list element and use the key as the name value unless its
explicitly set.
*/}}
{{- if eq (typeOf $value) "map[string]interface {}" }}
{{- merge (dict) $value (dict "name" $key) | list | toYaml | println }}
{{- /*
- If extraEnv.someKey has a string value, then we use the key as the
environment variable name for the value.
*/}}
{{- else if eq (typeOf $value) "string" -}}
- name: {{ $key | quote }}
value: {{ $value | quote | println }}
{{- else }}
{{- printf "?.extraEnv.%s had an unexpected type (%s)" $key (typeOf $value) | fail }}
{{- end }}
{{- end }} {{- /* end of range */}}
{{- end }}
{{- end }} {{- /* end of: if . */}}
{{- end }} {{- /* end of definition */}}
......@@ -202,19 +202,7 @@ spec:
key: hub.db.password
{{- end }}
{{- end }}
{{- if .Values.hub.extraEnv }}
{{- $extraEnvType := typeOf .Values.hub.extraEnv }}
{{- /* If we have a list, embed that here directly. This allows for complex configuration from configmap, downward API, etc. */}}
{{- if eq $extraEnvType "[]interface {}" }}
{{- .Values.hub.extraEnv | toYaml | trimSuffix "\n" | nindent 12 }}
{{- else if eq $extraEnvType "map[string]interface {}" }}
{{- /* If we have a map, treat those as key-value pairs. */}}
{{- range $key, $value := .Values.hub.extraEnv }}
- name: {{ $key | quote }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- include "jupyterhub.extraEnv" .Values.hub.extraEnv | nindent 12 }}
ports:
- containerPort: 8081
name: hub
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment