-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kubevirt VmDetails #1682
Kubevirt VmDetails #1682
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { K8sResourceKind, ObjectMetadata } from '@console/internal/module/k8s'; | ||
|
||
// https://kubevirt.io/api-reference/master/definitions.html#_v1_virtualmachineinstancespec | ||
export type VMISpec = { | ||
affinity: any; | ||
dnsConfig: any; | ||
dnsPolicy: string; | ||
domain?: any; | ||
evictionStrategy: any; | ||
hostname: string; | ||
livenessProbe: any; | ||
networks?: any[]; | ||
nodeSelector: any; | ||
readinessProbe: any; | ||
subdomain: string; | ||
terminationGracePeriodSeconds: number; | ||
tolerations: any[]; | ||
volumes?: any[]; | ||
}; | ||
|
||
// https://kubevirt.io/api-reference/master/definitions.html#_v1_virtualmachineinstancestatus | ||
export type VMIStatus = { | ||
conditions: any[]; | ||
interfaces: any[]; | ||
migrationMethod: string; | ||
migrationState: any; | ||
nodeName: string; | ||
phase: string; | ||
reason: string; | ||
}; | ||
|
||
export type VMIKind = { | ||
spec: VMISpec; | ||
status: VMIStatus; | ||
} & K8sResourceKind; | ||
|
||
export type VMITemplate = { | ||
metadata?: ObjectMetadata; | ||
spec?: VMISpec; | ||
}; | ||
|
||
export type VMSpec = { | ||
template: VMITemplate; | ||
running?: boolean; | ||
runStrategy?: any; | ||
dataVolumeTemplates?: any[]; | ||
}; | ||
|
||
export type VMStatus = { | ||
conditions?: any[]; | ||
created?: boolean; | ||
ready?: boolean; | ||
stateChangeRequests?: any[]; | ||
}; | ||
|
||
// https://kubevirt.io/api-reference/master/definitions.html#_v1_virtualmachine | ||
export type VMKind = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I'd put the base object first, i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I don't think this is something crucial. Anyway, the rest of recent code-base uses both options where to place operands. The one already used in this PR looks more common (statistic retrieved via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
IMO it's more readable to put base object before the extension, instead of the other way around. So my comment was related to better code readability, which I personally consider as crucial. |
||
spec: VMSpec; | ||
status: VMStatus; | ||
} & K8sResourceKind; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react'; | ||
|
||
import { navFactory } from '@console/internal/components/utils'; | ||
|
||
import { DetailsPage } from '@console/internal/components/factory'; | ||
import { K8sResourceKindReference } from '@console/internal/module/k8s'; | ||
|
||
import { VMDetailsFirehose } from './vm-details'; | ||
|
||
// import { VmEvents } from './vm-events'; | ||
// import VmConsolesConnected from '../vmconsoles'; | ||
// import { Nic } from '../nic'; | ||
// import { Disk } from '../disk'; | ||
// import { menuActions } from './menu-actions'; | ||
|
||
export const VirtualMachinesDetailsPage = (props: VirtualMachinesDetailsPageProps) => { | ||
/* TODO(mlibra): pages will be transferred one by one in follow-ups | ||
const consolePage = { | ||
href: 'consoles', | ||
name: 'Consoles', | ||
component: VmConsolesConnected, | ||
}; | ||
|
||
const nicsPage = { | ||
href: 'nics', | ||
name: 'Network Interfaces', | ||
component: VmNic, | ||
}; | ||
|
||
const disksPage = { | ||
href: 'disks', | ||
name: 'Disks', | ||
component: VmDisk, | ||
}; | ||
*/ | ||
|
||
const pages = [ | ||
navFactory.details(VMDetailsFirehose), | ||
navFactory.editYaml(), | ||
// consolePage, | ||
// navFactory.events(VmEvents), | ||
// nicsPage, | ||
// disksPage, | ||
]; | ||
|
||
const menuActions = undefined; // TODO(mlibra): menuActions | ||
|
||
return <DetailsPage {...props} menuActions={menuActions} pages={pages} />; | ||
}; | ||
|
||
type VirtualMachinesDetailsPageProps = { | ||
name: string; | ||
namespace: string; | ||
kind: K8sResourceKindReference; | ||
match: any; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
|
||
import { getResource, getServicesForVm } from 'kubevirt-web-ui-components'; | ||
|
||
import { | ||
Firehose, | ||
StatusBox, | ||
ScrollToTopOnMount, | ||
SectionHeading, | ||
} from '@console/internal/components/utils'; | ||
|
||
import { PodKind } from '@console/internal/module/k8s'; | ||
import { PodModel, ServiceModel } from '@console/internal/models'; | ||
|
||
import { ServicesList } from '@console/internal/components/service'; | ||
import { VMKind, VMIKind } from './types'; | ||
import { VirtualMachineInstanceModel, VirtualMachineInstanceMigrationModel } from '../../models'; | ||
import { VMResourceSummary, VMDetailsList } from './vm-resource'; | ||
|
||
export const VMDetailsFirehose = ({ obj: vm }: { obj: VMKind }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put the VmDetails implementation into a separate file and use this file only as disambiguation for all the tabs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other pages have details co-located as well. Anyway, to move forward, I split it here. |
||
const { name, namespace } = vm.metadata; | ||
|
||
const vmiRes = getResource(VirtualMachineInstanceModel, { | ||
name, | ||
namespace, | ||
isList: false, | ||
prop: 'vmi', | ||
optional: true, | ||
}); | ||
|
||
const resources = [ | ||
vmiRes, | ||
getResource(PodModel, { namespace, prop: 'pods' }), | ||
getResource(VirtualMachineInstanceMigrationModel, { namespace, prop: 'migrations' }), | ||
getResource(ServiceModel, { namespace, prop: 'services' }), | ||
]; | ||
|
||
return ( | ||
<div className="co-m-pane__body"> | ||
<Firehose resources={resources}> | ||
<VMDetails vm={vm} /> | ||
</Firehose> | ||
</div> | ||
); | ||
}; | ||
|
||
const VMDetails = (props: VMDetailsProps) => { | ||
const { vm, ...restProps } = props; | ||
const flatResources = { | ||
vm, | ||
vmi: _.get(props, 'vmi.data'), | ||
pods: _.get(props, 'pods.data'), | ||
migrations: _.get(props, 'migrations.data'), | ||
}; | ||
|
||
const vmServicesData = getServicesForVm(_.get(props, 'services', {}).data, vm); | ||
|
||
return ( | ||
<StatusBox data={vm} {...restProps}> | ||
<ScrollToTopOnMount /> | ||
<div className="co-m-pane__body"> | ||
<SectionHeading text="VM Overview" /> | ||
<div className="row"> | ||
<div className="col-sm-6"> | ||
<VMResourceSummary {...flatResources} /> | ||
</div> | ||
<div className="col-sm-6"> | ||
<VMDetailsList {...flatResources} /> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="co-m-pane__body"> | ||
<SectionHeading text="Services" /> | ||
<ServicesList {...restProps} data={vmServicesData} /> | ||
</div> | ||
</StatusBox> | ||
); | ||
}; | ||
|
||
type VMDetailsProps = { | ||
vm: VMKind; | ||
pods?: PodKind[]; | ||
migrations?: any[]; | ||
vmi?: VMIKind; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
getDescription, | ||
getOperatingSystemName, | ||
getOperatingSystem, | ||
getVmStatus, | ||
getVmiIpAddresses, | ||
getWorkloadProfile, | ||
getVmTemplate, | ||
getTemplateDisplayName, | ||
getNodeName, | ||
getFlavor, | ||
VmStatuses, | ||
BootOrder, | ||
isVmOff, | ||
getBootableDevicesInOrder, | ||
} from 'kubevirt-web-ui-components'; | ||
|
||
import { ResourceSummary, NodeLink, ResourceLink } from '@console/internal/components/utils'; | ||
import { PodKind } from '@console/internal/module/k8s'; | ||
import { getName, getNamespace, DASH } from '@console/shared'; | ||
import { PodModel } from '@console/internal/models'; | ||
|
||
import { VMKind, VMIKind } from './types'; | ||
|
||
export const VMResourceSummary = ({ vm }: VMResourceSummaryProps) => { | ||
const template = getVmTemplate(vm); | ||
const templateLink = template && getTemplateDisplayName(template); // TODO(mlibra): link to a template detail, once implemented | ||
|
||
return ( | ||
<ResourceSummary resource={vm}> | ||
<dt>Description</dt> | ||
<dd>{getDescription(vm)}</dd> | ||
<dt>Operating System</dt> | ||
<dd>{getOperatingSystemName(vm) || getOperatingSystem(vm) || DASH}</dd> | ||
<dt>Template</dt> | ||
<dd>{templateLink || DASH}</dd> | ||
</ResourceSummary> | ||
); | ||
}; | ||
|
||
export const VMDetailsList = ({ vm, vmi, pods, migrations }: VMResourceListProps) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you planning to do the editing part as well? IMO it would be much easier to pull it in atomically than by parts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Editing will have to wait for a followup patch, we need to get at least this part in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
const vmStatus = getVmStatus(vm, pods, migrations); | ||
const { launcherPod } = vmStatus; | ||
const sortedBootableDevices = getBootableDevicesInOrder(vm); | ||
const nodeName = getNodeName(launcherPod); | ||
const vmIsOff = isVmOff(vmStatus); | ||
const ipAddresses = vmIsOff ? [] : getVmiIpAddresses(vmi); | ||
|
||
return ( | ||
<dl className="co-m-pane__details"> | ||
<dt>Status</dt> | ||
<dd> | ||
<VmStatuses vm={vm} pods={pods} migrations={migrations} /> | ||
</dd> | ||
<dt>Pod</dt> | ||
<dd> | ||
{launcherPod ? ( | ||
<ResourceLink | ||
kind={PodModel.kind} | ||
name={getName(launcherPod)} | ||
namespace={getNamespace(launcherPod)} | ||
/> | ||
) : ( | ||
DASH | ||
)} | ||
</dd> | ||
<dt>Boot Order</dt> | ||
<dd> | ||
{sortedBootableDevices.length > 0 ? ( | ||
<BootOrder bootableDevices={sortedBootableDevices} /> | ||
) : ( | ||
DASH | ||
)} | ||
</dd> | ||
<dt>IP Address</dt> | ||
<dd>{ipAddresses.length > 0 ? ipAddresses.join(', ') : DASH}</dd> | ||
<dt>Node</dt> | ||
<dd>{<NodeLink name={nodeName} />}</dd> | ||
<dt>Flavour</dt> | ||
<dd>{getFlavor(vm) || DASH}</dd> | ||
<dt>Workload Profile</dt> | ||
<dd>{getWorkloadProfile(vm) || DASH}</dd> | ||
</dl> | ||
); | ||
}; | ||
|
||
type VMResourceSummaryProps = { | ||
vm: VMKind; | ||
}; | ||
|
||
type VMResourceListProps = { | ||
vm: VMKind; | ||
pods?: PodKind[]; | ||
migrations?: any[]; | ||
vmi?: VMIKind; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import '~kubevirt-web-ui-components/dist/sass/components'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd put the base object first, i.e.
K8sResourceKind & { .. }