Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1801295: fix pod ring text while scaling up from 0 #4090

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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,52 @@
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 for podRingLabel', () => {
const podWithReplicas = _.set(mockPod, 'spec.replicas', 2);
const mockData = _.set(podWithReplicas, 'status.availableReplicas', 2);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).title).toEqual(2);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).subTitle).toEqual('pods');
});

it('should return title 0, subtitle scaling to 2 and no titleComponent, subtitleComponent for podRingLabel when scaling from 1 to 2 pods', () => {
const podWithReplicas = _.set(_.cloneDeep(mockPod), 'spec.replicas', 2);
const mockData = _.set(podWithReplicas, 'status.availableReplicas', 1);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).title).toEqual(1);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).subTitle).toEqual('scaling to 2');
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).titleComponent).toEqual(
undefined,
);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).subTitleComponent).toEqual(
undefined,
);
});

it('should return title 0, subtitle scaling to 1 and no titleComponent, subtitleComponent for podRingLabel when the first pod is being created', () => {
const podWithReplicas = _.set(mockPod, 'spec.replicas', 1);
const mockData = _.set(podWithReplicas, 'status.availableReplicas', 0);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).title).toEqual('0');
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).subTitle).toEqual('scaling to 1');
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).titleComponent).toEqual(
undefined,
);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).subTitleComponent).toEqual(
undefined,
);
});

it('should return title 0, subtitle scaling to 1 and no titleComponent, subtitleComponent for podRingLabel when pod count is 1 and status is pending', () => {
const podWithReplicas = _.set(_.cloneDeep(mockPod), 'spec.replicas', 1);
const mockData = _.set(podWithReplicas, 'status.phase', 'Pending');
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).title).toEqual('0');
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).subTitle).toEqual('scaling to 1');
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).titleComponent).toEqual(
undefined,
);
expect(podRingLabel(mockData, true, [mockData as ExtPodKind]).subTitleComponent).toEqual(
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