INFRA-4076 | Revert changes due to merge conflict

This commit is contained in:
Ashvin Sharma
2024-12-18 18:33:45 +05:30
parent bab469fd91
commit 552d72ec97
10 changed files with 110 additions and 84 deletions

View File

@@ -213,7 +213,7 @@ const Form = (props: any) => {
.forEach(breached => {
const path = breached.path
.split('/')
.filter(part => part.length > 0)
.filter(part => part.length > 0 && part !== '*')
.map(part => (isNaN(part) ? part : parseInt(part, 10)));
const pathKey = breached.limitPath;

View File

@@ -46,4 +46,5 @@ export const defaultValues = {
'/deployment/instance/minMemory': '512Mi',
'/deployment/instance/cpu': 5,
'/deployment/instance/memory': '4095Mi',
'/deployment/allowEndpoint': [],
};

View File

@@ -3,7 +3,7 @@ import React from 'react';
import { TabPanelProps, TabType } from './Types';
import { FormikProps } from 'formik';
import { AutoCompleteOption } from '@src/types/Types';
import { ZoneElement } from '@src/types/Deployment';
import { CiliumServiceEntry, ZoneElement } from '@src/types/Deployment';
import * as _m from '../models/Manifest';
import {
clusterZoneMapping,
@@ -110,3 +110,19 @@ export const getClusters = (environment: string) => {
}
return [];
};
export const populateServiceEntriesOptions = (
preChangedServiceEntries: CiliumServiceEntry[] | undefined,
serviceEntries: CiliumServiceEntry[],
) => {
const serviceEntriesOptionsMap = preChangedServiceEntries?.reduce((acc, serviceEntry) => {
acc[`${serviceEntry.host}:${serviceEntry.port}`] = serviceEntry?.hashedIdentifier;
return acc;
}, {});
return serviceEntries?.map(serviceEntry => {
return {
...serviceEntry,
hashedIdentifier: serviceEntriesOptionsMap?.[`${serviceEntry.host}:${serviceEntry.port}`],
};
});
};

View File

@@ -1,17 +1,17 @@
import * as React from 'react';
import { FC, useEffect, useState } from 'react';
import React, { FC } from 'react';
import Grid from '@material-ui/core/Grid';
import * as _m from '../../models/Manifest';
import { FormikTextField } from '../../components/common/FormikTextField';
import { FormikAutocomplete } from '../../components/common/FormikAutocomplete';
import { populateServiceEntriesOptions, toMenuItems } from '../FormUtil';
import { Field, useField, useFormikContext } from 'formik';
import { FormControlLabel, makeStyles, styled, TableCell, Tooltip } from '@material-ui/core';
import { useFormikContext, Field, setIn, useField } from 'formik';
import { makeStyles, TableCell, styled, FormControlLabel, Tooltip } from '@material-ui/core';
import { FormikTable } from '../../components/common/FormikTable';
import HealthCheckCard from './HealthCheckCard';
import { cardStyles } from '../Styles';
import AutoscalingCard from './AutoscalingCard';
import CardLayout from '../../components/common/CardLayout';
import { useEffect, useState } from 'react';
import { httpClient } from '../../helper/api-client';
import { FormikCheckbox } from '../../components/common/FormikCheckbox';
import { Cluster } from '../../constants/Cluster';
@@ -20,15 +20,10 @@ import { Environment } from '../../constants/Environment';
import { InfoOutlined } from '@material-ui/icons';
import WarningDialog from '../../components/common/WarningDialog';
import { Manifest } from '@src/types/Manifest';
import {
AP_SOUTH_1A,
AP_SOUTH_1B,
AP_SOUTH_1C,
ciliumEnabledCluster,
} from '@src/coreform/deployment/constants';
import { ciliumEnabledCluster } from '@src/coreform/deployment/constants';
import { CiliumServiceEntry } from '@src/types/Deployment';
import { useSelector } from 'react-redux';
import { RootState } from '@src/store';
import FormikMultiSelect from '@components/common/FormikMultiSelect';
const useStyles = makeStyles({
...cardStyles,
@@ -59,9 +54,6 @@ const useStyles = makeStyles({
infoIcon: {
verticalAlign: 'middle',
},
multiSelectMarginTop: {
marginTop: 10,
},
});
const MarginedFormControlLabel = styled(FormControlLabel)({
@@ -240,21 +232,17 @@ function renderGpu(team: string) {
}
function renderSpotNodeCard(environment: string) {
return <AdvancedDeploymentConfigurationCard environment={environment} />;
if (spotNodeEnabledEnvironments.has(environment)) {
return <SpotNodeCard />;
} else {
return <></>;
}
}
const disablegRPCCheckbox = (values: any, i: number) => {
return values.deployment.exposedPorts[i].name === 'metrics';
};
interface AdvancedDeploymentConfigurationProps {
environment: string;
}
const AdvancedDeploymentConfigurationCard = (
props: AdvancedDeploymentConfigurationProps,
): React.JSX.Element => {
const classes = useStyles();
const SpotNodeCard = () => {
const { values, setFieldValue }: { values: any; setFieldValue: any } = useFormikContext();
const [isSpotNodeEnabled, setIsSpotNodeEnabled] = React.useState(
values.deployment.scheduleOnSpotNodes,
@@ -274,34 +262,20 @@ const AdvancedDeploymentConfigurationCard = (
}, [isSpotNodeEnabled, gpu.value]);
return (
<>
<CardLayout heading={'Advanced Deployment Configuration'}>
<FormikMultiSelect
fullWidth
name={`deployment.zoneAffinity`}
label={'Availability Zones'}
className={classes.multiSelectMarginTop}
>
{toMenuItems([AP_SOUTH_1A, AP_SOUTH_1B, AP_SOUTH_1C])}
</FormikMultiSelect>
{spotNodeEnabledEnvironments.has(props.environment) ? (
<FormControlLabel
control={
<Tooltip title="Spot instances are short lived nodes but are 90% cheaper than on-demand nodes. Useful in saving cost.">
<FormikCheckbox
name={`deployment.scheduleOnSpotNodes`}
onClick={handleSpotNodeToggle}
checked={isSpotNodeEnabled}
/>
</Tooltip>
}
label={'Schedule workload on spot nodes'}
/>
) : (
<></>
)}
</CardLayout>
</>
<CardLayout heading={'Spot Node Configuration'}>
<FormControlLabel
control={
<Tooltip title="Spot instances are short lived nodes but are 90% cheaper than on-demand nodes. Useful in saving cost.">
<FormikCheckbox
name={`deployment.scheduleOnSpotNodes`}
onClick={handleSpotNodeToggle}
checked={isSpotNodeEnabled}
/>
</Tooltip>
}
label={'Schedule workload on spot nodes'}
/>
</CardLayout>
);
};

View File

@@ -98,7 +98,3 @@ export const ciliumEnabledCluster = new Set([
Cluster.LENDING_PROD,
Cluster.IAPL_PROD,
]);
export const AP_SOUTH_1A = 'ap-south-1a';
export const AP_SOUTH_1B = 'ap-south-1b';
export const AP_SOUTH_1C = 'ap-south-1c';

View File

@@ -1,5 +1,6 @@
import _ from 'lodash';
import { toast } from 'react-toastify';
import { getHashedIdentifier } from './changeRequestUtils';
interface ValueWithWeight {
type: string;
@@ -18,6 +19,18 @@ const isObject = input => {
);
};
export const getBreachPath = (
manifestPath: string,
key: string,
index: number,
hasHashedIdentifier: boolean,
): string => {
if (hasHashedIdentifier) {
return `${manifestPath}/${key}/*`;
}
return `${manifestPath}/${key}/${index}`;
};
export const parseValue = str => {
const len = str.length;
const unit = str.substring(len - 2, len);
@@ -156,9 +169,16 @@ const safeMapAccess = (preManifestObject, key) => {
return preManifestObject[key];
};
const safeArrayAccess = (array, idx) => {
if (isUndefined(array)) return undefined;
return array[idx];
const safeArrayAccess = (array, identifier: number | string) => {
if (!Array.isArray(array)) {
return undefined;
}
if (typeof identifier === 'number') {
return array[identifier];
} else if (typeof identifier === 'string') {
return array?.find(obj => obj.hashedIdentifier == identifier);
}
return undefined;
};
const getBreachedLimits = (
@@ -176,17 +196,22 @@ const getBreachedLimits = (
const currentManifestObj = manifestObject[key];
const currentPreManifestObj = safeMapAccess(preManifestObject, key);
if (isTarget(currentLimitObj)) {
if (currentLimitObj.hasOwnProperty('forEach') && currentManifestObj?.length !== undefined) {
if (currentLimitObj.hasOwnProperty('forEach') && currentManifestObj?.length) {
for (let i = 0; i < currentManifestObj.length; i++) {
const obj = currentManifestObj[i];
const isBreach = isChangeRequestRequired(
currentLimitObj['forEach'],
obj,
currentPreManifestObj,
manifestEnv,
);
const path = `${manifestPath}/${key}/${i}`;
if (isBreach && !_.isEqual(obj, safeArrayAccess(currentPreManifestObj, i))) {
const hasHashedIdentifier = currentLimitObj['hasHashedIdentifier'] == true;
const isBreach =
hasHashedIdentifier ||
isChangeRequestRequired(
currentLimitObj['forEach'],
obj,
currentPreManifestObj,
manifestEnv,
);
const path = getBreachPath(manifestPath, key, i, hasHashedIdentifier);
const identifier = hasHashedIdentifier ? getHashedIdentifier(obj, key) : i;
console.log(`path:${path}, limitPath:${limitPath} key:${key} identifier:${identifier}`);
if (isBreach && !_.isEqual(obj, safeArrayAccess(currentPreManifestObj, identifier))) {
const diffObj = {
op: getOp(currentPreManifestObj),
path: path,
@@ -194,7 +219,7 @@ const getBreachedLimits = (
value: obj,
};
if (replaceWithPreviousValue) {
manifestObject[key] = safeArrayAccess(preManifestObject, key);
manifestObject[key] = safeMapAccess(preManifestObject, key);
}
breaches = breaches.concat(diffObj);
}
@@ -208,7 +233,6 @@ const getBreachedLimits = (
);
const path = `${manifestPath}/${key}`;
if (isBreach && currentManifestObj !== currentPreManifestObj) {
console.log(`${path} is changed`);
const obj = {
op: getOp(currentPreManifestObj),
path: path,
@@ -216,12 +240,11 @@ const getBreachedLimits = (
value: currentManifestObj,
};
if (replaceWithPreviousValue) {
manifestObject[key] = safeArrayAccess(preManifestObject, key);
manifestObject[key] = safeMapAccess(preManifestObject, key);
}
breaches = breaches.concat(obj);
}
}
if (!isObject(currentLimitObj)) return breaches;
for (const nextKey in currentLimitObj) {
const nextManifestPath = `${manifestPath}/${key}`;
@@ -292,6 +315,7 @@ const getBreachedValues = (
),
);
}
console.log('Breached values:', breaches);
return breaches;
};

View File

@@ -0,0 +1,8 @@
export const getHashedIdentifier = (obj, key: string): string => {
switch (key) {
case 'allowEndpoint':
return btoa(`${obj?.host}:${obj?.port}`);
default:
return '';
}
};

View File

@@ -12,7 +12,6 @@ import { DEFAULT_ELASTIC_SEARCH_VERSION } from '../constants/ElasticSearchConsta
import { LATEST_EC_VERSION } from '@src/coreform/elasticcache/constant';
import { FormType } from '@components/manifest/ShowSelectedForm';
import { DefaultFlinkAlerts } from '@src/coreform/flink/DefaultAlerts';
import { AP_SOUTH_1A, AP_SOUTH_1B, AP_SOUTH_1C } from '@src/coreform/deployment/constants';
// lodash like path for resources in the manifest object
export const path = {
@@ -333,7 +332,6 @@ export const addDeployment = (manifest: any) => {
},
isDeployed: false,
isVpaEnabled: true,
zoneAffinity: [AP_SOUTH_1A, AP_SOUTH_1B, AP_SOUTH_1C],
perfUtility: {
mockServer: false,
postgresServer: false,
@@ -427,7 +425,7 @@ export const newOutboundConnectivity = () => {
};
export const newAllowEndpoint = () => {
return { host: '', port: '' };
return { host: '', port: '', hashedIdentifier: '' };
};
export const newHpaCronJob = () => {
return { name: '', schedule: '' };

View File

@@ -725,12 +725,15 @@ const perfValidationSchema = yup.object({
}),
});
const allowEndpointValidationSchema = yup.array().of(
yup.object({
host: yup.string().required('is Required'),
port: yup.string().required('is Required'),
}),
);
const allowEndpointValidationSchema = yup
.array()
.of(
yup.object({
host: yup.string().required('is Required'),
port: yup.string().required('is Required'),
}),
)
.unique('Host and port combination should be unique', ({ host, port }) => `${host}:${port}`);
const scyllaDbValidationSchema = yup.object({
name: yup
@@ -803,7 +806,6 @@ const deploymentValidationSchema = yup.object({
efs: efsValidationSchema.default(undefined),
fsx: fsxValidationSchema.default(undefined),
perfUtility: perfValidationSchema.default(undefined),
zoneAffinity: yup.array().of(yup.string().required('is Required')).min(1),
});
const docdbValidationScheme = yup.object({

View File

@@ -32,6 +32,7 @@ export interface Deployment {
instance: Instance;
scheduleOnSpotNodes: boolean;
isVpaEnabled: boolean;
allowEndpoint?: CiliumServiceEntry[];
}
export interface ZoneElement {
zone: string;
@@ -55,3 +56,9 @@ export type LbEndpointProps = {
getHostedZone: (index: number) => AutoCompleteOption;
setHostedZone: (index: number, value: string) => void;
};
export type CiliumServiceEntry = {
host: string;
port: string;
hashedIdentifier: string;
};