Skip to content

Commit

Permalink
Merge pull request #5373 from rawagner/restart_reboot_mc
Browse files Browse the repository at this point in the history
Bug 1834172: Detect remediation strategy for Machine
  • Loading branch information
openshift-merge-robot committed May 12, 2020
2 parents 5adc246 + dfb34eb commit 2ae5dd7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 21 deletions.
Expand Up @@ -163,8 +163,11 @@ const NodeAlerts: React.FC = () => {

return (
<AlertsBody>
{!!healthCheck && (
<StatusItem Icon={YellowExclamationTriangleIcon} message={msg.CONDITIONS_WARNING}>
{!!healthCheck?.failingHealthCheck && (
<StatusItem
Icon={YellowExclamationTriangleIcon}
message={msg.CONDITIONS_WARNING(healthCheck.reboot)}
>
<HealthChecksLink />
</StatusItem>
)}
Expand Down
Expand Up @@ -5,7 +5,7 @@ import DashboardGrid from '@console/shared/src/components/dashboard/DashboardGri
import { NodeKind } from '@console/internal/module/k8s';
import { LimitRequested } from '@console/shared/src/components/dashboard/utilization-card/UtilizationItem';

import { NodeDashboardContext } from './NodeDashboardContext';
import { NodeDashboardContext, HealthCheck } from './NodeDashboardContext';
import InventoryCard from './InventoryCard';
import DetailsCard from './DetailsCard';
import StatusCard from './StatusCard';
Expand Down Expand Up @@ -51,7 +51,7 @@ export const reducer = (state: NodeDashboardState, action: NodeDashboardAction)
};
}
case ActionType.HEALTH_CHECK: {
if (action.payload === state.healthCheck) {
if (_.isEqual(action.payload, state.healthCheck)) {
return state;
}
return {
Expand Down Expand Up @@ -89,7 +89,7 @@ const NodeDashboard: React.FC<NodeDashboardProps> = ({ obj }) => {
[],
);
const setHealthCheck = React.useCallback(
(payload: boolean) => dispatch({ type: ActionType.HEALTH_CHECK, payload }),
(payload: HealthCheck) => dispatch({ type: ActionType.HEALTH_CHECK, payload }),
[],
);

Expand Down Expand Up @@ -122,11 +122,11 @@ type NodeDashboardState = {
obj: NodeKind;
cpuLimit: LimitRequested;
memoryLimit: LimitRequested;
healthCheck: boolean;
healthCheck: HealthCheck;
};

type NodeDashboardAction =
| { type: ActionType.CPU_LIMIT; payload: LimitRequested }
| { type: ActionType.MEMORY_LIMIT; payload: LimitRequested }
| { type: ActionType.HEALTH_CHECK; payload: boolean }
| { type: ActionType.HEALTH_CHECK; payload: HealthCheck }
| { type: ActionType.OBJ; payload: NodeKind };
Expand Up @@ -8,12 +8,17 @@ export const NodeDashboardContext = React.createContext<NodeDashboardContext>({
setHealthCheck: () => {},
});

export type HealthCheck = {
failingHealthCheck: boolean;
reboot: boolean;
};

type NodeDashboardContext = {
obj?: NodeKind;
cpuLimit?: LimitRequested;
setCPULimit: (state: LimitRequested) => void;
memoryLimit?: LimitRequested;
setMemoryLimit: (state: LimitRequested) => void;
healthCheck?: boolean;
setHealthCheck: (state: boolean) => void;
healthCheck?: HealthCheck;
setHealthCheck: (state: HealthCheck) => void;
};
Expand Up @@ -38,7 +38,8 @@ export const HealthChecksPopup: React.FC<HealthChecksPopupProps> = ({
conditions = [],
machineHealthChecks,
}) => {
let showRestart: boolean = false;
let conditionFailing: boolean = false;
let reboot: boolean = false;
const grouppedConditions = Object.values(
_.groupBy(
conditions.sort((a, b) => a.type.localeCompare(b.type)),
Expand All @@ -47,7 +48,11 @@ export const HealthChecksPopup: React.FC<HealthChecksPopupProps> = ({
).map((cds) => {
const failing = cds.some((c) => c.failing);
if (failing) {
showRestart = true;
conditionFailing = true;
reboot =
machineHealthChecks?.[0]?.metadata?.annotations?.[
'machine.openshift.io/remediation-strategy'
] === 'external-baremetal';
}
return {
title: cds[0].type,
Expand Down Expand Up @@ -90,14 +95,14 @@ export const HealthChecksPopup: React.FC<HealthChecksPopupProps> = ({
))}
</StatusPopupSection>
)}
{showRestart && (
{conditionFailing && (
<Alert
variant="warning"
isInline
title="Restart pending"
title={`${reboot ? 'Reboot' : 'Reprovision'} pending`}
className="co-node-health__popup-alert"
>
{CONDITIONS_WARNING}
{CONDITIONS_WARNING(reboot)}
</Alert>
)}
{machineHealthChecks?.length > 1 && (
Expand Down Expand Up @@ -204,9 +209,24 @@ export const HealthChecksItem: React.FC = () => {
const healthChecks = useK8sWatchResource<MachineHealthCheckKind[]>(machineHealthChecksResource);
const healthState = getMachineHealth(obj, machine, healthChecks);

setHealthCheck(
healthState.state === HealthState.WARNING && healthState.conditions.some((c) => c.failing),
);
let failingHealthCheck = false;
let reboot = false;
_.forEach(healthState.conditions, (c) => {
if (c.failing) {
failingHealthCheck = true;
reboot =
healthState.matchingHC?.[0]?.metadata?.annotations?.[
'machine.openshift.io/remediation-strategy'
] === 'external-baremetal';
return false;
}
return true;
});

setHealthCheck({
failingHealthCheck,
reboot,
});

return (
<HealthItem title="Health Checks" popupTitle="Health Checks" {...healthState}>
Expand Down
@@ -1,5 +1,7 @@
export const CONDITIONS_WARNING =
'One or more health check remediation conditions have been met. The node will restart automatically.';
export const CONDITIONS_WARNING = (reboot = false) =>
`One or more health check remediation conditions have been met. The node will ${
reboot ? 'reboot' : 'reprovision'
} automatically.`;

export const CPU_LIMIT_REQ_ERROR =
'This node’s CPU resources are overcommitted. The total CPU resource limit of all pods exceeds the node’s total capacity. The total CPU requested is also approaching the node’s capacity. Pod performance will be throttled under high load, and new pods may not be schedulable on this node.';
Expand Down
Expand Up @@ -4,7 +4,10 @@ import DashboardGrid from '@console/shared/src/components/dashboard/DashboardGri
import { NodeKind, K8sResourceKind } from '@console/internal/module/k8s';
import UtilizationCard from '@console/app/src/components/nodes/node-dashboard/UtilizationCard';
import ActivityCard from '@console/app/src/components/nodes/node-dashboard/ActivityCard';
import { NodeDashboardContext } from '@console/app/src/components/nodes/node-dashboard/NodeDashboardContext';
import {
NodeDashboardContext,
HealthCheck,
} from '@console/app/src/components/nodes/node-dashboard/NodeDashboardContext';
import {
reducer,
initialState,
Expand Down Expand Up @@ -49,7 +52,7 @@ const BareMetalNodeDashboard: React.FC<BareMetalNodeDashboardProps> = ({
[],
);
const setHealthCheck = React.useCallback(
(payload: boolean) => dispatch({ type: ActionType.HEALTH_CHECK, payload }),
(payload: HealthCheck) => dispatch({ type: ActionType.HEALTH_CHECK, payload }),
[],
);

Expand Down

0 comments on commit 2ae5dd7

Please sign in to comment.