From a34aa776b566b38bb2d8cd95dc8708e4976109c9 Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Sun, 12 May 2019 12:01:53 -0700 Subject: [PATCH 1/2] w261: Create GCP resources for users When a user pod starts, we ensure the following GCP resources: 1. A GCS bucket 2. A Service Account with admin rights on the bucket 3. A Service Account Key for the Service Account We then populate two environment variables in the spawned pod 1. SPARK_GCS_BUCKET - name of GCS bucket for this user 2. SPARK_GCS_KEY - JSON Private key for service account This is all done through a custom Spawner that inherits from KubeSpawner. This should operate at the level of a 'Spark+GCS on GCP', so nothing too UCB specific. In addition, there's a custom role created in the ucb-datahub-2018 project - projects/ucb-datahub-2018/roles/w261_hub_resource_creator that has the appropriate permissions needed by the *hub* to create the resources it needs. --- deployments/w261/config/common.yaml | 11 ++ deployments/w261/secrets/staging.yaml | Bin 524 -> 3061 bytes images/hub/Dockerfile | 17 +++ images/hub/sparklyspawner/setup.py | 13 ++ .../sparklyspawner/sparklyspawner/__init__.py | 124 ++++++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 images/hub/sparklyspawner/setup.py create mode 100644 images/hub/sparklyspawner/sparklyspawner/__init__.py diff --git a/deployments/w261/config/common.yaml b/deployments/w261/config/common.yaml index af5bcd694..fcd8037a4 100644 --- a/deployments/w261/config/common.yaml +++ b/deployments/w261/config/common.yaml @@ -1,4 +1,15 @@ jupyterhub: + hub: + extraConfig: + 90-sparklyspawner: | + import z2jh + c.JupyterHub.spawner_class = 'sparklyspawner.SparklySpawner' + + sparkly_config = z2jh.get_config('custom.sparkly', {}) + c.SparklySpawner.gcp_service_key = sparkly_config.get('gcp_service_key', None) + c.SparklySpawner.storage_bucket_template = 'ucb-datahub-2018-w261-test-user-{username}' + c.SparklySpawner.service_account_template = 'w261-s-{username}' + c.SparklySpawner.gcp_project = 'ucb-datahub-2018' auth: type: google admin: diff --git a/deployments/w261/secrets/staging.yaml b/deployments/w261/secrets/staging.yaml index 1d3870a2900cc57b28b99ea18f5f8dba1ffdcc96..3718f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aml | 2 +- hub/values.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hub/Chart.yaml b/hub/Chart.yaml index 2b081ba58..3c328fba1 100644 --- a/hub/Chart.yaml +++ b/hub/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v1 appVersion: '1.0' description: Deployment Chart for JupyterHub name: hub -version: 0.1.0-facec6f +version: 0.1.0-a34aa77 diff --git a/hub/values.yaml b/hub/values.yaml index 530beb026..292330843 100644 --- a/hub/values.yaml +++ b/hub/values.yaml @@ -35,7 +35,7 @@ jupyterhub: # Generated by chartpress image: name: gcr.io/ucb-datahub-2018/jupyterhub-hub - tag: '0.1.0-401ee46' + tag: '0.1.0-a34aa77' networkPolicy: enabled: true extraConfig: @@ -47,7 +47,7 @@ jupyterhub: hosted_domain = 'berkeley.edu' course_profile_tmpl = '/srv/jupyterhub/profiles.d/{}-{}.txt' - + def memparse(val): '''Parse memory for relative comparisons.''' if type(val) != str or len(val) == 0: return val @@ -55,7 +55,7 @@ jupyterhub: unit = val[-1] n = {'B':0, 'K':1, 'M':2, 'G':3}[unit] return mem * 1024**n - + def mem_cmp(a, b): '''Compare memory values.''' x = memparse(a) ; y = memparse(b)