This repository was archived by the owner on Mar 1, 2024. It is now read-only.
forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 11
Add 'Start Maintenance' action to Host #301
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -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), | ||
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. shouldn't there be a yes/no dialog? 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. 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, | ||
]; |
61 changes: 61 additions & 0 deletions
61
frontend/public/metalkube/components/modals/start-maintenance-modal.jsx
This file contains hidden or 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,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'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); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you can also use selectors for these.
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.
Done