Skip to content
This repository was 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 1 commit
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
14 changes: 10 additions & 4 deletions frontend/public/metalkube/components/host/host.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
BaremetalHostRole,
BaremetalHostStatus,
getHostMachineName,
getHostBmcAddress,
getResource,
getSimpleHostStatus,
} from 'kubevirt-web-ui-components';

Expand All @@ -19,7 +21,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 @@ -56,12 +58,11 @@ const HostHeader = props => (
const HostRow = ({ obj: host }) => {
const {
metadata: { name, namespace, uid },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also use selectors for these.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

spec: {
bmc: { address },
},
} = host;

const machineName = getHostMachineName(host);
const address = getHostBmcAddress(host)

const machineResource = {
kind: referenceForModel(MachineModel),
name: machineName,
Expand All @@ -77,6 +78,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 +109,7 @@ const HostRow = ({ obj: host }) => {
actions={menuActions}
kind={BaremetalHostModel.kind}
resource={host}
resources={hostResources}
/>
</div>
</ResourceRow>
Expand Down
46 changes: 38 additions & 8 deletions frontend/public/metalkube/components/host/menu-actions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
import {
getHostPoweredOn,
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';

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: () => makeNodeSchedulable(node),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't there be a yes/no dialog?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

};
};

const menuActionDrainHost = (kind, host) => ({
hidden: false, // TODO(jtomasek): use canDrainHost selector
label: 'Drain Host',
const menuActionPowerOn = (kind, host) => ({
hidden: getHostPoweredOn(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: !getHostPoweredOn(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);