Skip to content

Commit

Permalink
Restart all connected notebooks when the pvc size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Sep 24, 2024
1 parent 438da63 commit 594b974
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
28 changes: 28 additions & 0 deletions frontend/src/api/k8s/__tests__/notebooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
removeNotebookSecret,
getStopPatch,
startPatch,
restartNotebook,
} from '~/api/k8s/notebooks';

import {
Expand Down Expand Up @@ -955,3 +956,30 @@ describe('removeNotebookSecret', () => {
});
});
});

describe('restartNotebook', () => {
it('should add restart notebook annotation', async () => {
const name = 'test-notebook';
const namespace = 'test-project';
const notebookMock = mockNotebookK8sResource({ uid });

k8sGetResourceMock.mockResolvedValue(notebookMock);
k8sPatchResourceMock.mockResolvedValue(notebookMock);

const renderResult = await restartNotebook(name, namespace);
expect(k8sPatchResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: NotebookModel,
patches: [
{
op: 'add',
path: '/metadata/annotations/notebooks.opendatahub.io~1notebook-restart',
value: 'true',
},
],
queryOptions: { name, ns: namespace, queryParams: {} },
});
expect(k8sPatchResourceMock).toHaveBeenCalledTimes(1);
expect(renderResult).toStrictEqual(notebookMock);
});
});
25 changes: 25 additions & 0 deletions frontend/src/api/k8s/notebooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,28 @@ export const removeNotebookSecret = (
})
.catch(reject);
});

export const restartNotebook = (
notebookName: string,
namespace: string,
opts?: K8sAPIOptions,
): Promise<NotebookKind> => {
const patches: Patch[] = [
{
op: 'add',
path: '/metadata/annotations/notebooks.opendatahub.io~1notebook-restart',
value: 'true',
},
];

return k8sPatchResource<NotebookKind>(
applyK8sAPIOptions(
{
model: NotebookModel,
queryOptions: { name: notebookName, ns: namespace },
patches,
},
opts,
),
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Form, Modal, Stack, StackItem } from '@patternfly/react-core';
import { attachNotebookPVC, createPvc, removeNotebookPVC, updatePvc } from '~/api';
import { attachNotebookPVC, createPvc, removeNotebookPVC, restartNotebook, updatePvc } from '~/api';
import { NotebookKind, PersistentVolumeClaimKind } from '~/k8sTypes';
import { ProjectDetailsContext } from '~/pages/projects/ProjectDetailsContext';
import { useCreateStorageObjectForNotebook } from '~/pages/projects/screens/spawner/storage/utils';
Expand Down Expand Up @@ -98,6 +98,11 @@ const ManageStorageModal: React.FC<AddStorageModalProps> = ({ existingData, isOp
) {
pvcPromises.push(updatePvc(createData, existingData, namespace, { dryRun }));
}
if (existingData.spec.resources.requests.storage !== createData.size) {
connectedNotebooks.map((connectedNotebook) =>
pvcPromises.push(restartNotebook(connectedNotebook.metadata.name, namespace, { dryRun })),
);
}
if (removedNotebooks.length > 0) {
// Remove connected pvcs
pvcPromises.push(
Expand Down

0 comments on commit 594b974

Please sign in to comment.