Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to delete attached PVC #699

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/k8sTypes.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ type ImageStreamSpecTagAnnotations = Partial<{
}>;

export type NotebookAnnotations = Partial<{
'kubeflow-resource-stopped': string | null; // datestamp of stop (if omitted, it is running)
'kubeflow-resource-stopped': string | null; // datestamp of stop (if omitted, it is running), `odh-notebook-controller-lock` is set when first creating the notebook to avoid race conditions, it's a fake stop
'notebooks.kubeflow.org/last-activity': string; // datestamp of last use
'opendatahub.io/link': string; // redirect notebook url
'opendatahub.io/username': string; // the untranslated username behind the notebook
1 change: 0 additions & 1 deletion frontend/src/pages/projects/const.ts

This file was deleted.

6 changes: 2 additions & 4 deletions frontend/src/pages/projects/notebook/utils.ts
Original file line number Diff line number Diff line change
@@ -4,10 +4,8 @@ import { useWatchNotebookEvents } from './useWatchNotebookEvents';

export const hasStopAnnotation = (notebook: NotebookKind): boolean => {
return !!(
(
notebook.metadata.annotations?.['kubeflow-resource-stopped'] &&
notebook.metadata.annotations['kubeflow-resource-stopped'] !== 'odh-notebook-controller-lock'
) // 'odh-notebook-controller-lock' is set when first creating the notebook to avoid race conditions, it's a fake stop
notebook.metadata.annotations?.['kubeflow-resource-stopped'] &&
notebook.metadata.annotations['kubeflow-resource-stopped'] !== 'odh-notebook-controller-lock'
);
};

43 changes: 36 additions & 7 deletions frontend/src/pages/projects/pvc/DeletePVCModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { Alert, Button, Modal, Stack, StackItem } from '@patternfly/react-core';
import { getPvcDisplayName } from '../utils';
import { getNotebookDisplayName, getPvcDisplayName } from '../utils';
import { PersistentVolumeClaimKind } from '../../../k8sTypes';
import { deletePvc } from '../../../api';
import { deletePvc, removeNotebookPVC } from '../../../api';
import useRelatedNotebooks, { ConnectedNotebookContext } from '../notebook/useRelatedNotebooks';

type DeletePVCModalProps = {
pvcToDelete?: PersistentVolumeClaimKind;
@@ -12,6 +13,11 @@ type DeletePVCModalProps = {
const DeletePVCModal: React.FC<DeletePVCModalProps> = ({ pvcToDelete, onClose }) => {
const [isDeleting, setIsDeleting] = React.useState(false);
const [error, setError] = React.useState<Error | undefined>();
const {
connectedNotebooks,
loaded: notebookLoaded,
error: notebookError,
} = useRelatedNotebooks(ConnectedNotebookContext.PVC, pvcToDelete?.metadata.name);

const onBeforeClose = (deleted: boolean) => {
onClose(deleted);
@@ -33,12 +39,17 @@ const DeletePVCModal: React.FC<DeletePVCModalProps> = ({ pvcToDelete, onClose })
onClick={() => {
if (pvcToDelete) {
const { name, namespace } = pvcToDelete.metadata;

setIsDeleting(true);
deletePvc(name, namespace)
.then(() => {
onBeforeClose(true);
})
Promise.all(
connectedNotebooks.map((notebook) =>
removeNotebookPVC(notebook.metadata.name, namespace, name),
),
)
.then(() =>
deletePvc(name, namespace).then(() => {
onBeforeClose(true);
}),
)
.catch((e) => {
setError(e);
setIsDeleting(false);
@@ -54,6 +65,24 @@ const DeletePVCModal: React.FC<DeletePVCModalProps> = ({ pvcToDelete, onClose })
]}
>
<Stack hasGutter>
{notebookLoaded && !notebookError && connectedNotebooks.length !== 0 && (
<StackItem>
<Alert
variant="warning"
isInline
title={
<>
This storage is connected to{' '}
{connectedNotebooks
.map((notebook) => getNotebookDisplayName(notebook))
.join(', ')}
</>
}
>
Delete this storage could lead to the restart of the workbenches it connects to.
</Alert>
</StackItem>
)}
<StackItem>
Are you sure you want to delete{' '}
{pvcToDelete ? (
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { AppContext } from '../../../../../app/AppContext';
import { DEFAULT_PVC_SIZE } from '../../../const';

const DEFAULT_PVC_SIZE = 20;

const useDefaultPvcSize = (): number => {
const {
Original file line number Diff line number Diff line change
@@ -17,11 +17,9 @@ const useAvailablePvcs = (
if (projectName) {
getPvcs(projectName)
.then((newPvcs) => {
let usedPvcs: string[] = [];
notebooks.forEach((notebook) => {
const pvcNames = getNotebookPVCNames(notebook.notebook);
usedPvcs = _.union(usedPvcs, pvcNames);
});
const usedPvcs = _.uniq(
notebooks.flatMap((notebook) => getNotebookPVCNames(notebook.notebook)),
);
setPvcs(newPvcs.filter((pvc) => !usedPvcs.includes(pvc.metadata.name)));
setLoaded(true);
})