Skip to content

Commit 95dde9a

Browse files
Merge pull request #501 from devtron-labs/feat/build-infra-2.5
feat: add useBuildXDriver in build infra
2 parents 82caa5f + 41bf8d4 commit 95dde9a

File tree

8 files changed

+159
-64
lines changed

8 files changed

+159
-64
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.4.0-patch-1",
3+
"version": "1.4.0-patch-2",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/AppStatus/AppStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default function AppStatus({
7171
className="default-tt w-200"
7272
arrow={false}
7373
placement="top"
74-
content="To fetch app status for GitOps based deployments open the app detail page"
74+
content="To fetch app status for Helm based deployments open the app detail page"
7575
>
7676
<div className="flex">
7777
<InfoIcon className="icon-dim-16 fcn-6" />

src/Pages/GlobalConfigurations/BuildInfra/UseBuildInfraForm.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
BuildInfraToleranceOperatorType,
1919
BuildInfraToleranceValueType,
2020
CREATE_MODE_REQUIRED_INPUT_FIELDS,
21-
createBuildInfraProfile,
2221
DEFAULT_PROFILE_NAME,
2322
DEFAULT_TOLERANCE_EFFECT,
2423
DEFAULT_TOLERANCE_OPERATOR,
@@ -29,7 +28,7 @@ import {
2928
ProfileInputErrorType,
3029
TARGET_PLATFORM_ERROR_FIELDS_MAP,
3130
ToleranceHeaderType,
32-
updateBuildInfraProfile,
31+
upsertBuildInfraProfile,
3332
UseBuildInfraFormProps,
3433
UseBuildInfraFormResponseType,
3534
ValidateNodeSelectorParamsType,
@@ -285,6 +284,7 @@ const useBuildInfraForm = ({
285284
name,
286285
editProfile,
287286
handleSuccessRedirection,
287+
canConfigureUseK8sDriver = false,
288288
}: UseBuildInfraFormProps): UseBuildInfraFormResponseType => {
289289
const fromCreateView = !name
290290

@@ -293,6 +293,7 @@ const useBuildInfraForm = ({
293293
getBuildInfraProfileByName({
294294
name: name ?? DEFAULT_PROFILE_NAME,
295295
fromCreateView,
296+
canConfigureUseK8sDriver,
296297
}),
297298
[name],
298299
)
@@ -330,11 +331,16 @@ const useBuildInfraForm = ({
330331
const currentInput = structuredClone(profileInput)
331332
const currentInputErrors = structuredClone(profileInputErrors)
332333
const targetPlatform =
333-
'targetPlatform' in data && Object.hasOwn(data, 'targetPlatform') ? data.targetPlatform : ''
334+
data && 'targetPlatform' in data && Object.hasOwn(data, 'targetPlatform') ? data.targetPlatform : ''
334335
const currentConfiguration = currentInput.configurations[targetPlatform]
335336
const lastSavedConfiguration = profileResponse.profile.configurations[targetPlatform] || currentConfiguration
336337

337338
switch (action) {
339+
case BuildInfraProfileInputActionType.TOGGLE_USE_K8S_DRIVER: {
340+
currentInput.useK8sDriver = !currentInput.useK8sDriver
341+
break
342+
}
343+
338344
case BuildInfraMetaConfigTypes.DESCRIPTION: {
339345
const { value } = data
340346
currentInput.description = value
@@ -599,6 +605,20 @@ const useBuildInfraForm = ({
599605
if (Object.keys(currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR] || {}).length === 0) {
600606
currentInputErrors[BuildInfraConfigTypes.NODE_SELECTOR] = null
601607
}
608+
609+
// Will validate all the keys since checking duplicates
610+
const existingKeys = currentConfiguration[BuildInfraConfigTypes.NODE_SELECTOR].value.map(
611+
(selector) => selector.key,
612+
)
613+
614+
currentConfiguration[BuildInfraConfigTypes.NODE_SELECTOR].value.forEach((selector) => {
615+
validateNodeSelector({
616+
selector,
617+
existingKeys,
618+
profileInputErrors: currentInputErrors,
619+
})
620+
})
621+
602622
break
603623
}
604624

@@ -748,8 +768,8 @@ const useBuildInfraForm = ({
748768
setProfileInputErrors(currentInputErrors)
749769
}
750770

751-
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
752-
e.preventDefault()
771+
const handleSubmit = async (event?: FormEvent<HTMLFormElement>) => {
772+
event?.preventDefault()
753773
// Since considering '' as a valid error message
754774
const hasErrors =
755775
Object.keys(profileInputErrors).filter(
@@ -766,11 +786,11 @@ const useBuildInfraForm = ({
766786

767787
setLoadingActionRequest(true)
768788
try {
769-
if (editProfile) {
770-
await updateBuildInfraProfile({ name, profileInput })
771-
} else {
772-
await createBuildInfraProfile({ profileInput })
773-
}
789+
await upsertBuildInfraProfile({
790+
name,
791+
profileInput,
792+
canConfigureUseK8sDriver,
793+
})
774794
setLoadingActionRequest(false)
775795
ToastManager.showToast({
776796
variant: ToastVariantType.success,

src/Pages/GlobalConfigurations/BuildInfra/constants.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
BuildInfraLocators,
2727
BuildInfraMetaConfigTypes,
2828
ProfileInputErrorType,
29-
BuildInfraProfileBase,
30-
BuildInfraProfileVariants,
3129
HandleProfileInputChangeType,
3230
BuildInfraProfileAdditionalErrorKeysType,
3331
BuildInfraAPIVersionType,
@@ -176,13 +174,6 @@ export const PROFILE_INPUT_ERROR_FIELDS = Object.fromEntries(
176174
// fields required to be filled before submitting the form in create view, since we pre-populate the form with default values so no need in configs
177175
export const CREATE_MODE_REQUIRED_INPUT_FIELDS = [BuildInfraMetaConfigTypes.NAME]
178176

179-
export const CREATE_PROFILE_BASE_VALUE: BuildInfraProfileBase = {
180-
name: '',
181-
description: '',
182-
type: BuildInfraProfileVariants.NORMAL,
183-
appCount: 0,
184-
}
185-
186177
export const BUILD_INFRA_TEST_IDS = {
187178
SUBMIT_BUTTON: 'build-infra-submit-button',
188179
CANCEL_BUTTON: 'build-infra-cancel-button',
@@ -256,3 +247,5 @@ export const DEFAULT_TOLERANCE_OPERATOR = BuildInfraToleranceOperatorType.EQUALS
256247
export const INFRA_CONFIG_NOT_SUPPORTED_BY_BUILD_X: Partial<Record<BuildInfraConfigTypes, true>> = {
257248
[BuildInfraConfigTypes.BUILD_TIMEOUT]: true,
258249
}
250+
251+
export const USE_BUILD_X_DRIVER_FALLBACK = true

src/Pages/GlobalConfigurations/BuildInfra/services.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import {
2424
BuildInfraProfileDTO,
2525
BuildInfraProfileInfoDTO,
2626
BuildInfraProfileResponseType,
27-
CreateBuildInfraProfileType,
2827
GetBuildInfraProfileType,
29-
UpdateBuildInfraProfileType,
28+
UpsertBuildInfraProfileServiceParamsType,
3029
} from './types'
3130

3231
export const getBuildInfraProfileByName = async ({
3332
name,
3433
fromCreateView,
34+
canConfigureUseK8sDriver,
3535
}: GetBuildInfraProfileType): Promise<BuildInfraProfileResponseType> => {
3636
try {
3737
const profilePayload: Pick<BuildInfraProfileDTO['profile'], 'name'> = { name }
@@ -45,25 +45,33 @@ export const getBuildInfraProfileByName = async ({
4545
defaultConfigurations,
4646
profile,
4747
fromCreateView,
48+
canConfigureUseK8sDriver,
4849
})
4950
} catch (error) {
5051
showError(error)
5152
throw error
5253
}
5354
}
5455

55-
export const updateBuildInfraProfile = async ({ name, profileInput }: UpdateBuildInfraProfileType) => {
56-
const updateProfilePayload: Pick<BuildInfraProfileDTO['profile'], 'name'> = { name }
57-
const response = await put<ReturnType<typeof put>, BuildInfraProfileInfoDTO>(
58-
getUrlWithSearchParams(getBuildInfraProfileEndpoint(), updateProfilePayload),
59-
getBuildInfraProfilePayload(profileInput),
60-
)
56+
export const upsertBuildInfraProfile = async ({
57+
name,
58+
profileInput,
59+
canConfigureUseK8sDriver,
60+
}: UpsertBuildInfraProfileServiceParamsType) => {
61+
const isEditView = !!name
62+
const baseEndpoint = getBuildInfraProfileEndpoint()
63+
const payload = getBuildInfraProfilePayload(profileInput, canConfigureUseK8sDriver)
64+
65+
if (isEditView) {
66+
const updateProfileQueryPayload: Pick<BuildInfraProfileDTO['profile'], 'name'> = { name }
67+
const response = await put<ReturnType<typeof put>, BuildInfraProfileInfoDTO>(
68+
getUrlWithSearchParams(baseEndpoint, updateProfileQueryPayload),
69+
payload,
70+
)
6171

72+
return response
73+
}
74+
75+
const response = await post<ReturnType<typeof post>, BuildInfraProfileInfoDTO>(baseEndpoint, payload)
6276
return response
6377
}
64-
65-
export const createBuildInfraProfile = async ({ profileInput }: CreateBuildInfraProfileType) =>
66-
post<ReturnType<typeof post>, BuildInfraProfileInfoDTO>(
67-
getBuildInfraProfileEndpoint(),
68-
getBuildInfraProfilePayload(profileInput),
69-
)

src/Pages/GlobalConfigurations/BuildInfra/types.tsx

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,27 @@ export type BuildInfraConfigurationMapTypeWithoutDefaultFallback = {
225225

226226
export type BuildInfraConfigurationMapType = Record<BuildInfraConfigTypes, BuildInfraConfigurationType>
227227

228+
export enum BuildXDriverType {
229+
KUBERNETES = 'kubernetes',
230+
DOCKER_CONTAINER = 'docker-container',
231+
}
232+
228233
interface BuildInfraProfileBaseDTO {
229234
id?: number
230235
name?: string
231236
description: string
232237
type: BuildInfraProfileVariants
233238
appCount?: number
234239
active?: boolean
240+
/**
241+
* @default `BuildXDriverType.KUBERNETES`
242+
*/
243+
buildxDriverType?: BuildXDriverType
235244
}
236245

237-
export interface BuildInfraProfileBase extends BuildInfraProfileBaseDTO {}
246+
export interface BuildInfraProfileBase extends Omit<BuildInfraProfileBaseDTO, 'buildxDriverType'> {
247+
useK8sDriver?: boolean
248+
}
238249

239250
export interface BuildInfraProfileInfoDTO extends BuildInfraProfileBaseDTO {
240251
configurations: BuildInfraPlatformConfigurationMapDTO
@@ -247,20 +258,6 @@ export interface BuildInfraProfileData extends BuildInfraProfileBase {
247258
configurations: Record<string, BuildInfraConfigurationMapType>
248259
}
249260

250-
export interface GetBuildInfraProfileType {
251-
name: string
252-
fromCreateView?: boolean
253-
}
254-
255-
export interface BuildInfraProfileResponseType {
256-
configurationUnits: BuildInfraUnitsMapType | null
257-
profile: BuildInfraProfileData | null
258-
/**
259-
* To be used in case user is creating configuration for new platform
260-
*/
261-
fallbackPlatformConfigurationMap: BuildInfraProfileData['configurations']
262-
}
263-
264261
export interface UseBuildInfraFormProps {
265262
/**
266263
* Name of the profile, if not provided assumption would be for create view
@@ -274,6 +271,24 @@ export interface UseBuildInfraFormProps {
274271
* If true, call this on form submission success
275272
*/
276273
handleSuccessRedirection?: () => void
274+
/**
275+
* @default false
276+
*/
277+
canConfigureUseK8sDriver?: boolean
278+
}
279+
280+
export interface GetBuildInfraProfileType extends Pick<UseBuildInfraFormProps, 'canConfigureUseK8sDriver'> {
281+
name: string
282+
fromCreateView?: boolean
283+
}
284+
285+
export interface BuildInfraProfileResponseType {
286+
configurationUnits: BuildInfraUnitsMapType | null
287+
profile: BuildInfraProfileData | null
288+
/**
289+
* To be used in case user is creating configuration for new platform
290+
*/
291+
fallbackPlatformConfigurationMap: BuildInfraProfileData['configurations']
277292
}
278293

279294
export enum BuildInfraProfileAdditionalErrorKeysType {
@@ -322,6 +337,7 @@ interface NumericBuildInfraConfigPayloadType {
322337

323338
export enum BuildInfraProfileInputActionType {
324339
ADD_TARGET_PLATFORM = 'add_target_platform',
340+
TOGGLE_USE_K8S_DRIVER = 'toggle_use_k8s_driver',
325341
REMOVE_TARGET_PLATFORM = 'remove_target_platform',
326342
RENAME_TARGET_PLATFORM = 'rename_target_platform',
327343
RESTORE_PROFILE_CONFIG_SNAPSHOT = 'restore_profile_config_snapshot',
@@ -336,6 +352,10 @@ export enum BuildInfraProfileInputActionType {
336352
}
337353

338354
export type HandleProfileInputChangeType =
355+
| {
356+
action: BuildInfraProfileInputActionType.TOGGLE_USE_K8S_DRIVER
357+
data?: never
358+
}
339359
| {
340360
action: NumericBuildInfraConfigTypes
341361
data: ProfileInputDispatchDataType & NumericBuildInfraConfigPayloadType
@@ -402,7 +422,7 @@ export interface UseBuildInfraFormResponseType {
402422
profileInputErrors: ProfileInputErrorType
403423
handleProfileInputChange: ({ action, data }: HandleProfileInputChangeType) => void
404424
loadingActionRequest: boolean
405-
handleSubmit: (e: FormEvent<HTMLFormElement>) => Promise<void>
425+
handleSubmit: (e?: FormEvent<HTMLFormElement>) => Promise<void>
406426
}
407427

408428
export interface BuildInfraConfigFormProps
@@ -476,8 +496,13 @@ export interface FooterProps {
476496
loading?: boolean
477497
}
478498

479-
export interface UpdateBuildInfraProfileType extends Pick<UseBuildInfraFormResponseType, 'profileInput'> {
480-
name: string
499+
export interface UpsertBuildInfraProfileServiceParamsType
500+
extends Pick<UseBuildInfraFormResponseType, 'profileInput'>,
501+
Pick<UseBuildInfraFormProps, 'canConfigureUseK8sDriver'> {
502+
/**
503+
* If not given would consider as create view
504+
*/
505+
name?: string
481506
}
482507

483508
export interface CreateBuildInfraProfileType extends Pick<UseBuildInfraFormResponseType, 'profileInput'> {}
@@ -519,7 +544,8 @@ export interface BuildInfraProfileDTO extends BaseBuildInfraProfileDTO {
519544

520545
export interface BuildInfraProfileTransformerParamsType
521546
extends BuildInfraProfileDTO,
522-
Pick<GetBuildInfraProfileType, 'fromCreateView'> {}
547+
Pick<GetBuildInfraProfileType, 'fromCreateView'>,
548+
Pick<GetBuildInfraProfileType, 'canConfigureUseK8sDriver'> {}
523549

524550
export interface GetPlatformConfigurationsWithDefaultValuesParamsType {
525551
profileConfigurationsMap: BuildInfraConfigurationMapTypeWithoutDefaultFallback
@@ -544,3 +570,6 @@ export interface ValidateNodeSelectorParamsType
544570
selector: BuildInfraNodeSelectorValueType
545571
existingKeys: string[]
546572
}
573+
574+
export interface GetBaseProfileObjectParamsType
575+
extends Pick<BuildInfraProfileTransformerParamsType, 'canConfigureUseK8sDriver' | 'fromCreateView' | 'profile'> {}

0 commit comments

Comments
 (0)