Skip to content

Commit

Permalink
fix pod ring text while scaling up
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesis09 committed Feb 5, 2020
1 parent 3282b64 commit 305ee75
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const PodRing: React.FC<PodRingProps> = ({
const { title, subTitle, titleComponent, subTitleComponent } = podRingLabel(
resourceObj,
isScalingAllowed,
pods,
);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as _ from 'lodash';
import { mockPod } from '../__mocks__/pod-utils-test-data';
import { podRingLabel } from '../pod-ring-utils';
import { ExtPodKind } from '../../types';

describe('pod-ring utils:', () => {
it('should return proper title, subtitle, titleComponent, subtitleComponent for podRingLabel', () => {
let mockData = _.set(_.cloneDeep(mockPod), 'spec.replicas', 2);
mockData = _.set(mockData, 'status.avaiableReplicas', 1);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind])).toEqual({
title: '0',
subtitle: 'scaling to 2',
titleComponent: undefined,
subtitleComponent: undefined,
});
mockData = _.set(mockData, 'status.avaiableReplicas', 2);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind])).toEqual({
title: '2',
subtitle: 'pods',
titleComponent: undefined,
subtitleComponent: undefined,
});
});

it('should return title 0, subtitle scaing to 1 for podRingLabel when the first pod is being created', () => {
let mockData = _.set(_.cloneDeep(mockPod), 'spec.replicas', 1);
mockData = _.set(mockData, 'status.avaiableReplicas', 0);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind])).toEqual({
title: '0',
subtitle: `scaling to 1`,
titleComponent: undefined,
subtitleComponent: undefined,
});
});
});
16 changes: 11 additions & 5 deletions frontend/packages/console-shared/src/utils/pod-ring-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,27 @@ const applyPods = (podsData: PodRingData, dc: PodRCData) => {
return podsData;
};

export const podRingLabel = (obj: K8sResourceKind, canScale: boolean): PodRingLabelType => {
export const podRingLabel = (
obj: K8sResourceKind,
canScale: boolean,
pods: ExtPodKind[],
): PodRingLabelType => {
const {
spec: { replicas },
status: { availableReplicas },
kind,
} = obj;

const isPending = (pods?.length === 1 && pods[0].status?.phase === 'Pending') || replicas;
const pluralize = replicas > 1 || replicas === 0 ? 'pods' : 'pod';
const knativeSubtitle = canScale ? '' : 'to 0';
const scalingSubtitle = !replicas ? knativeSubtitle : `scaling to ${replicas}`;
const title = availableReplicas || (canScale ? 'Scaled to 0' : 'Autoscaled');
const title = availableReplicas || (isPending ? '0' : canScale ? 'Scaled to 0' : 'Autoscaled');
const subTitle = replicas !== availableReplicas ? scalingSubtitle : pluralize;
const titleComponent = !availableReplicas
? React.createElement(ChartLabel, { style: { fontSize: '14px' } })
: undefined;
const titleComponent =
!availableReplicas && !isPending
? React.createElement(ChartLabel, { style: { fontSize: '14px' } })
: undefined;
const subTitleComponent =
kind === 'Revision'
? React.createElement(ChartLabel, { style: { fontSize: '14px' } })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const PodSet: React.FC<PodSetProps> = ({ size, data, x = 0, y = 0, showPodCount
true,
);
const obj = get(data, ['current', 'obj'], null) || data.dc;
const { title, subTitle, titleComponent, subTitleComponent } = podRingLabel(obj, accessAllowed);
const { title, subTitle, titleComponent, subTitleComponent } = podRingLabel(
obj,
accessAllowed,
data?.pods,
);
return (
<>
<PodStatus
Expand Down

0 comments on commit 305ee75

Please sign in to comment.