Skip to content

Commit

Permalink
Add Jobs, CronJobs, and standalone Pods to topology view
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Jun 24, 2020
1 parent 138b518 commit dfc6463
Show file tree
Hide file tree
Showing 23 changed files with 1,776 additions and 176 deletions.
3 changes: 2 additions & 1 deletion frontend/packages/console-shared/src/types/resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { K8sResourceKind, PodKind, RouteKind } from '@console/internal/module/k8s';
import { JobKind, K8sResourceKind, PodKind, RouteKind } from '@console/internal/module/k8s';
import { DEPLOYMENT_STRATEGY } from '../constants';
import { OverviewItemAlerts, PodControllerOverviewItem } from './pod';
import { ClusterServiceVersionKind } from '@console/operator-lifecycle-manager';
Expand Down Expand Up @@ -28,6 +28,7 @@ export type OverviewItem<T = K8sResourceKind> = {
previous?: PodControllerOverviewItem;
routes: RouteKind[];
services: K8sResourceKind[];
jobs?: JobKind[];
status?: React.ReactNode;
ksroutes?: K8sResourceKind[];
configurations?: K8sResourceKind[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import {
sampleKnativeDeployments,
MockKnativeResources,
} from '@console/knative-plugin/src/topology/__tests__/topology-knative-test-data';
import { DaemonSetModel, StatefulSetModel } from '@console/internal/models';
import {
createDaemonSetItems,
createDeploymentConfigItems,
createOverviewItemsForType,
createPodItems,
createStatefulSetItems,
createWorkloadItems,
getPodsForDeploymentConfigs,
getPodsForDeployments,
} from '../resource-utils';
Expand Down Expand Up @@ -92,6 +93,7 @@ enum Keys {
ROLLINGOUT = 'isRollingOut',
OBJ = 'obj',
PODS = 'pods',
JOBS = 'jobs',
PREVIOUS = 'previous',
ROUTES = 'routes',
STATUS = 'status',
Expand Down Expand Up @@ -160,7 +162,8 @@ describe('TransformResourceData', () => {
});

it('should create StatefulSets Items for a provided ss', () => {
const transformedData = createStatefulSetItems(
const transformedData = createWorkloadItems(
StatefulSetModel,
sampleStatefulSets.data,
MockResources,
knativeOverviewResourceUtils,
Expand All @@ -170,17 +173,22 @@ describe('TransformResourceData', () => {
});

it('should not have rc current or previous prop for created StatefulSets Items for a provided ss', () => {
const transformedData = createStatefulSetItems(
const transformedData = createWorkloadItems(
StatefulSetModel,
sampleStatefulSets.data,
MockResources,
knativeOverviewResourceUtils,
);
expect(transformedData).toHaveLength(1);
expect(transformedData[0]).not.toHaveProperties([...dsAndSSKeys, 'previous']);
expect(transformedData[0][Keys.CURRENT]).toBeUndefined();
expect(transformedData[0][Keys.PREVIOUS]).toBeUndefined();
expect(transformedData[0][Keys.ROLLINGOUT]).toBeUndefined();
expect(transformedData[0][Keys.BC]).toHaveLength(0);
});

it('should create DaemonSets Items for a provided ds', () => {
const transformedData = createDaemonSetItems(
const transformedData = createWorkloadItems(
DaemonSetModel,
sampleDaemonSets.data,
MockResources,
knativeOverviewResourceUtils,
Expand All @@ -190,13 +198,17 @@ describe('TransformResourceData', () => {
});

it('should not have rc current or previous prop for created DaemonSets Items for a provided ds', () => {
const transformedData = createDaemonSetItems(
const transformedData = createWorkloadItems(
DaemonSetModel,
sampleDaemonSets.data,
MockResources,
knativeOverviewResourceUtils,
);
expect(transformedData).toHaveLength(1);
expect(transformedData[0]).not.toHaveProperties([...dsAndSSKeys, 'current']);
expect(transformedData[0][Keys.CURRENT]).toBeUndefined();
expect(transformedData[0][Keys.PREVIOUS]).toBeUndefined();
expect(transformedData[0][Keys.ROLLINGOUT]).toBeUndefined();
expect(transformedData[0][Keys.BC]).toHaveLength(0);
});

it('should return pods and replication controllers for a given DeploymentConfig', () => {
Expand Down Expand Up @@ -228,4 +240,24 @@ describe('TransformResourceData', () => {
expect(element).not.toHaveProperties([...podKeys, 'current', 'previous']);
});
});

it('should create standalone Job Items', () => {
const transformedData = createOverviewItemsForType('jobs', MockResources);
expect(transformedData).toHaveLength(1);
expect(transformedData[0][Keys.CURRENT]).toBeUndefined();
expect(transformedData[0][Keys.PREVIOUS]).toBeUndefined();
expect(transformedData[0][Keys.ROLLINGOUT]).toBeUndefined();
expect(transformedData[0][Keys.BC]).toHaveLength(0);
});

it('should create CronJob Items', () => {
const transformedData = createOverviewItemsForType('cronJobs', MockResources);
expect(transformedData).toHaveLength(1);
expect(transformedData[0][Keys.CURRENT]).toBeUndefined();
expect(transformedData[0][Keys.PREVIOUS]).toBeUndefined();
expect(transformedData[0][Keys.ROLLINGOUT]).toBeUndefined();
expect(transformedData[0][Keys.BC]).toHaveLength(1);
expect(transformedData[0][Keys.JOBS]).toHaveLength(2);
expect(transformedData[0][Keys.PODS]).toHaveLength(2);
});
});
33 changes: 29 additions & 4 deletions frontend/packages/console-shared/src/utils/pod-ring-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
ReplicationControllerModel,
ReplicaSetModel,
PodModel,
JobModel,
CronJobModel,
} from '@console/internal/models';
import { ChartLabel } from '@patternfly/react-charts';
import {
Expand Down Expand Up @@ -64,8 +66,8 @@ const applyPods = (podsData: PodRingData, dc: PodRCData) => {
return podsData;
};

const pluralizeString = (count: number, singularString: string, expectedString?: string) =>
count && count > 1 ? expectedString || `${singularString}s` : singularString;
const podKindString = (count: number) =>
(count === 1 ? PodModel.label : PodModel.plural).toLowerCase();

const isPendingPods = (
pods: ExtPodKind[],
Expand All @@ -76,6 +78,10 @@ const isPendingPods = (
(!currentPodCount && !!desiredPodCount);

export const getFailedPods = (pods: ExtPodKind[]): number => {
if (!pods?.length) {
return 0;
}

return pods.reduce((acc, currValue) => {
if ([AllPodStatus.CrashLoopBackOff, AllPodStatus.Failed].includes(getPodStatus(currValue))) {
return acc + 1;
Expand Down Expand Up @@ -106,7 +112,7 @@ const getTitleAndSubtitle = (
if (currentPodCount) {
titlePhrase = currentPodCount.toString();
if (currentPodCount === desiredPodCount) {
subTitlePhrase = pluralizeString(currentPodCount, 'pod');
subTitlePhrase = podKindString(currentPodCount);
} else {
subTitlePhrase = `scaling to ${desiredPodCount}`;
longSubtitle = true;
Expand Down Expand Up @@ -167,13 +173,32 @@ export const podRingLabel = (
subTitle = `scaling to ${desiredPodCount}`;
} else {
title = currentPodCount;
subTitle = pluralizeString(currentPodCount, 'pod');
subTitle = podKindString(currentPodCount);
}
return {
title,
subTitle,
titleComponent: getTitleComponent(),
};
case PodModel.kind:
case JobModel.kind:
currentPodCount = 1;
title = currentPodCount;
subTitle = podKindString(currentPodCount);
return {
title,
subTitle,
titleComponent: getTitleComponent(),
};
case CronJobModel.kind:
currentPodCount = pods.length;
title = `${currentPodCount}`;
subTitle = podKindString(currentPodCount);
return {
title,
subTitle,
titleComponent: getTitleComponent(),
};
default:
currentPodCount = (obj.status?.readyReplicas || 0) + failedPodCount;
desiredPodCount = obj.spec?.replicas;
Expand Down

0 comments on commit dfc6463

Please sign in to comment.