Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,17 @@ const RestorePVCModal: FC<RestorePVCModalProps> = ({ close, cancel, resource })
>(PersistentVolumeClaimModel, resource?.spec?.source?.persistentVolumeClaimName, namespace);

const pvcStorageClassName = pvcResource?.spec?.storageClassName;
const pvcNotFound = pvcResourceLoaded && !pvcResource;
const [scResource, scResourceLoaded, scResourceLoadError] = useK8sGet<StorageClassResourceKind>(
StorageClassModel,
pvcStorageClassName,
);

// Form is ready when either:
// - PVC was found and its StorageClass has loaded
// - PVC was not found (deleted) — annotations and snapshot status provide sufficient data
const formReady = pvcNotFound || (!!pvcStorageClassName && scResourceLoaded);

Comment on lines +83 to +93
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Gate pvcNotFound on an explicit 404 signal.

Line 83 currently treats any “loaded but no PVC object” state as deleted. That can misclassify non-404 failures (RBAC/API/transient) as deletion and set formReady true incorrectly.

Suggested fix
-  const pvcNotFound = pvcResourceLoaded && !pvcResource;
+  const pvcNotFound = pvcResourceLoaded && !pvcResource && pvcResourceLoadError?.code === 404;

If this hook surfaces HTTP status via status instead of code, use that field instead.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const pvcNotFound = pvcResourceLoaded && !pvcResource;
const [scResource, scResourceLoaded, scResourceLoadError] = useK8sGet<StorageClassResourceKind>(
StorageClassModel,
pvcStorageClassName,
);
// Form is ready when either:
// - PVC was found and its StorageClass has loaded
// - PVC was not found (deleted) — annotations and snapshot status provide sufficient data
const formReady = pvcNotFound || (!!pvcStorageClassName && scResourceLoaded);
const pvcNotFound = pvcResourceLoaded && !pvcResource && pvcResourceLoadError?.code === 404;
const [scResource, scResourceLoaded, scResourceLoadError] = useK8sGet<StorageClassResourceKind>(
StorageClassModel,
pvcStorageClassName,
);
// Form is ready when either:
// - PVC was found and its StorageClass has loaded
// - PVC was not found (deleted) — annotations and snapshot status provide sufficient data
const formReady = pvcNotFound || (!!pvcStorageClassName && scResourceLoaded);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/packages/console-app/src/components/modals/restore-pvc/restore-pvc-modal.tsx`
around lines 83 - 93, The code treats any "loaded but no PVC object"
(pvcNotFound computed from pvcResourceLoaded && !pvcResource) as deletion which
can misclassify non-404 errors; update the logic that computes pvcNotFound to
only be true when the GET hook indicates an explicit 404 (check the hook's error
payload field name, e.g., error.status or error.code) returned by the useK8sGet
call for the PVC (use the same variable holding the error/status), and then use
that gated pvcNotFound when deriving formReady so transient/API/RBAC errors
won't set formReady true.

const [volumeMode, setVolumeMode] = useState('');
const requestedSizeInputChange = ({ value, unit }) => {
setRequestedSize(value);
Expand Down Expand Up @@ -156,13 +162,16 @@ const RestorePVCModal: FC<RestorePVCModalProps> = ({ close, cancel, resource })
/>
</FormGroup>
<FormGroup fieldId="restore-storage-class">
{!pvcStorageClassName || !scResourceLoaded ? (
{!formReady ? (
<div className="skeleton-text" />
) : (
<StorageClassDropdown
onChange={handleStorageClass}
filter={(scObj: StorageClassResourceKind) =>
onlyPvcSCs(scObj, scResourceLoadError, scResource)
filter={
pvcNotFound
? undefined
: (scObj: StorageClassResourceKind) =>
onlyPvcSCs(scObj, scResourceLoadError, scResource)
}
id="restore-storage-class"
required
Expand Down Expand Up @@ -190,14 +199,17 @@ const RestorePVCModal: FC<RestorePVCModalProps> = ({ close, cancel, resource })
availableVolumeMode={volumeSnapshotAnnotations?.[snapshotPVCVolumeModeAnnotation]}
/>
<FormGroup label={t('console-app~Size')} isRequired fieldId="pvc-size">
{!!pvcStorageClassName && scResourceLoaded ? (
{formReady ? (
<RequestSizeInput
name="requestSize"
onChange={requestedSizeInputChange}
defaultRequestSizeUnit={requestedUnit}
defaultRequestSizeValue={requestedSize}
dropdownUnits={dropdownUnits}
isInputDisabled={scResourceLoadError || isCephProvisioner(scResource?.provisioner)}
isInputDisabled={
!pvcNotFound &&
(scResourceLoadError || isCephProvisioner(scResource?.provisioner))
}
required
/>
) : (
Expand Down