-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(topology): adding status icon in the sidebar of vm details (#2131)
* feat(topology) : showing status icon * feat(topology) : utilizing Status component * feat(topology) : fixing sonar issue * feat(topology) : removing extra props from StatusIconAndText * feat(topology-vm) : removing extra test case
- Loading branch information
1 parent
a4562cc
commit b0f27e6
Showing
6 changed files
with
275 additions
and
6 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
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,162 @@ | ||
import { V1Pod } from '@kubernetes/client-node'; | ||
|
||
import { K8sResourceKind, VMIKind, VMKind } from '../types/vm'; | ||
import { | ||
POD_PHASE_PENDING, | ||
RunStrategy, | ||
StateChangeRequest, | ||
VMIPhase, | ||
VMStatusEnum, | ||
VMStatusSimpleLabel, | ||
} from '../vm-const'; | ||
import { | ||
getDeletetionTimestamp, | ||
getPodStatusPhase, | ||
getStatusConditions, | ||
getVMIConditionsByType, | ||
} from './selector'; | ||
|
||
// Paused | ||
const isVMIPaused = (vmi: VMIKind): boolean => | ||
getVMIConditionsByType(vmi, 'Paused').length > 0; | ||
|
||
// Running | ||
const getStatusPhase = <T = string>(entity: K8sResourceKind): T => | ||
entity?.status?.phase; | ||
const isRunning = (vmi: VMIKind): boolean => { | ||
if (getStatusPhase(vmi) === VMIPhase.Running) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
// Error | ||
const getStatusConditionOfType = ( | ||
statusResource: K8sResourceKind, | ||
type: string, | ||
) => | ||
getStatusConditions(statusResource).find( | ||
(condition: { type: string }) => condition?.type === type, | ||
); | ||
|
||
const isVMError = (vm: VMKind): boolean => { | ||
const vmFailureCond = getStatusConditionOfType(vm, 'Failure'); | ||
if (vmFailureCond) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
// Stopped | ||
const isVMCreated = (vm: VMKind) => !!vm?.status?.created; | ||
const isStoppedFromConsole = (vm: VMKind, vmi: VMIKind) => { | ||
return ( | ||
vm && | ||
isVMCreated(vm) && | ||
getStatusPhase(vmi) === VMIPhase.Succeeded && | ||
vm.status.printableStatus === VMStatusSimpleLabel.Stopped | ||
); | ||
}; | ||
|
||
// Deleting | ||
const isDeleting = (vm: VMKind, vmi: VMIKind): boolean => | ||
!!(getDeletetionTimestamp(vm) || (vmi && getDeletetionTimestamp(vmi))); | ||
|
||
// Stopping | ||
const isVMExpectedRunning = (vm: VMKind, vmi: VMIKind) => { | ||
if (!vm?.spec) { | ||
return false; | ||
} | ||
const { running, runStrategy } = vm.spec; | ||
|
||
if (running !== null) { | ||
return running; | ||
} | ||
|
||
if (runStrategy !== null) { | ||
let changeRequests; | ||
switch (runStrategy as RunStrategy) { | ||
case RunStrategy.Halted: | ||
return false; | ||
case RunStrategy.Always: | ||
return true; | ||
case RunStrategy.RerunOnFailure: | ||
return getStatusPhase<VMIPhase>(vmi) !== VMIPhase.Succeeded; | ||
case RunStrategy.Manual: | ||
default: | ||
changeRequests = new Set( | ||
(vm.status?.stateChangeRequests || []).map( | ||
chRequest => chRequest?.action, | ||
), | ||
); | ||
|
||
if (changeRequests.has(StateChangeRequest.Stop)) { | ||
return false; | ||
} | ||
if (changeRequests.has(StateChangeRequest.Start)) { | ||
return true; | ||
} | ||
|
||
return isVMCreated(vm); // if there is no change request we can assume created is representing running (current and expected) | ||
} | ||
} | ||
return false; | ||
}; | ||
const isBeingStopped = (vm: VMKind, vmi: VMIKind): boolean => { | ||
if ( | ||
vm && | ||
!isVMExpectedRunning(vm, vmi) && | ||
isVMCreated(vm) && | ||
getStatusPhase<VMIPhase>(vmi) !== VMIPhase.Succeeded | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
// Starting | ||
const isStarting = (vm: VMKind, vmi: VMIKind): boolean => { | ||
if (vm && isVMCreated(vm) && isVMExpectedRunning(vm, vmi)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
// isInProgress | ||
const isInProgress = (vm: VMKind, vmi: VMIKind) => | ||
isStarting(vm, vmi) || isBeingStopped(vm, vmi) || isDeleting(vm, vmi); | ||
|
||
// VMI_WAITING (PENDING) | ||
const isVMIWaiting = (vmi: VMIKind) => getStatusPhase(vmi) === VMIPhase.Pending; | ||
|
||
// CDI_IMPORT_PENDING(PENDING) | ||
const isCDIImportPending = (pod: V1Pod): boolean => | ||
getPodStatusPhase(pod) === POD_PHASE_PENDING; | ||
|
||
// V2V_CONVERSION_PENDING(PENDING) | ||
const isV2VConversionPemding = (podOfVM: V1Pod): boolean => { | ||
const podPhase = getPodStatusPhase(podOfVM); | ||
return podPhase === POD_PHASE_PENDING; | ||
}; | ||
// PENDING | ||
const isPending = (vmi: VMIKind, pod: V1Pod) => | ||
isVMIWaiting(vmi) || isCDIImportPending(pod) || isV2VConversionPemding(pod); | ||
|
||
export const getStatus = (vm: VMKind, vmi: VMIKind, pod: V1Pod) => { | ||
if (isVMIPaused(vmi)) { | ||
return VMStatusEnum.PAUSED; | ||
} else if (isRunning(vmi)) { | ||
return VMStatusEnum.RUNNING; | ||
} else if (isVMError(vm)) { | ||
return VMStatusEnum.ERROR; | ||
} else if (isStoppedFromConsole(vm, vmi)) { | ||
return VMStatusEnum.STOPPED; | ||
} else if (isInProgress(vm, vmi)) { | ||
return VMStatusEnum.IN_PROGRESS; | ||
} else if (isPending(vmi, pod)) { | ||
return VMStatusEnum.PENDING; | ||
} | ||
return VMStatusEnum.UNKNOWN; | ||
}; |
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,38 @@ | ||
export enum VMIPhase { | ||
Pending = 'Pending', | ||
Scheduling = 'Scheduling', | ||
Scheduled = 'Scheduled', | ||
Running = 'Running', | ||
Succeeded = 'Succeeded', | ||
Failed = 'Failed', | ||
Unknown = 'Unknown', | ||
} | ||
export enum VMStatusSimpleLabel { | ||
Starting = 'Starting', | ||
Paused = 'Paused', | ||
Migrating = 'Migrating', | ||
Stopping = 'Stopping', | ||
Running = 'Running', | ||
Stopped = 'Stopped', | ||
Deleting = 'Deleting', | ||
} | ||
export enum VMStatusEnum { | ||
PAUSED = 'Paused', | ||
RUNNING = 'Running', | ||
STOPPED = 'Stopped', | ||
ERROR = 'Error', | ||
PENDING = 'Pending', // VMI_WAITING,CDI_IMPORT_PENDING,V2V_CONVERSION_PENDING | ||
IN_PROGRESS = 'Progress', // STARTING, STOPPING, DELETING | ||
UNKNOWN = 'Unknown', | ||
} | ||
export enum RunStrategy { | ||
Always = 'Always', | ||
RerunOnFailure = 'RerunOnFailure', | ||
Halted = 'Halted', | ||
Manual = 'Manual', | ||
} | ||
export enum StateChangeRequest { | ||
Start = 'Start', | ||
Stop = 'Stop', | ||
} | ||
export const POD_PHASE_PENDING = 'Pending'; |