Skip to content

Commit

Permalink
Migration status title is now showing state of migration
Browse files Browse the repository at this point in the history
Signed-off-by: Matan Schatzman <mschatzm@redhat.com>
  • Loading branch information
metalice committed Dec 29, 2020
1 parent 1e133aa commit a360de7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
Expand Up @@ -569,6 +569,7 @@
"Last restored": "Last restored",
"This virtual machine has some pending changes that will apply after it is restarted.": "This virtual machine has some pending changes that will apply after it is restarted.",
"View Details": "View Details",
"Unknown": "Unknown",
"{{provider}} supported": "{{provider}} supported",
"Create new Template from": "Create new Template from",
"Delete Template": "Delete Template",
Expand Down Expand Up @@ -715,6 +716,12 @@
"Supported by most operating systems including Windows out of the box. Offers lower performance compared to virtio. Consider using it for CD-ROM devices": "Supported by most operating systems including Windows out of the box. Offers lower performance compared to virtio. Consider using it for CD-ROM devices",
"scsi": "scsi",
"Useful when the VM wants to interact with the device using direct scsi commands. Supported by most operating systems including Windows out of the box. Offers lower performance compared to virtio": "Useful when the VM wants to interact with the device using direct scsi commands. Supported by most operating systems including Windows out of the box. Offers lower performance compared to virtio",
"Pending Migration": "Pending Migration",
"Scheduling Migration": "Scheduling Migration",
"Preparing Target Migration": "Preparing Target Migration",
"Scheduled Migration": "Scheduled Migration",
"Target Ready Migration": "Target Ready Migration",
"Running Migration": "Running Migration",
"Desktop": "Desktop",
"Small scale consumption, recommended for using the graphical console": "Small scale consumption, recommended for using the graphical console",
"Server": "Server",
Expand Down
Expand Up @@ -160,10 +160,11 @@ export const VMStatus: React.FC<VMStatusProps> = ({
vmStatusBundle,
arePendingChanges,
}) => {
const { t } = useTranslation();
const vmiLike = vm || vmi;

const { status, pod, progress, importerPodsStatuses } = vmStatusBundle;
const title = status.toString(); // TODO status.toVerboseString() should be called to pass to popup header
const title = t(status.getLabelKey()) || status.toString() || t('kubevirt-plugin~Unknown'); // TODO status.toVerboseString() should be called to pass to popup header
const popoverTitle = arePendingChanges ? 'Pending Changes' : null;
const message = vmStatusBundle.message || vmStatusBundle.detailedMessage;
const detailedMessage = vmStatusBundle.message ? vmStatusBundle.detailedMessage : null;
Expand Down Expand Up @@ -201,11 +202,7 @@ export const VMStatus: React.FC<VMStatusProps> = ({
}

return (
<GenericStatus
title={title || VMStatusEnum.UNKNOWN.toString()}
Icon={icon}
popoverTitle={popoverTitle}
>
<GenericStatus title={title} Icon={icon} popoverTitle={popoverTitle}>
{(message || isPaused) && (
<VMStatusPopoverContent key="popover" message={message} links={links} progress={progress}>
{isPaused && (
Expand Down
Expand Up @@ -23,6 +23,7 @@ export abstract class StatusEnum<SIMPLE_LABEL = StatusSimpleLabel> extends Objec

protected readonly group: StatusGroup;
protected readonly label: string;
protected readonly labelKey: string;
protected readonly simpleLabel: SIMPLE_LABEL | StatusSimpleLabel; // cache resolveSimpleLabel call

protected constructor(
Expand All @@ -37,6 +38,7 @@ export abstract class StatusEnum<SIMPLE_LABEL = StatusSimpleLabel> extends Objec
isUnknown,
group,
}: StatusMetadata = {},
labelKey?: string,
) {
super(value);
if (label == null) {
Expand All @@ -48,7 +50,6 @@ export abstract class StatusEnum<SIMPLE_LABEL = StatusSimpleLabel> extends Objec
this._isPending = isPending || false;
this._isImporting = isImporting || false;
this._isInProgress = this._isPending || this._isImporting || isInProgress || false; // pending means expected progress

const isKnown = isError || isCompleted || isPending || isImporting || isInProgress;

if (isUnknown && isKnown) {
Expand All @@ -59,6 +60,7 @@ export abstract class StatusEnum<SIMPLE_LABEL = StatusSimpleLabel> extends Objec

this.group = group;
this.label = label;
this.labelKey = labelKey;
this.simpleLabel = this.resolveSimpleLabel();
}

Expand Down Expand Up @@ -87,6 +89,8 @@ export abstract class StatusEnum<SIMPLE_LABEL = StatusSimpleLabel> extends Objec

getLabel = () => this.label;

getLabelKey = () => this.labelKey;

getGroup = () => this.group;

getSimpleLabel = () => this.simpleLabel;
Expand Down
60 changes: 54 additions & 6 deletions frontend/packages/kubevirt-plugin/src/constants/vm/vm-status.ts
Expand Up @@ -6,6 +6,33 @@ import { getStringEnumValues } from '../../utils/types';
import { StatusSimpleLabel } from '../status-constants';
import { StatusGroup } from '../status-group';

export const VMStatusMigrationPhases = {
Pending: {
// t('kubevirt-plugin~Pending Migration')
labelKey: 'kubevirt-plugin~Migration - Pending',
},
Scheduling: {
// t('kubevirt-plugin~Scheduling Migration')
labelKey: 'kubevirt-plugin~Migration - Scheduling',
},
PreparingTarget: {
// t('kubevirt-plugin~Preparing Target Migration')
labelKey: 'kubevirt-plugin~Migration - Preparing Target',
},
Scheduled: {
// t('kubevirt-plugin~Scheduled Migration')
labelKey: 'kubevirt-plugin~Migration - Scheduled',
},
TargetReady: {
// t('kubevirt-plugin~Target Ready Migration')
labelKey: 'kubevirt-plugin~Migration - Target Ready ',
},
Running: {
// t('kubevirt-plugin~Running Migration')
labelKey: 'kubevirt-plugin~Migration - Running',
},
};

export enum VMStatusSimpleLabel {
Starting = 'Starting',
Paused = 'Paused',
Expand Down Expand Up @@ -47,8 +74,12 @@ export class VMStatus extends StatusEnum<VMStatusSimpleLabel | StatusSimpleLabel
static readonly DELETING = new VMStatus('VMStatus_DELETING', VMStatusSimpleLabel.Deleting, {
isInProgress: true,
});
static readonly VM_ERROR = new VMStatus('VMStatus_VM_ERROR', 'VM error', { isError: true });
static readonly VMI_ERROR = new VMStatus('VMStatus_VMI_ERROR', 'VMI error', { isError: true });
static readonly VM_ERROR = new VMStatus('VMStatus_VM_ERROR', 'VM error', {
isError: true,
});
static readonly VMI_ERROR = new VMStatus('VMStatus_VMI_ERROR', 'VMI error', {
isError: true,
});
static readonly LAUNCHER_POD_ERROR = new VMStatus(
'VMStatus_LAUNCHER_POD_ERROR',
'Launcher pod error',
Expand Down Expand Up @@ -78,6 +109,17 @@ export class VMStatus extends StatusEnum<VMStatusSimpleLabel | StatusSimpleLabel
static readonly MIGRATING = new VMStatus('VMStatus_MIGRATING', VMStatusSimpleLabel.Migrating, {
isMigrating: true,
});

static readonly getMigrationStatus = (phase = 'Pending') =>
new VMStatus(
'VMStatus_MIGRATING',
VMStatusSimpleLabel.Migrating,
{
isMigrating: true,
},
VMStatusMigrationPhases[phase].labelKey,
);

static readonly V2V_CONVERSION_ERROR = new VMStatus(
'VMStatus_V2V_CONVERSION_ERROR',
'Import error',
Expand Down Expand Up @@ -123,11 +165,17 @@ export class VMStatus extends StatusEnum<VMStatusSimpleLabel | StatusSimpleLabel
value: string,
label: string,
{ isMigrating, ...metadata }: VMStatusMetadata = {},
labelKey?: string,
) {
super(value, label, {
...metadata,
isInProgress: isMigrating || metadata.isInProgress,
});
super(
value,
label,
{
...metadata,
isInProgress: isMigrating || metadata.isInProgress,
},
labelKey,
);

this._isMigrating = isMigrating || false;
}
Expand Down
Expand Up @@ -139,10 +139,11 @@ const isBeingMigrated = (

const migration = findVMIMigration(name, namespace, migrations);
if (isMigrating(migration)) {
const phase = getMigrationStatusPhase(migration);
return {
status: VMStatus.MIGRATING,
status: VMStatus.getMigrationStatus(phase),
migration,
detailedMessage: getMigrationStatusPhase(migration),
detailedMessage: phase,
};
}
return null;
Expand Down

0 comments on commit a360de7

Please sign in to comment.