Skip to content

Commit

Permalink
Adding i18n for missed HPA form
Browse files Browse the repository at this point in the history
  • Loading branch information
zherman0 committed Apr 26, 2021
1 parent b3e7ea0 commit 47c306c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
9 changes: 9 additions & 0 deletions frontend/packages/dev-console/locales/en/devconsole.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@
"Add command": "Add command",
"argument": "argument",
"The command to run inside the Container.": "The command to run inside the Container.",
"CPU and memory resource limits must be set if you want to use CPU and memory utilization. The HorizontalPodAutoscaler will not have CPU or memory metrics until resource limits are set.": "CPU and memory resource limits must be set if you want to use CPU and memory utilization. The HorizontalPodAutoscaler will not have CPU or memory metrics until resource limits are set.",
"CPU resource limits must be set if you want to use CPU utilization. The HorizontalPodAutoscaler will not have CPU metrics until resource limits are set.": "CPU resource limits must be set if you want to use CPU utilization. The HorizontalPodAutoscaler will not have CPU metrics until resource limits are set.",
"Memory resource limits must be set if you want to use memory utilization. The HorizontalPodAutoscaler will not have memory metrics until resource limits are set.": "Memory resource limits must be set if you want to use memory utilization. The HorizontalPodAutoscaler will not have memory metrics until resource limits are set.",
"Cannot create a HorizontalPodAutoscaler with no valid metrics.": "Cannot create a HorizontalPodAutoscaler with no valid metrics.",
"CPU and memory utilization cannot be used currently.": "CPU and memory utilization cannot be used currently.",
"CPU utilization cannot be used currently.": "CPU utilization cannot be used currently.",
"Memory utilization cannot be used currently.": "Memory utilization cannot be used currently.",
"Note: Some fields may not be represented in this form view. Please select \"YAML view\" for full control.": "Note: Some fields may not be represented in this form view. Please select \"YAML view\" for full control.",
"Name": "Name",
"Minimum Pods": "Minimum Pods",
Expand All @@ -183,6 +190,8 @@
"Resource": "Resource",
"This resource is not available": "This resource is not available",
"This is not a supported in-context type": "This is not a supported in-context type",
"{{label}} Utilization": "{{label}} Utilization",
"{{label}} request and limit must be set before {{label}} utilization can be set.": "{{label}} request and limit must be set before {{label}} utilization can be set.",
"Name must consist of lower-case letters, numbers and hyphens. It must start with a letter and end with a letter or number.": "Name must consist of lower-case letters, numbers and hyphens. It must start with a letter and end with a letter or number.",
"Cannot be longer than 253 characters.": "Cannot be longer than 253 characters.",
"Minimum Pods must be an integer.": "Minimum Pods must be an integer.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PercentIcon } from '@patternfly/react-icons';
import { HorizontalPodAutoscalerKind, HPAMetric } from '@console/internal/module/k8s';
import { getMetricByType } from './hpa-utils';
import { HPAFormValues, SupportedMetricTypes } from './types';
import { useTranslation } from 'react-i18next';

type HPAUtilizationFieldProps = {
disabled?: boolean;
Expand All @@ -26,12 +27,15 @@ const HPAUtilizationField: React.FC<HPAUtilizationFieldProps> = ({
const value: number = metric?.resource?.target?.averageUtilization;
const thisErrorMetric = errors.formData?.spec?.metrics?.[index] as FormikErrors<HPAMetric>;
const error: string = thisErrorMetric?.resource?.target?.averageUtilization;

const { t } = useTranslation();
return (
<FormGroup
fieldId={`${type}-utilization`}
label={`${label} Utilization`}
helperText={`${label} request and limit must be set before ${label} utilization can be set.`}
label={t('devconsole~{{label}} Utilization', { label })}
helperText={t(
'devconsole~{{label}} request and limit must be set before {{label}} utilization can be set.',
{ label },
)}
helperTextInvalid={error}
validated={error ? 'error' : null}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import { deploymentConfigExamples, deploymentExamples, hpaExamples } from './hpa
import { DeploymentKind, HorizontalPodAutoscalerKind } from '@console/internal/module/k8s';
import { HPAFormValues } from '../types';

jest.mock('i18next', () => ({
default: {
t: jest.fn((key) => key),
},
}));

describe('isCpuUtilizationPossible provides accurate checks', () => {
it('expect an invalid resource to return no', () => {
expect(isCpuUtilizationPossible(null)).toBe(false);
Expand Down
24 changes: 14 additions & 10 deletions frontend/packages/dev-console/src/components/hpa/hpa-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { HorizontalPodAutoscalerModel } from '@console/internal/models';
import { baseTemplates } from '@console/internal/models/yaml-templates';
import { LimitsData } from '@console/shared/src';
import { HPAFormValues, SupportedMetricTypes } from './types';
import i18next from 'i18next';

export const VALID_HPA_TARGET_KINDS = ['Deployment', 'DeploymentConfig'];

Expand All @@ -29,17 +30,20 @@ export const getLimitWarning = (resource: K8sResourceKind): string => {
const limits = getResourceLimitsData(resource);

if (!limits) {
return `CPU and memory resource limits must be set if you want to use CPU and memory utilization. \
The ${HorizontalPodAutoscalerModel.label} will not have CPU or memory metrics until resource limits are set.`;
return i18next.t(
'devconsole~CPU and memory resource limits must be set if you want to use CPU and memory utilization. The HorizontalPodAutoscaler will not have CPU or memory metrics until resource limits are set.',
);
}

if (!hasCpuLimits(limits)) {
return `CPU resource limits must be set if you want to use CPU utilization. \
The ${HorizontalPodAutoscalerModel.label} will not have CPU metrics until resource limits are set.`;
return i18next.t(
'devconsole~CPU resource limits must be set if you want to use CPU utilization. The HorizontalPodAutoscaler will not have CPU metrics until resource limits are set.',
);
}
if (!hasMemoryLimits(limits)) {
return `Memory resource limits must be set if you want to use memory utilization. \
The ${HorizontalPodAutoscalerModel.label} will not have memory metrics until resource limits are set.`;
return i18next.t(
'devconsole~Memory resource limits must be set if you want to use memory utilization. The HorizontalPodAutoscaler will not have memory metrics until resource limits are set.',
);
}

return null;
Expand Down Expand Up @@ -148,16 +152,16 @@ export const getInvalidUsageError = (
const invalidMemory = lackMemoryLimits && metricNames.includes('memory');

if (metricNames.length === 0) {
return `Cannot create a ${HorizontalPodAutoscalerModel.label} with no valid metrics.`;
return i18next.t('devconsole~Cannot create a HorizontalPodAutoscaler with no valid metrics.');
}
if (invalidCPU && invalidMemory) {
return 'CPU and memory utilization cannot be used currently.';
return i18next.t('devconsole~CPU and memory utilization cannot be used currently.');
}
if (invalidCPU) {
return 'CPU utilization cannot be used currently.';
return i18next.t('devconsole~CPU utilization cannot be used currently.');
}
if (invalidMemory) {
return 'Memory utilization cannot be used currently.';
return i18next.t('devconsole~Memory utilization cannot be used currently.');
}

return null;
Expand Down

0 comments on commit 47c306c

Please sign in to comment.