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

Add 'Start Maintenance' action to Host #301

Merged
merged 2 commits into from
Apr 15, 2019
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
24 changes: 16 additions & 8 deletions frontend/public/metalkube/components/host/host.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
BaremetalHostRole,
BaremetalHostStatus,
getHostMachineName,
getHostBmcAddress,
getName,
getNamespace,
getResource,
getSimpleHostStatus,
getUid,
} from 'kubevirt-web-ui-components';

import { actions, referenceForModel } from '../../../kubevirt/module/okdk8s';
Expand All @@ -19,7 +24,7 @@ import {
import { ResourceLink, ResourceKebab } from '../utils/okdutils';
import MachineCell from './machine-cell';
import { WithResources } from '../../../kubevirt/components/utils/withResources';
import { BaremetalHostModel, MachineModel } from '../../models';
import { BaremetalHostModel, MachineModel, NodeModel } from '../../models';
import { menuActions } from './menu-actions';
import { openCreateBaremetalHostModal } from '../modals/create-host-modal';

Expand Down Expand Up @@ -54,14 +59,12 @@ const HostHeader = props => (
);

const HostRow = ({ obj: host }) => {
const {
metadata: { name, namespace, uid },
spec: {
bmc: { address },
},
} = host;

const name = getName(host);
const namespace = getNamespace(host);
const uid = getUid(host);
const machineName = getHostMachineName(host);
const address = getHostBmcAddress(host);

const machineResource = {
kind: referenceForModel(MachineModel),
name: machineName,
Expand All @@ -77,6 +80,10 @@ const HostRow = ({ obj: host }) => {
},
};

const hostResources = machineName
? [machineResource, getResource(NodeModel, { namespaced: false })]
: [];

return (
<ResourceRow obj={host}>
<div className={nameColumnClasses}>
Expand Down Expand Up @@ -104,6 +111,7 @@ const HostRow = ({ obj: host }) => {
actions={menuActions}
kind={BaremetalHostModel.kind}
resource={host}
resources={hostResources}
/>
</div>
</ResourceRow>
Expand Down
52 changes: 44 additions & 8 deletions frontend/public/metalkube/components/host/menu-actions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
import {
isHostPoweredOn,
getMachineNode,
canHostStartMaintenance,
canHostStopMaintenance,
} from 'kubevirt-web-ui-components';

import { makeNodeSchedulable } from '../../../module/k8s';
import { Kebab } from '../utils/okdutils';
import { startMaintenanceModal } from '../modals/start-maintenance-modal';
import { confirmModal } from '../../../components/modals/confirm-modal';

const menuActionStartMaintenance = (kind, host, { machine, Node: nodes }) => {
const node = getMachineNode(nodes, machine);
return {
hidden: !canHostStartMaintenance(node),
label: 'Start Maintenance',
callback: () => startMaintenanceModal({ resource: node }),
};
};

const menuActionStopMaintenance = (kind, host, { machine, Node: nodes }) => {
const node = getMachineNode(nodes, machine);
return {
hidden: !canHostStopMaintenance(node),
label: 'Stop Maintenance',
callback: () =>
confirmModal({
executeFn: () => makeNodeSchedulable(node),
title: 'Stop Maintenance',
message: 'Node will exit maintenance and start taking workloads.',
}),
};
};

const menuActionDrainHost = (kind, host) => ({
hidden: false, // TODO(jtomasek): use canDrainHost selector
label: 'Drain Host',
const menuActionPowerOn = (kind, host) => ({
hidden: isHostPoweredOn(host),
label: 'Power On',
callback: () => {
// eslint-disable-next-line no-console
console.log(host);
},
});

const menuActionStartMaintenance = (kind, host) => ({
hidden: false,
label: 'Start Maintenance',
const menuActionPowerOff = (kind, host) => ({
hidden: !isHostPoweredOn(host),
label: 'Power Off',
callback: () => {
// eslint-disable-next-line no-console
console.log(host);
},
});

export const menuActions = [
menuActionDrainHost,
menuActionPowerOn,
menuActionPowerOff,
menuActionStartMaintenance,
...Kebab.factory.common,
menuActionStopMaintenance,
Kebab.factory.Edit,
Kebab.factory.Delete,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';

import { makeNodeUnschedulable } from '../../../module/k8s';
import {
createModalLauncher,
ModalTitle,
ModalBody,
ModalSubmitFooter,
} from '../factory/okdfactory';
import { PromiseComponent } from '../utils/okdutils';

class StartMaintenanceModal extends PromiseComponent {
constructor(props) {
super(props);
this._submit = this._submit.bind(this);
this._cancel = this.props.cancel.bind(this);
}

_submit(event) {
event.preventDefault();

this.handlePromise(makeNodeUnschedulable(this.props.resource))
.then(this.props.close)
.catch(error => {
throw error;
});
}

render() {
return (
<form onSubmit={this._submit} name="form" className="modal-content ">
<ModalTitle>Start Maintenance</ModalTitle>
<ModalBody>
<p>
All managed workloads will be moved off of this host. New workloads
and data will not be added to this host until maintenance is
stopped.
</p>
<p>
If the host does not exit maintenance within{' '}
<strong>30 minutes</strong>, the cluster will automatically rebuild
the host&apos;s data using replicated copies
</p>
</ModalBody>
<ModalSubmitFooter
errorMessage={this.state.errorMessage}
inProgress={this.state.inProgress}
submitText="Start Maintenance"
cancel={this._cancel}
/>
</form>
);
}
}

StartMaintenanceModal.propTypes = {
resource: PropTypes.object.isRequired,
};

export const startMaintenanceModal = createModalLauncher(StartMaintenanceModal);