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

Commit

Permalink
[OKD-Core] Do not add maintenance actions if NodeMaintenance CRD is m…
Browse files Browse the repository at this point in the history
  • Loading branch information
rawagner authored and mareklibra committed Apr 30, 2019
1 parent 1bf7ab7 commit 230c1a2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
18 changes: 8 additions & 10 deletions frontend/public/components/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import * as React from 'react';

import { nodeStatus, makeNodeSchedulable, K8sResourceKind, referenceForModel } from '../module/k8s';
import { ResourceEventStream } from './events';
import { ColHead, DetailsPage, List, ListHeader, ListPage, ResourceRow } from './factory';
import { ColHead, List, ListHeader, ListPage, ResourceRow } from './factory';
import { configureUnschedulableModal } from './modals';
import { PodsPage } from './pod';
import { Kebab, navFactory, LabelList, ResourceKebab, SectionHeading, ResourceLink, Timestamp, units, cloudProviderNames, cloudProviderID, pluralize } from './utils';
import { Kebab, navFactory, LabelList, SectionHeading, ResourceLink, Timestamp, units, cloudProviderNames, cloudProviderID, pluralize } from './utils';
import { Line, requirePrometheus } from './graphs';
import { MachineModel, NodeModel, NodeMaintenance } from '../models';
import { MachineModel, NodeModel } from '../models';
import { CamelCaseWrap } from './utils/camel-case-wrap';
import { NodeStatusWithMaintenanceConnected, maintenanceActions } from '../kubevirt/components/node/node';
import { getResource } from 'kubevirt-web-ui-components';
import { NodeStatusWithMaintenanceConnected, NodeMaintenanceKebab, NodeDetailsPageWithMaintenance } from '../kubevirt/components/node/node';

const MarkAsUnschedulable = (kind, obj) => ({
label: 'Mark as Unschedulable',
Expand All @@ -28,9 +27,9 @@ const MarkAsSchedulable = (kind, obj) => ({
});

const { ModifyLabels, ModifyAnnotations, Edit } = Kebab.factory;
const menuActions = [MarkAsSchedulable, MarkAsUnschedulable, ModifyLabels, ModifyAnnotations, Edit, ...maintenanceActions];
const menuActions = [MarkAsSchedulable, MarkAsUnschedulable, ModifyLabels, ModifyAnnotations, Edit];

const NodeKebab = ({node}) => <ResourceKebab actions={menuActions} kind="Node" resource={node} resources={[getResource(NodeMaintenance)]} />;
const NodeKebab = ({node}) => <NodeMaintenanceKebab actions={menuActions} kind="Node" resource={node} />;

const getMachine = (node: K8sResourceKind) => {
const machine = _.get(node, 'metadata.annotations["machine.openshift.io/machine"]');
Expand Down Expand Up @@ -245,9 +244,8 @@ const pages = [
pods(({obj}) => <PodsPage showTitle={false} fieldSelector={`spec.nodeName=${obj.metadata.name}`} />),
events(ResourceEventStream),
];
export const NodesDetailsPage = props => <DetailsPage
export const NodesDetailsPage = props => <NodeDetailsPageWithMaintenance
{...props}
menuActions={menuActions}
pages={pages}
resources={[getResource(NodeMaintenance)]}
menuActions={menuActions}
/>;
35 changes: 32 additions & 3 deletions frontend/public/kubevirt/components/node/node.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as React from 'react';
import { connect } from 'react-redux';
import { getResource, findNodeMaintenance, getDeletionTimestamp, NodeStatus } from 'kubevirt-web-ui-components';

import { k8sKill, nodeStatus } from '../../module/okdk8s';
import { NodeMaintenance } from '../../models';
import { LoadingInline, StatusIcon, Timestamp } from '../utils/okdutils';
import { LoadingInline, StatusIcon, Timestamp, ResourceKebab } from '../utils/okdutils';
import { startMaintenanceModal } from './node-maintenance-modal';
import { WithResources } from '../utils/withResources';
import { DetailsPage } from '../factory/okdfactory';

const statusResourceMap = {
const maintenanceResourceMap = {
maintenances: {
resource: getResource(NodeMaintenance),
},
Expand All @@ -31,7 +33,7 @@ const StopMaintenanceAction = (kind, obj, actionArgs) => {
export const maintenanceActions = [StartMaintenanceAction, StopMaintenanceAction];

export const NodeStatusWithMaintenanceConnected = ({node}) => (
<WithResources resourceMap={statusResourceMap}>
<WithResources resourceMap={maintenanceResourceMap}>
<NodeStatusWithMaintenance node={node} />
</WithResources>
);
Expand All @@ -43,3 +45,30 @@ const NodeStatusWithMaintenance = ({node, maintenances}) => {
const maintenance = findNodeMaintenance(node, maintenances);
return maintenance ? <NodeStatus node={node} maintenances={maintenances} TimestampComponent={Timestamp} /> : <StatusIcon status={nodeStatus(node)} />;
};

const stateToProps = ({k8s}) => ({
nodeMaintenanceExists: !!k8s.getIn(['RESOURCES', 'models', NodeMaintenance.kind]),
});

export const NodeDetailsPageWithMaintenance = connect(stateToProps)(({nodeMaintenanceExists, menuActions, ...rest}) => {
const resources = nodeMaintenanceExists ? [getResource(NodeMaintenance)] : null;

const maintenanceMenuActions = nodeMaintenanceExists ? [...menuActions, ...maintenanceActions] : menuActions;

return (
<DetailsPage
{...rest}
menuActions={maintenanceMenuActions}
resources={resources}
/>
);
});

const ConnectedNodeMaintenanceKebab = connect(stateToProps)(({nodeMaintenanceExists, actions, ...rest }) => {
const maintenanceMenuActions = nodeMaintenanceExists ? [...actions, ...maintenanceActions] : actions;
const resources = nodeMaintenanceExists ? [getResource(NodeMaintenance)] : [];

return <ResourceKebab {...rest} actions={maintenanceMenuActions} resources={resources} />;
});

export const NodeMaintenanceKebab = props => <ConnectedNodeMaintenanceKebab {...props} />;

0 comments on commit 230c1a2

Please sign in to comment.