From 5142b4d43160f8a60f7d9752e0fd1804e4250f89 Mon Sep 17 00:00:00 2001 From: Andrew Ballantyne Date: Fri, 26 Apr 2024 12:36:59 -0400 Subject: [PATCH] Jupyter tile, merge cert info from old notebook to avoid loss --- backend/src/routes/api/notebooks/utils.ts | 4 ++-- backend/src/utils/notebookUtils.ts | 26 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/backend/src/routes/api/notebooks/utils.ts b/backend/src/routes/api/notebooks/utils.ts index c4de264e86..b3efc2a3fe 100644 --- a/backend/src/routes/api/notebooks/utils.ts +++ b/backend/src/routes/api/notebooks/utils.ts @@ -120,8 +120,8 @@ export const enableNotebook = async ( const url = request.headers.origin; try { - await getNotebook(fastify, notebookNamespace, name); - return await updateNotebook(fastify, username, url, notebookData); + const notebook = await getNotebook(fastify, notebookNamespace, name); + return await updateNotebook(fastify, username, url, notebookData, notebook); } catch (e) { if (e.response?.statusCode === 404) { return await createNotebook(fastify, username, url, notebookData); diff --git a/backend/src/utils/notebookUtils.ts b/backend/src/utils/notebookUtils.ts index ba93cba7aa..adaf935b59 100644 --- a/backend/src/utils/notebookUtils.ts +++ b/backend/src/utils/notebookUtils.ts @@ -1,4 +1,5 @@ import { getDashboardConfig } from './resourceUtils'; +import { merge } from 'lodash'; import { ContainerResourceAttributes, EnvironmentVariable, @@ -510,6 +511,7 @@ export const updateNotebook = async ( username: string, url: string, notebookData: NotebookData, + oldNotebook: Notebook, ): Promise => { if (!notebookData) { const error = createCustomError( @@ -521,7 +523,29 @@ export const updateNotebook = async ( throw error; } try { - const notebookAssembled = await generateNotebookResources(fastify, username, url, notebookData); + const serverNotebook = await generateNotebookResources(fastify, username, url, notebookData); + + // Fix for Workbench Certs that get overridden + // We are intentionally applying on some details as to avoid implementing logic to properly + // manage the notebook the same way as workbench + const importantOldNotebookDetails: RecursivePartial = { + spec: { + template: { + spec: { + containers: [ + { + env: oldNotebook.spec.template.spec.containers[0].env, + volumeMounts: oldNotebook.spec.template.spec.containers[0].volumeMounts, + }, + ], + volumes: oldNotebook.spec.template.spec.volumes, + }, + }, + }, + }; + + const notebookAssembled = merge({}, importantOldNotebookDetails, serverNotebook); + const response = await fastify.kube.customObjectsApi.patchNamespacedCustomObject( 'kubeflow.org', 'v1',