Skip to content

Commit

Permalink
convert probe data values from string to number type
Browse files Browse the repository at this point in the history
  • Loading branch information
debsmita1 committed Jun 16, 2021
1 parent 65a5227 commit 2d52e05
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 44 deletions.
2 changes: 1 addition & 1 deletion frontend/packages/dev-console/locales/en/devconsole.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"Edit health checks": "Edit health checks",
"Add health checks": "Add health checks",
"Learn more": "Learn more",
"Health checks for": "Health checks for",
"Health checks for &nbsp;<1></1>": "Health checks for &nbsp;<1></1>",
"Container": "Container",
"Container not found": "Container not found",
"Readiness probe": "Readiness probe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { ExternalLinkAltIcon } from '@patternfly/react-icons';
import { FormikProps, FormikValues } from 'formik';
import * as _ from 'lodash';
import Helmet from 'react-helmet';
import { useTranslation } from 'react-i18next';
import { useTranslation, Trans } from 'react-i18next';
import {
ContainerDropdown,
history,
PageHeading,
ResourceLink,
ResourceIcon,
openshiftHelpBase,
} from '@console/internal/components/utils';
import { ContainerModel } from '@console/internal/models';
Expand Down Expand Up @@ -93,19 +92,21 @@ const AddHealthChecks: React.FC<FormikProps<FormikValues> & AddHealthChecksProps
</>
}
/>
<div className="odc-add-health-checks__body">
<p>
{t('devconsole~Health checks for')} &nbsp;
<ResourceLink
kind={referenceFor(resource)}
name={name}
namespace={namespace}
title={name}
inline
/>
</p>
<Form onSubmit={!viewOnly ? handleSubmit : undefined}>
<div>
<Form onSubmit={!viewOnly ? handleSubmit : undefined}>
<div className="odc-add-health-checks__body">
<p>
<Trans t={t} ns="devconsole">
Health checks for &nbsp;
<ResourceLink
kind={referenceFor(resource)}
name={name}
namespace={namespace}
title={name}
inline
/>
</Trans>
</p>
<p>
{t('devconsole~Container')} &nbsp;
{_.size(containers) > 1 ? (
<ContainerDropdown
Expand All @@ -114,24 +115,27 @@ const AddHealthChecks: React.FC<FormikProps<FormikValues> & AddHealthChecksProps
onChange={handleSelectContainer}
/>
) : (
<>
<ResourceIcon kind={ContainerModel.kind} />
{containers[0].name}
</>
<ResourceLink
kind={ContainerModel.kind}
name={containers[0].name}
linkTo={false}
inline
/>
)}
</div>
</p>
<br />
<HealthChecks resourceType={getResourcesType(resource)} />
<FormFooter
handleReset={handleReset}
errorMessage={status && status?.errors?.json?.message}
isSubmitting={isSubmitting}
submitLabel={healthCheckAdded ? t('devconsole~Save') : t('devconsole~Add')}
disableSubmit={isFormClean || !dirty || !_.isEmpty(errors) || isSubmitting}
resetLabel={t('devconsole~Cancel')}
hideSubmit={viewOnly}
/>
</Form>
</div>
</div>
<FormFooter
handleReset={handleReset}
errorMessage={status && status?.errors?.json?.message}
isSubmitting={isSubmitting}
submitLabel={healthCheckAdded ? t('devconsole~Save') : t('devconsole~Add')}
disableSubmit={isFormClean || !dirty || !_.isEmpty(errors) || isSubmitting}
resetLabel={t('devconsole~Cancel')}
hideSubmit={viewOnly}
/>
</Form>
</HealthCheckContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,44 @@ export const enabledProbeData = {
timeoutSeconds: 1,
},
};

export const healthChecksFormInputData = {
healthChecks: {
readinessProbe: {
showForm: false,
enabled: true,
modified: false,
data: {
failureThreshold: '3',
requestType: RequestType.HTTPGET,
httpGet: {
scheme: 'HTTPS',
path: '/tmp/healthy',
port: 8080,
httpHeaders: [{ name: 'custom-header', value: 'value' }],
},
tcpSocket: {
port: 8080,
},
exec: { command: [''] },
initialDelaySeconds: '0',
periodSeconds: '10',
timeoutSeconds: '1',
successThreshold: '1',
},
},
livenessProbe: healthChecksDefaultValues,
startupProbe: {
showForm: false,
enabled: true,
modified: false,
data: {
...healthChecksDefaultValues.data,
requestType: RequestType.TCPSocket,
tcpSocket: {
port: 8081,
},
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { HealthCheckProbeData, RequestType, HealthChecksProbeType } from './heal

export const constructProbeData = (data: HealthCheckProbeData, resourceType?: Resources) => {
const probeData = {
...(data.failureThreshold && { failureThreshold: data.failureThreshold }),
...(data.successThreshold && { successThreshold: data.successThreshold }),
...(data.failureThreshold && { failureThreshold: _.toInteger(data.failureThreshold) }),
...(data.successThreshold && { successThreshold: _.toInteger(data.successThreshold) }),
...(data.requestType === RequestType.ContainerCommand && {
exec: data.exec,
}),
Expand All @@ -26,10 +26,10 @@ export const constructProbeData = (data: HealthCheckProbeData, resourceType?: Re
},
}),
...(data.initialDelaySeconds && {
initialDelaySeconds: data.initialDelaySeconds,
initialDelaySeconds: _.toInteger(data.initialDelaySeconds),
}),
...(data.periodSeconds && { periodSeconds: data.periodSeconds }),
...(data.timeoutSeconds && { timeoutSeconds: data.timeoutSeconds }),
...(data.periodSeconds && { periodSeconds: _.toInteger(data.periodSeconds) }),
...(data.timeoutSeconds && { timeoutSeconds: _.toInteger(data.timeoutSeconds) }),
};
return probeData;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export enum RequestType {
ContainerCommand = 'command',
TCPSocket = 'tcpSocket',
}

export interface HealthCheckProbeData {
failureThreshold: number;
failureThreshold: number | string;
requestType?: string;
httpGet?: {
scheme: string;
Expand All @@ -25,12 +24,11 @@ export interface HealthCheckProbeData {
port: number;
};
exec?: { command?: string[] };
initialDelaySeconds: number;
periodSeconds: number;
timeoutSeconds: number;
successThreshold: number;
initialDelaySeconds: number | string;
periodSeconds: number | string;
timeoutSeconds: number | string;
successThreshold: number | string;
}

export interface HealthCheckProbe {
showForm?: boolean;
enabled?: boolean;
Expand Down

0 comments on commit 2d52e05

Please sign in to comment.