Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Improve VM Status #115

Merged
merged 6 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/public/components/factory/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import {
serviceCatalogStatus,
serviceClassDisplayName,
} from '../../module/k8s';
import { getVmStatus } from '../../kubevirt/components/utils/resources';

import { getVmStatus } from 'kubevirt-web-ui-components';

const fuzzyCaseInsensitive = (a, b) => fuzzy(_.toLower(a), _.toLower(b));

Expand Down Expand Up @@ -167,6 +168,7 @@ const listFilters = {
return true;
}

// TODO: figure out how to get VM pods here
const status = getVmStatus(vm);
return statuses.selected.has(status) || !_.includes(statuses.all, status);
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/kubevirt/components/okdcomponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export * from '../../components/namespace';
export * from '../../components/global-notifications';
export * from '../../components/resource-list';
export * from '../../components/events';
export * from '../../components/utils/status-box';
export * from '../../components/utils/status-box'; // TODO: move to utils/okdutils.jsx
export * from '../../components/modals/error-modal';
3 changes: 3 additions & 0 deletions frontend/public/kubevirt/components/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ export const NETWORK_TYPE_POD = 'Pod Networking';

export const NIC = 'NIC';
export const DISK = 'Disk';

export const VIRT_LAUNCHER_POD_PREFIX = 'virt-launcher-';
export const IMPORTER_DV_POD_PREFIX = 'importer-datavolume-';
17 changes: 13 additions & 4 deletions frontend/public/kubevirt/components/utils/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ export const getResourceKind = (model, name, namespaced, namespace, isList, matc

export const getLabelMatcher = (vm) => _.get(vm, 'spec.template.metadata.labels');

export const findPod = (data, name) => {
const pods = data.filter(p => p.metadata.name.startsWith(`virt-launcher-${name}-`));
export const findPod = (data, vmName, podNamePrefix) => {
if (!data) {
return null;
}
const pods = data.filter(p => p.metadata.name.startsWith(`${podNamePrefix}${vmName}-`));
const runningPod = pods.find(p => _.get(p, 'status.phase') === 'Running' || _.get(p, 'status.phase') === 'Pending');
return runningPod ? runningPod : pods.find(p => _.get(p, 'status.phase') === 'Failed' || _.get(p, 'status.phase') === 'Unknown');
};

export const findVMIMigration = (data, vmiName) => {
if (!data || !data.items) {
return null;
}
const migrations = data.items.filter(m => m.spec.vmiName === vmiName);
return migrations.find(m => !_.get(m, 'status.completed') && !_.get(m, 'status.failed') );
};

export const findVMI = (data, name) => data.find(vmi => vmi.metadata.name === name);

export const getFlattenForKind = (kind) => {
Expand All @@ -35,8 +46,6 @@ export const getFlattenForKind = (kind) => {
export const isVmiRunning = (vmi) => _.get(vmi, 'status.phase') === 'Running';
export const isVmStarting = (vm, vmi) => _.get(vm, 'spec.running') && !isVmiRunning(vmi);

export const getVmStatus = vm => _.get(vm, 'spec.running', false) ? 'Running' : 'Stopped';

export const getVncConnectionDetails = vmi => {
// Example: ws://localhost:9000/api/kubernetes/apis/subresources.kubevirt.io/v1alpha2/namespaces/kube-system/virtualmachineinstances/vm-cirros1/vnc
let base = k8sBasePath;
Expand Down
75 changes: 41 additions & 34 deletions frontend/public/kubevirt/components/vm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,43 @@ import {
NetworkAttachmentDefinitionModel,
StorageClassModel,
PersistentVolumeClaimModel,
VirtualMachineInstanceMigrationModel,
} from '../models';
import { k8sCreate, actions } from '../module/okdk8s';

import { startStopVmModal } from './modals/start-stop-vm-modal';
import { restartVmModal } from './modals/restart-vm-modal';
import { getResourceKind, getLabelMatcher, findVMI, findPod, getFlattenForKind, getVmStatus } from './utils/resources';
import {
getResourceKind,
getLabelMatcher,
findVMI,
findPod,
findVMIMigration,
getFlattenForKind,
} from './utils/resources';

import {
CreateVmWizard,
BasicMigrationDialog,
TEMPLATE_TYPE_LABEL,
TEMPLATE_OS_LABEL,
VmStatus,
getVmStatus,
VM_STATUS_ALL,
VM_STATUS_TO_TEXT,
} from 'kubevirt-web-ui-components';

import { CreateVmWizard, BasicMigrationDialog, TEMPLATE_TYPE_LABEL, TEMPLATE_OS_LABEL } from 'kubevirt-web-ui-components';
import VmConsolesConnected from './vmconsoles';
import { Nic } from './nic';
import { Disk } from './disk';
import { DASHES } from './utils/constants';
import { DASHES, IMPORTER_DV_POD_PREFIX, VIRT_LAUNCHER_POD_PREFIX } from './utils/constants';
import { resourceLauncher } from './utils/resourceLauncher';
import { showError } from './utils/showErrors';

const VMHeader = props => <ListHeader>
<ColHead {...props} className="col-lg-2 col-md-2 col-sm-2 col-xs-6" sortField="metadata.name">Name</ColHead>
<ColHead {...props} className="col-lg-2 col-md-2 col-sm-2 col-xs-6" sortField="metadata.namespace">Namespace</ColHead>
<ColHead {...props} className="col-lg-2 col-md-2 col-sm-2 hidden-xs" sortField="spec.running">State</ColHead>
<ColHead {...props} className="col-lg-2 col-md-2 col-sm-2 hidden-xs" sortField="metadata.phase">Phase</ColHead>
<ColHead {...props} className="col-lg-2 col-md-2 col-sm-2 hidden-xs">Virtual Machine Instance</ColHead>
<ColHead {...props} className="col-lg-2 col-md-2 col-sm-2 hidden-xs">Pod</ColHead>
</ListHeader>;
Expand Down Expand Up @@ -78,25 +95,28 @@ const menuActionMigrate = (kind, vm) => ({

const menuActions = [menuActionStart, menuActionRestart, menuActionMigrate, Kebab.factory.Delete];

const getPod = (vm, resources, podNamePrefix) => {
const podFlatten = getFlattenForKind(PodModel.kind);
const podData = podFlatten(resources);
return findPod(podData, vm.metadata.name, podNamePrefix);
};

const getMigration = (vm, resources) => {
const flatten = getFlattenForKind(VirtualMachineInstanceMigrationModel.kind);
const migrationData = flatten(resources);
return findVMIMigration(migrationData, vm.metadata.name);
};

const StateColumn = props => {
if (props.loaded){
const vm = props.flatten(props.resources);
if (vm){
return getVmStatus(vm);
if (vm) {
return <VmStatus vm={vm} launcherPod={getPod(vm, props.resources, VIRT_LAUNCHER_POD_PREFIX)} importerPod={getPod(vm, props.resources, IMPORTER_DV_POD_PREFIX)} migration={getMigration(vm, props.resources)} />;
}
}
return DASHES;
};

const PhaseColumn = props => {
if (props.loaded){
const resources = props.flatten(props.resources);
const vmi = props.filter(resources);
return _.get(vmi, 'status.phase', DASHES);
}
return DASHES;
};

const FirehoseResourceLink = props => {
if (props.loaded) {
const data = props.flatten(props.resources);
Expand All @@ -121,6 +141,7 @@ export const VMRow = ({obj: vm}) => {
const vmResource = getResourceKind(VirtualMachineModel, vm.metadata.name, true, vm.metadata.namespace, false);
const vmiResources = getResourceKind(VirtualMachineInstanceModel, vm.metadata.name, true, vm.metadata.namespace, true, getLabelMatcher(vm));
const podResources = getResourceKind(PodModel, undefined, true, vm.metadata.namespace, true, getLabelMatcher(vm));
const migrationResources = getResourceKind(VirtualMachineInstanceMigrationModel, undefined, true, vm.metadata.namespace, false); // https://kubevirt.io/api-reference/master/definitions.html#_v1_virtualmachineinstancemigration

return <ResourceRow obj={vm}>
<div className="col-lg-2 col-md-2 col-sm-2 col-xs-6">
Expand All @@ -130,23 +151,18 @@ export const VMRow = ({obj: vm}) => {
<ResourceLink kind={NamespaceModel.kind} name={vm.metadata.namespace} title={vm.metadata.namespace} />
</div>
<div className="col-lg-2 col-md-2 col-sm-2 hidden-xs">
<Firehose resources={[vmResource]} flatten={getFlattenForKind(VirtualMachineModel.kind)}>
<Firehose resources={[vmResource, podResources, migrationResources]} flatten={getFlattenForKind(VirtualMachineModel.kind)}>
<StateColumn />
</Firehose>
</div>
<div className="col-lg-2 col-md-2 col-sm-2 hidden-xs">
<Firehose resources={[vmiResources]} flatten={getFlattenForKind(VirtualMachineInstanceModel.kind)}>
<PhaseColumn filter={data => findVMI(data, vm.metadata.name)} />
</Firehose>
</div>
<div className="col-lg-2 col-md-2 col-sm-2 hidden-xs">
<Firehose resources={[vmiResources]} flatten={getFlattenForKind(VirtualMachineInstanceModel.kind)}>
<FirehoseResourceLink filter={data => findVMI(data, vm.metadata.name)} />
</Firehose>
</div>
<div className="col-lg-2 col-md-2 col-sm-2 hidden-xs">
<Firehose resources={[podResources]} flatten={getFlattenForKind(PodModel.kind)}>
<FirehoseResourceLink filter={data => findPod(data, vm.metadata.name)} />
<FirehoseResourceLink filter={data => findPod(data, vm.metadata.name, VIRT_LAUNCHER_POD_PREFIX)} />
</Firehose>
</div>
<div className="co-kebab-wrapper">
Expand All @@ -172,12 +188,6 @@ const VMStatus = (props) => {
<StateColumn />
</Firehose>
</dd>
<dt>Phase:</dt>
<dd>
<Firehose resources={[vmiResources]} flatten={getFlattenForKind(VirtualMachineInstanceModel.kind)}>
<PhaseColumn filter={data => findVMI(data, props.vm.metadata.name)} />
</Firehose>
</dd>
<dt>VM Instance:</dt>
<dd>
<Firehose resources={[vmiResources]} flatten={getFlattenForKind(VirtualMachineInstanceModel.kind)}>
Expand All @@ -187,7 +197,7 @@ const VMStatus = (props) => {
<dt>Pod:</dt>
<dd>
<Firehose resources={[podResources]} flatten={getFlattenForKind(PodModel.kind)}>
<FirehoseResourceLink filter={data => findPod(data, props.vm.metadata.name)} />
<FirehoseResourceLink filter={data => findPod(data, props.vm.metadata.name, VIRT_LAUNCHER_POD_PREFIX)} />
</Firehose>
</dd>
</dl>
Expand Down Expand Up @@ -370,12 +380,9 @@ const openNewVmWizard = activeNamespace => {

const filters = [{
type: 'vm-status',
selected: [ 'Running', 'Stopped' ],
selected: VM_STATUS_ALL,
reducer: getVmStatus,
items: [
{ id: 'Running', title: 'Running' },
{ id: 'Stopped', title: 'Stopped' },
],
items: VM_STATUS_ALL.map(status => ({ id: status, title: VM_STATUS_TO_TEXT[status] }) ),
}];

export const VirtualMachinesPage = connect(
Expand Down
15 changes: 15 additions & 0 deletions frontend/public/kubevirt/models/vm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// eslint-disable-next-line no-unused-vars
import { K8sKind } from '../../module/k8s';

// TODO: reuse following from kubevirt-web-ui-components to avoid duplicity

export const VirtualMachineModel: K8sKind = {
label: 'Virtual Machine',
labelPlural: 'Virtual Machines',
Expand Down Expand Up @@ -65,3 +67,16 @@ export const NetworkAttachmentDefinitionModel: K8sKind = {
kind: 'NetworkAttachmentDefinition',
id: 'network-attachment-definition',
};

export const VirtualMachineInstanceMigrationModel: K8sKind = {
label: 'Virtual Machine Instance Migration',
labelPlural: 'Virtual Machine Instance Migrations',
apiVersion: 'v1alpha2',
path: 'virtualmachineinstancemigrations',
apiGroup: 'kubevirt.io',
plural: 'virtualmachineinstancemigrations',
abbr: 'VMIM',
namespaced: true,
kind: 'VirtualMachineInstanceMigration',
id: 'virtualmachineinstancemigration',
};