Skip to content

Commit

Permalink
adds decorator if any associated Workload pods has type warning
Browse files Browse the repository at this point in the history
  • Loading branch information
invincibleJai committed Jan 23, 2020
1 parent 3607a4d commit df77dd0
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 9 deletions.
Expand Up @@ -242,6 +242,7 @@ Object {
"previous": undefined,
},
"editUrl": "https://github.com/redhat-developer/topology-example",
"eventWarning": false,
"isKnativeResource": false,
"kind": "apps.openshift.io~v1~DeploymentConfig",
"showPodCount": undefined,
Expand Down Expand Up @@ -382,7 +383,7 @@ Object {
],
"revision": undefined,
},
"events": undefined,
"events": Array [],
"isRollingOut": undefined,
"obj": Object {
"apiVersion": "apps.openshift.io/v1",
Expand Down Expand Up @@ -940,6 +941,7 @@ Object {
"previous": undefined,
},
"editUrl": undefined,
"eventWarning": false,
"isKnativeResource": false,
"kind": "apps~v1~Deployment",
"showPodCount": undefined,
Expand Down Expand Up @@ -1243,7 +1245,26 @@ Object {
],
"revision": 1,
},
"events": undefined,
"events": Array [
Object {
"apiVersion": "v1",
"firstTimestamp": "2020-01-23T08:21:06Z",
"involvedObject": Object {
"kind": "Pod",
"name": "analytics-deployment-59dd7c47d4-2jp7t",
"namespace": "testproject3",
"uid": "f5ee90e4-959f-47df-b305-56a78cb047ea",
},
"kind": "Event",
"lastTimestamp": "2020-01-23T10:00:47Z",
"reason": "Started",
"source": Object {
"component": "kubelet",
"host": "ip-10-0-130-190.us-east-2.compute.internal",
},
"type": "Normal",
},
],
"isRollingOut": false,
"obj": Object {
"apiVersion": "apps/v1",
Expand Down Expand Up @@ -1914,6 +1935,7 @@ Object {
"previous": undefined,
},
"editUrl": undefined,
"eventWarning": false,
"isKnativeResource": false,
"kind": "apps~v1~Deployment",
"showPodCount": undefined,
Expand Down Expand Up @@ -2215,7 +2237,7 @@ Object {
],
"revision": 1,
},
"events": undefined,
"events": Array [],
"isRollingOut": false,
"obj": Object {
"apiVersion": "apps/v1",
Expand Down Expand Up @@ -2631,6 +2653,7 @@ Object {
"previous": undefined,
},
"editUrl": undefined,
"eventWarning": false,
"isKnativeResource": false,
"kind": "apps~v1~Deployment",
"showPodCount": undefined,
Expand All @@ -2644,7 +2667,7 @@ Object {
"alerts": Object {},
"buildConfigs": Array [],
"current": undefined,
"events": undefined,
"events": Array [],
"isRollingOut": false,
"obj": Object {
"apiVersion": "apps/v1",
Expand Down
@@ -1,5 +1,5 @@
import { FirehoseResult } from '@console/internal/components/utils';
import { DeploymentKind, PodKind } from '@console/internal/module/k8s';
import { DeploymentKind, PodKind, EventKind } from '@console/internal/module/k8s';
import { Model } from '@console/topology';
import { TopologyDataModel, TopologyDataResources } from '../topology-types';

Expand Down Expand Up @@ -2158,6 +2158,31 @@ export const sampleHelmChartDeploymentConfig = {
},
};

export const sampleEventsResource: FirehoseResult<EventKind[]> = {
loaded: true,
loadError: '',
data: [
{
apiVersion: 'v1',
kind: 'Event',
type: 'Normal',
lastTimestamp: '2020-01-23T10:00:47Z',
reason: 'Started',
firstTimestamp: '2020-01-23T08:21:06Z',
involvedObject: {
kind: 'Pod',
namespace: 'testproject3',
name: 'analytics-deployment-59dd7c47d4-2jp7t',
uid: 'f5ee90e4-959f-47df-b305-56a78cb047ea',
},
source: {
component: 'kubelet',
host: 'ip-10-0-130-190.us-east-2.compute.internal',
},
},
],
};

export const MockResources: TopologyDataResources = {
deployments: sampleDeployments,
deploymentConfigs: sampleDeploymentConfigs,
Expand All @@ -2173,4 +2198,5 @@ export const MockResources: TopologyDataResources = {
pipelines: samplePipeline,
pipelineRuns: samplePipelineRun,
clusterServiceVersions: sampleClusterServiceVersions,
events: sampleEventsResource,
};
Expand Up @@ -154,6 +154,49 @@ describe('TopologyUtils ', () => {
expect((topologyTransformedData[keys[0]].data as WorkloadData).isKnativeResource).toBeFalsy();
});

it('should return false for eventWarning if workloads pods have no events of type warning', () => {
const { topologyTransformedData, keys } = getTranformedTopologyData(MockResources, [
'deploymentConfigs',
'deployments',
]);
expect((topologyTransformedData[keys[0]].data as WorkloadData).eventWarning).toBe(false);
});

it('should return true for eventWarning if workload pods have events of type warning', () => {
const mockResources = {
...MockResources,
events: {
loaded: true,
loadError: '',
data: [
{
apiVersion: 'v1',
kind: 'Event',
type: 'Warning',
lastTimestamp: '2020-01-23T10:00:47Z',
reason: 'BackOff',
firstTimestamp: '2020-01-23T08:21:06Z',
involvedObject: {
kind: 'Pod',
namespace: 'testproject3',
name: 'analytics-deployment-59dd7c47d4-6btjb',
uid: 'f5ee90e4-959f-47df-b305-56a78cb047ea',
},
source: {
component: 'kubelet',
host: 'ip-10-0-130-190.us-east-2.compute.internal',
},
},
],
},
};
const { topologyTransformedData, keys } = getTranformedTopologyData(mockResources, [
'deployments',
'deploymentConfigs',
]);
expect((topologyTransformedData[keys[0]].data as WorkloadData).eventWarning).toBe(true);
});

it('should return a valid pod status for scale to 0', () => {
const { topologyTransformedData } = getTranformedTopologyData(MockKnativeResources, [
'deploymentConfigs',
Expand Down
@@ -1,6 +1,7 @@
.odc-decorator {
color: var(--pf-global--Color--200);
transition: color 0.2s ease;
outline: none;

&__link:hover {
text-decoration: none;
Expand Down
Expand Up @@ -10,7 +10,8 @@ import {
WithContextMenuProps,
} from '@console/topology';
import { Tooltip, TooltipPosition } from '@patternfly/react-core';
import { ExternalLinkAltIcon } from '@patternfly/react-icons';
import { ExternalLinkAltIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
import { global_danger_color_100 as dangerColor } from '@patternfly/react-tokens';
import { routeDecoratorIcon } from '../../../import/render-utils';
import Decorator from './Decorator';
import PodSet from './PodSet';
Expand Down Expand Up @@ -43,7 +44,7 @@ const WorkloadNode: React.FC<WorkloadNodeProps> = ({
const { width, height } = element.getBounds();
const workloadData = element.getData().data;
const size = Math.min(width, height);
const { donutStatus, editUrl, cheEnabled } = workloadData;
const { donutStatus, editUrl, cheEnabled, eventWarning } = workloadData;
const { radius, decoratorRadius } = calculateRadius(size);
const cx = width / 2;
const cy = height / 2;
Expand Down Expand Up @@ -96,6 +97,30 @@ const WorkloadNode: React.FC<WorkloadNodeProps> = ({
</Decorator>
</Tooltip>
),
eventWarning && (
<Tooltip key="monitoring" content="Monitoring" position={TooltipPosition.left}>
<Decorator
x={cx + -radius + decoratorRadius * 0.7}
y={cy + -radius + decoratorRadius * 0.7}
radius={decoratorRadius}
onClick={(e) => {
e.stopPropagation();
element
.getGraph()
.getController()
.fireEvent('selection', [element.getId()]);
}}
>
<g transform={`translate(-${decoratorRadius / 2}, -${decoratorRadius / 2})`}>
<ExclamationCircleIcon
color={dangerColor.value}
style={{ fontSize: decoratorRadius }}
alt="Monitoring"
/>
</g>
</Decorator>
</Tooltip>
),
<BuildDecorator
key="build"
workloadData={workloadData}
Expand Down
@@ -1,7 +1,7 @@
import { ComponentType } from 'react';
import { FirehoseResult, KebabOption } from '@console/internal/components/utils';
import { ExtPodKind, OverviewItem, PodControllerOverviewItem } from '@console/shared';
import { DeploymentKind, K8sResourceKind, PodKind } from '@console/internal/module/k8s';
import { DeploymentKind, K8sResourceKind, PodKind, EventKind } from '@console/internal/module/k8s';
import { ClusterServiceVersionKind } from '@console/operator-lifecycle-manager';
import { Pipeline, PipelineRun } from '../../utils/pipeline-augment';

Expand Down Expand Up @@ -32,7 +32,7 @@ export interface TopologyDataResources {
eventSourceKafka?: FirehoseResult;
clusterServiceVersions?: FirehoseResult;
serviceBindingRequests?: FirehoseResult;
events?: FirehoseResult;
events?: FirehoseResult<EventKind[]>;
}

export interface Node {
Expand Down Expand Up @@ -110,6 +110,7 @@ export interface WorkloadData {
donutStatus: DonutStatusData;
connectedPipeline: ConnectedWorkloadPipeline;
showPodCount?: boolean;
eventWarning?: boolean;
}

export interface DonutStatusData {
Expand Down
Expand Up @@ -103,6 +103,16 @@ export const getRoutesUrl = (resource: OverviewItem): string => {
return getRouteData(ksroutes, resource);
};

/**
* get monitoring status
*/
export const isEventWarning = (resource: OverviewItem): boolean => {
const { events } = resource;
if (!events) return false;
const eventStatus = _.filter(events, ['type', 'Warning']);
return !!eventStatus.length;
};

/**
* create instance of TransformResourceData, return object containing all methods
* @param resources
Expand Down Expand Up @@ -189,6 +199,7 @@ export const createTopologyNodeData = (
dc: deploymentConfig,
},
showPodCount: filters && filters.display.podCount,
eventWarning: isEventWarning(dc),
},
};
};
Expand Down

0 comments on commit df77dd0

Please sign in to comment.