-
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.
(feat): Add OCS kebab actions in the LSO disk inventory related to th…
…e day2 operations - Adds the disk replacement action - Utilizes flag for attached devices cluster (`OCS_ATTACHED_DEVICES`) to enable the OCS kebab actions Implements https://issues.redhat.com/browse/RHSTOR-1197 Signed-off-by: Afreen Rahman <afrahman@redhat.com>
- Loading branch information
Afreen Rahman
committed
Jul 28, 2020
1 parent
71e3cce
commit 0c63c1c
Showing
3 changed files
with
182 additions
and
6 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
...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,117 @@ | ||
import * as React from 'react'; | ||
import { | ||
ModalTitle, | ||
ModalBody, | ||
ModalSubmitFooter, | ||
createModalLauncher, | ||
ModalComponentProps, | ||
} from '@console/internal/components/factory'; | ||
import { | ||
k8sGet, | ||
k8sCreate, | ||
TemplateKind, | ||
TemplateInstanceKind, | ||
apiVersionForModel, | ||
K8sResourceCommon, | ||
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: TemplateSecret = { | ||
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: TemplateSecret, 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) | ||
*/ | ||
instantiatetemplate(osdId) | ||
.then(() => { | ||
setProgress(false); | ||
close(); | ||
}) | ||
.catch((err) => { | ||
setProgress(false); | ||
setError(err.message); | ||
}); | ||
}; | ||
|
||
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; | ||
|
||
type TemplateSecret = K8sResourceCommon & { | ||
stringData: SecretKind['stringData']; | ||
}; |
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