-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6124 from afreen23/disk-replacement-kebab-action
(feat): Add OCS kebab actions in the LSO disk inventory related to the day2 operations
- Loading branch information
Showing
4 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
...plugin/src/components/attached-devices-mode/lso-disk-inventory/disk-replacement-modal.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,111 @@ | ||
import * as React from 'react'; | ||
import { | ||
ModalTitle, | ||
ModalBody, | ||
ModalSubmitFooter, | ||
createModalLauncher, | ||
ModalComponentProps, | ||
} from '@console/internal/components/factory'; | ||
import { | ||
k8sGet, | ||
k8sCreate, | ||
TemplateKind, | ||
TemplateInstanceKind, | ||
apiVersionForModel, | ||
SecretKind, | ||
} from '@console/internal/module/k8s'; | ||
import { TemplateModel, TemplateInstanceModel, SecretModel } from '@console/internal/models'; | ||
import { CEPH_STORAGE_NAMESPACE } from '../../../constants'; | ||
|
||
const OSD_REMOVAL_TEMPLATE = 'ocs-osd-removal'; | ||
|
||
const createTemplateSecret = async (template: TemplateKind, osdId: string) => { | ||
const parametersSecret: SecretKind = { | ||
apiVersion: SecretModel.apiVersion, | ||
kind: SecretModel.kind, | ||
metadata: { | ||
name: `${OSD_REMOVAL_TEMPLATE}-parameters`, | ||
namespace: CEPH_STORAGE_NAMESPACE, | ||
}, | ||
stringData: { | ||
[template.parameters[0].name]: osdId, | ||
}, | ||
}; | ||
return k8sCreate(SecretModel, parametersSecret); | ||
}; | ||
|
||
const createTemplateInstance = async (parametersSecret: SecretKind, template: TemplateKind) => { | ||
const templateInstance: TemplateInstanceKind = { | ||
apiVersion: apiVersionForModel(TemplateInstanceModel), | ||
kind: TemplateInstanceModel.kind, | ||
metadata: { | ||
name: `${OSD_REMOVAL_TEMPLATE}-template-instance`, | ||
namespace: CEPH_STORAGE_NAMESPACE, | ||
}, | ||
spec: { | ||
secret: { | ||
name: parametersSecret.metadata.name, | ||
}, | ||
template, | ||
}, | ||
}; | ||
return k8sCreate(TemplateInstanceModel, templateInstance); | ||
}; | ||
|
||
const instantiateTemplate = async (osdId: string) => { | ||
const osdRemovalTemplate = await k8sGet( | ||
TemplateModel, | ||
OSD_REMOVAL_TEMPLATE, | ||
CEPH_STORAGE_NAMESPACE, | ||
); | ||
const templateSecret = await createTemplateSecret(osdRemovalTemplate, osdId); | ||
await createTemplateInstance(templateSecret, osdRemovalTemplate); | ||
}; | ||
|
||
const DiskReplacementAction = (props: DiskReplacementActionProps) => { | ||
const { diskName, osdId, cancel, close } = props; | ||
|
||
const [inProgress, setProgress] = React.useState(false); | ||
const [errorMessage, setError] = React.useState(''); | ||
|
||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
setProgress(true); | ||
/* | ||
* TODO:(Afreen) Add validations based on ocs status (part of followup PR) | ||
*/ | ||
try { | ||
instantiateTemplate(osdId); | ||
close(); | ||
} catch (err) { | ||
setError(err.message); | ||
} finally { | ||
setProgress(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} name="form" className="modal-content"> | ||
<ModalTitle>Disk Replacement</ModalTitle> | ||
<ModalBody> | ||
<p>This action will start preparing the disk for replacement.</p> | ||
<p> | ||
Are you sure you want to replace <strong>{diskName}</strong> ? | ||
</p> | ||
</ModalBody> | ||
<ModalSubmitFooter | ||
errorMessage={errorMessage} | ||
inProgress={inProgress} | ||
submitText="Replace" | ||
cancel={cancel} | ||
/> | ||
</form> | ||
); | ||
}; | ||
|
||
export const diskReplacementModal = createModalLauncher(DiskReplacementAction); | ||
|
||
export type DiskReplacementActionProps = { | ||
diskName: string; | ||
osdId: string; | ||
} & ModalComponentProps; |
27 changes: 27 additions & 0 deletions
27
...rage-plugin/src/components/attached-devices-mode/lso-disk-inventory/ocs-kebab-options.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,27 @@ | ||
import * as React from 'react'; | ||
import { TableData } from '@console/internal/components/factory'; | ||
import { KebabOption, Kebab } from '@console/internal/components/utils'; | ||
import { diskReplacementModal } from './disk-replacement-modal'; | ||
|
||
const startDiskReplacementAction = (diskName: string, osdId: string): KebabOption => ({ | ||
label: 'Start Disk Replacement', | ||
callback: () => | ||
diskReplacementModal({ | ||
diskName, | ||
osdId, | ||
}), | ||
}); | ||
|
||
export const OCSKebabOptions: React.FC<OCSKebabOptionsProps> = ({ diskName, diskOsdMap }) => { | ||
const osdId: string = diskOsdMap.get(diskName); | ||
const kebabOptions: KebabOption[] = [startDiskReplacementAction(diskName, osdId)]; | ||
|
||
return ( | ||
<TableData className={Kebab.columnClass}> | ||
{/* Disable options for non OCS based disks */} | ||
<Kebab options={kebabOptions} isDisabled={!!osdId} /> | ||
</TableData> | ||
); | ||
}; | ||
|
||
type OCSKebabOptionsProps = { diskName: string; diskOsdMap: Map<string, string> }; |
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