-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes 1871742: It is not possible to delete a PVC created using a dat…
…a upload
- Loading branch information
Gilad Lekner
authored and
Gilad Lekner
committed
Aug 30, 2020
1 parent
5697332
commit aa056df
Showing
7 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...tend/packages/kubevirt-plugin/src/components/cdi-upload-provider/pvc-delete-extension.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as React from 'react'; | ||
import { k8sKill, PersistentVolumeClaimKind } from '@console/internal/module/k8s'; | ||
import { DataVolumeModel } from '../../models'; | ||
import { | ||
useK8sWatchResource, | ||
WatchK8sResource, | ||
} from '@console/internal/components/utils/k8s-watch-hook'; | ||
import { PersistentVolumeClaimModel } from '@console/internal/models'; | ||
import { TEMPLATE_VM_GOLDEN_OS_NAMESPACE } from '../../constants'; | ||
|
||
export const killCDIBoundPVC = (pvc: PersistentVolumeClaimKind) => | ||
k8sKill(DataVolumeModel, { | ||
metadata: { | ||
name: pvc?.metadata?.name, | ||
namespace: pvc?.metadata?.namespace, | ||
}, | ||
}); | ||
|
||
export const PVCDeleteAlertExtension = ({ pvc }) => { | ||
const goldenPvcsResource: WatchK8sResource = { | ||
isList: true, | ||
optional: true, | ||
kind: PersistentVolumeClaimModel.kind, | ||
namespace: TEMPLATE_VM_GOLDEN_OS_NAMESPACE, | ||
}; | ||
const [goldenPvcs, loadedPvcs, errorPvcs] = useK8sWatchResource<PersistentVolumeClaimKind[]>( | ||
goldenPvcsResource, | ||
); | ||
|
||
const isGolden = | ||
pvc?.metadata?.namespace !== TEMPLATE_VM_GOLDEN_OS_NAMESPACE && | ||
goldenPvcs.find((goldenPvc) => goldenPvc?.metadata?.name === pvc?.metadata?.name); | ||
|
||
return ( | ||
<> | ||
<p> | ||
Deleting this PVC will also delete{' '} | ||
<strong className="co-break-word">{pvc?.metadata?.name}</strong> Data Volume | ||
</p> | ||
{!loadedPvcs && <p>Checking for usages of this PVC...</p>} | ||
{errorPvcs && <p>Error checking for usages of this PVC.</p>} | ||
{isGolden && ( | ||
<p> | ||
<strong className="co-break-word">WARNING:</strong> this PVC is used as a base operating | ||
system image. Removing this PVC could cause malfunctions to VMs who use it | ||
</p> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as React from 'react'; | ||
import { Alert, Stack, StackItem } from '@patternfly/react-core'; | ||
import { AsyncComponent, HandlePromiseProps, withHandlePromise } from '../utils'; | ||
import { getName, YellowExclamationTriangleIcon } from '@console/shared'; | ||
import { | ||
createModalLauncher, | ||
ModalTitle, | ||
ModalBody, | ||
ModalSubmitFooter, | ||
ModalComponentProps, | ||
} from '../factory'; | ||
import { k8sKill, PersistentVolumeClaimKind } from '@console/internal/module/k8s'; | ||
import { PersistentVolumeClaimModel } from '../../models'; | ||
import { isPVCDelete, PVCDelete, useExtensions } from '@console/plugin-sdk'; | ||
|
||
const DeletePVCModal = withHandlePromise<DeletePVCModalProps>((props) => { | ||
const { pvc, inProgress, errorMessage, handlePromise, close, cancel } = props; | ||
const pvcDeleteExtensions = useExtensions<PVCDelete>(isPVCDelete); | ||
const pvcName = getName(pvc); | ||
|
||
const submit = (e) => { | ||
e.preventDefault(); | ||
|
||
const promise = k8sKill(PersistentVolumeClaimModel, pvc); | ||
const extensionPromises = pvcDeleteExtensions.map( | ||
({ properties: { predicate, onPVCKill } }) => predicate(pvc) && onPVCKill(pvc), | ||
); | ||
return handlePromise(Promise.all([promise, ...extensionPromises]), close); | ||
}; | ||
|
||
const alertComponents = pvcDeleteExtensions.map( | ||
({ properties: { predicate, alert }, uid }) => | ||
predicate(pvc) && ( | ||
<Alert | ||
key={`pvc-alert-${uid}`} | ||
className="co-m-form-row" | ||
isInline | ||
variant={alert?.alertType} | ||
title={alert?.alertTitle} | ||
> | ||
<AsyncComponent loader={alert?.alertBody} pvc={pvc} /> | ||
</Alert> | ||
), | ||
); | ||
|
||
return ( | ||
<form onSubmit={submit} className="modal-content"> | ||
<ModalTitle> | ||
<YellowExclamationTriangleIcon className="co-icon-space-r" /> Delete Persistent Volume Claim | ||
</ModalTitle> | ||
<ModalBody> | ||
<Stack hasGutter> | ||
{alertComponents.map((alert, i) => ( | ||
<StackItem key={`alert-${i}`}>{alert}</StackItem> | ||
))} | ||
<StackItem> | ||
Are you sure you want to delete <strong className="co-break-word">{pvcName}</strong>{' '} | ||
Persistent Volume Claim? | ||
</StackItem> | ||
</Stack> | ||
</ModalBody> | ||
<ModalSubmitFooter | ||
errorMessage={errorMessage} | ||
inProgress={inProgress} | ||
submitText="Delete" | ||
submitDanger | ||
cancel={cancel} | ||
/> | ||
</form> | ||
); | ||
}); | ||
|
||
export type DeletePVCModalProps = { | ||
pvc: PersistentVolumeClaimKind; | ||
} & ModalComponentProps & | ||
HandlePromiseProps; | ||
|
||
export default createModalLauncher(DeletePVCModal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters