Skip to content

Commit

Permalink
Set scratch bucket env vars only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed May 6, 2021
1 parent 1b1d422 commit 00ee5f4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,4 @@ spec:
apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
kind: Project
external: projects/{{ .Values.jupyterhub.cloudResources.gcp.projectId }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
iam.gke.io/gcp-service-account: {{ include "cloudResources.gcp.serviceAccountName" .}}@{{ .Values.jupyterhub.cloudResources.gcp.projectId }}.iam.gserviceaccount.com
name: user-sa
{{- end }}
10 changes: 10 additions & 0 deletions hub-templates/basehub/templates/user-sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
{{ if .Values.jupyterhub.cloudResources.scratchBucket.enabled}}
{{ if eq .Values.jupyterhub.cloudResources.provider "gcp" }}
iam.gke.io/gcp-service-account: {{ include "cloudResources.gcp.serviceAccountName" .}}@{{ .Values.jupyterhub.cloudResources.gcp.projectId }}.iam.gserviceaccount.com
{{- end }}
{{- end }}
name: user-sa
47 changes: 23 additions & 24 deletions hub-templates/daskhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,6 @@ basehub:
# The default worker image matches the singleuser image.
DASK_GATEWAY__CLUSTER__OPTIONS__IMAGE: '{JUPYTER_IMAGE_SPEC}'

# FIXME: Only set these if scratchBucket.enabled is true
# Explicitly order environment variables that depend on each
# other, since a environment variable needs to be defined first
# before they can be interpolated.
# See https://github.com/jupyterhub/kubespawner/issues/491
daskhub-01-scratch-bucket-protocol:
name: SCRATCH_BUCKET_PROTOCOL
valueFrom:
configMapKeyRef:
name: cloud-env-vars
key: scratch-bucket-protocol
daskhub-02-scratch-bucket-name:
name: SCRATCH_BUCKET_NAME
valueFrom:
configMapKeyRef:
name: cloud-env-vars
key: scratch-bucket-name
daskhub-03-scratch-bucket:
name: SCRATCH_BUCKET
value: $(SCRATCH_BUCKET_PROTOCOL)://$(SCRATCH_BUCKET_NAME)/$(JUPYTERHUB_USER)
daskhub-04-pangeo-scratch:
name: PANGEO_SCRATCH
value: $(SCRATCH_BUCKET)

hub:
networkPolicy:
enabled: false
Expand Down Expand Up @@ -116,6 +92,29 @@ basehub:
break
else:
print("dask-gateway service not found. Did you set jupyterhub.hub.services.dask-gateway.apiToken?")
daskhub-02-cloud-storage-bucket: |
from z2jh import get_config
cloud_resources = get_config('cloudResources')
scratch_bucket = cloud_resources['scratchBucket']
import os
if scratch_bucket['enabled']:
# FIXME: Support other providers too
assert cloud_resources['provider'] == 'gcp'
project_id = cloud_resources['gcp']['projectId']
release = os.environ['HELM_RELEASE_NAME']
bucket_protocol = 'gcs'
bucket_name = f'{project_id}-{release}-scratch-bucket'
env = {
'SCRATCH_BUCKET_PROTOCOL': bucket_protocol,
# Matches "daskhub.scratchBUcket.name" helm template
'SCRATCH_BUCKET_NAME': bucket_name,
'SCRATCH_BUCKET': f'{bucket_protocol}://{bucket_name}',
'PANGEO_SCRATCH': f'{bucket_protocol}://{bucket_name}',
}
c.KubeSpawner.environment.update(env)
dask-gateway:
enabled: true # Enabling dask-gateway will install Dask Gateway as a dependency.
Expand Down

0 comments on commit 00ee5f4

Please sign in to comment.