-
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.
CNV-5024: Inform for pending changes in VM details view
Add alerts when the user make changes in the VM details view while the VM is running informing to restart the VM for the changes to apply. Additionally, the changes aren't reflected immediately on the screen while the VM is running, like they used to be, but change after the VM restarts. This way the screen represents the current configuration rather than the 'future' configuration. Signed-off-by: Ido Rosenzwig <irosenzw@redhat.com> CNV-5024# Please enter the commit message for your changes. Lines starting
- Loading branch information
Showing
15 changed files
with
271 additions
and
29 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
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
4 changes: 4 additions & 0 deletions
4
frontend/packages/kubevirt-plugin/src/components/vms/utils.scss
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,4 @@ | ||
.kubevirt-vm-details__restart_required-class-alert { | ||
margin-bottom: var(--pf-global--spacer--sm); | ||
margin-top: var(--pf-global--spacer--sm); | ||
} |
101 changes: 101 additions & 0 deletions
101
frontend/packages/kubevirt-plugin/src/components/vms/utils.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,101 @@ | ||
import * as React from 'react'; | ||
import { VMWrapper } from '../../k8s/wrapper/vm/vm-wrapper'; | ||
import { VMIWrapper } from '../../k8s/wrapper/vm/vmi-wrapper'; | ||
import * as _ from 'lodash'; | ||
import { getPVCSourceByDisk } from '../../selectors/vm/selectors'; | ||
import { getVMIPVCSourceByDisk } from '../../selectors/vmi/selectors'; | ||
import { BootableDeviceType } from '../../types/types'; | ||
import { IsPendingChange } from './types'; | ||
import { VMKind, VMIKind } from '../../types/vm'; | ||
import { Alert, AlertVariant } from '@patternfly/react-core'; | ||
|
||
import './utils.scss'; | ||
import { MODAL_RESTART_IS_REQUIRED } from '../../strings/vm/status'; | ||
|
||
export const isFlavorChanged = (vm: VMWrapper, vmi: VMIWrapper): boolean => { | ||
if (!vm || !vmi) { | ||
return false; | ||
} | ||
|
||
return vm.getFlavor() !== vmi.getFlavor(); | ||
}; | ||
|
||
export const isCDROMChanged = (vm: VMWrapper, vmi: VMIWrapper): boolean => { | ||
if (!vm || !vmi) { | ||
return false; | ||
} | ||
|
||
const vmPVCs: string[] = vm | ||
.getCDROMs() | ||
.map((cd) => getPVCSourceByDisk(vm.getVMObj(), cd.name)) | ||
.sort(); | ||
|
||
const vmiPVCs: string[] = vmi | ||
.getCDROMs() | ||
.map((cd) => getVMIPVCSourceByDisk(vmi.getVMIObj(), cd.name)) | ||
.sort(); | ||
|
||
if (vmiPVCs.length === 0) { | ||
return false; | ||
} | ||
|
||
if (vmPVCs.length !== vmiPVCs.length) { | ||
return true; | ||
} | ||
|
||
return !vmPVCs.every((value, index) => value === vmiPVCs[index]); | ||
}; | ||
|
||
export const isBootOrderChanged = (vm: VMWrapper, vmi: VMIWrapper): boolean => { | ||
if (!vm || !vmi) { | ||
return false; | ||
} | ||
|
||
const vmBootOrder: BootableDeviceType[] = _.sortBy( | ||
vm.getLabeledDevices().filter((dev) => dev.value.bootOrder), | ||
'value.bootOrder', | ||
); | ||
|
||
const vmiBootOrder: BootableDeviceType[] = _.sortBy( | ||
vmi.getLabeledDevices().filter((dev) => dev.value.bootOrder), | ||
'value.bootOrder', | ||
); | ||
|
||
if (vmiBootOrder.length === 0) { | ||
return false; | ||
} | ||
|
||
if (vmBootOrder.length !== vmiBootOrder.length) { | ||
return true; | ||
} | ||
|
||
return !vmBootOrder.every( | ||
(device, index) => | ||
device.type === vmiBootOrder[index].type && | ||
device.typeLabel === vmiBootOrder[index].typeLabel && | ||
device.value.bootOrder === vmiBootOrder[index].value.bootOrder && | ||
device.value.name === vmiBootOrder[index].value.name, | ||
); | ||
}; | ||
|
||
export const detectNextRunChanges = (vm: VMKind, vmi: VMIKind) => { | ||
const vmWrapper = new VMWrapper(vm); | ||
const vmiWrapper = new VMIWrapper(vmi); | ||
|
||
return { | ||
[IsPendingChange.flavor]: !!vmi && isFlavorChanged(vmWrapper, vmiWrapper), | ||
[IsPendingChange.cdroms]: !!vmi && isCDROMChanged(vmWrapper, vmiWrapper), | ||
[IsPendingChange.bootOrder]: !!vmi && isBootOrderChanged(vmWrapper, vmiWrapper), | ||
}; | ||
}; | ||
|
||
export const pendingChangesAlert = () => ( | ||
<Alert | ||
title="Pending Changes" | ||
isInline | ||
variant={AlertVariant.info} | ||
className="kubevirt-vm-details__restart_required-class-alert" | ||
> | ||
{MODAL_RESTART_IS_REQUIRED} | ||
</Alert> | ||
); |
4 changes: 4 additions & 0 deletions
4
frontend/packages/kubevirt-plugin/src/components/vms/vm-details.scss
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,4 @@ | ||
.kubevirt-vm-details__pending-changes-class-alert { | ||
margin-bottom: var(--pf-global--spacer--sm); | ||
margin-top: var(--pf-global--spacer--sm); | ||
} |
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
5 changes: 5 additions & 0 deletions
5
frontend/packages/kubevirt-plugin/src/components/vms/vm-resource.scss
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
@import "./resource-summary-description"; | ||
|
||
.kubevirt-vm-details__vm-details-item { | ||
padding-left: var(--pf-global--spacer--sm); | ||
padding-right: var(--pf-global--spacer--sm); | ||
} |
Oops, something went wrong.