Skip to content

Commit cd40ff6

Browse files
authored
Merge pull request #2040 from devtron-labs/feat/environment-labels
feat: Cluster -> Environment - namespace labels support
2 parents 7d63331 + 4d117ef commit cd40ff6

File tree

24 files changed

+654
-337
lines changed

24 files changed

+654
-337
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ src/components/cluster/ClusterComponentModal.tsx
242242
src/components/cluster/ClusterForm.tsx
243243
src/components/cluster/ClusterInfoStepsModal.tsx
244244
src/components/cluster/ClusterInstallStatus.tsx
245-
src/components/cluster/Environment.tsx
246245
src/components/cluster/UseNameListDropdown.tsx
247246
src/components/cluster/cluster.service.ts
248247
src/components/cluster/cluster.util.ts

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "0.3.11",
7+
"@devtron-labs/devtron-fe-common-lib": "0.3.12",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterEnvironmentDrawer/ClusterEnvironmentDrawer.tsx

Lines changed: 373 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ClusterEnvironmentDrawer'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { UseFormValidations } from '@devtron-labs/devtron-fe-common-lib'
2+
3+
import { ClusterEnvironmentDrawerFormProps } from './types'
4+
5+
export const clusterEnvironmentDrawerFormValidationSchema = ({
6+
isNamespaceMandatory,
7+
}: {
8+
isNamespaceMandatory: boolean
9+
}): UseFormValidations<ClusterEnvironmentDrawerFormProps> => ({
10+
environmentName: {
11+
required: true,
12+
pattern: [
13+
{ message: 'Environment name is required', value: /^.*$/ },
14+
{ message: "Use only lowercase alphanumeric characters or '-'", value: /^[a-z0-9-]+$/ },
15+
{ message: "Cannot start/end with '-'", value: /^(?![-]).*[^-]$/ },
16+
{ message: 'Minimum 1 and Maximum 16 characters required', value: /^.{1,16}$/ },
17+
],
18+
},
19+
namespace: {
20+
required: isNamespaceMandatory,
21+
pattern: [
22+
{ message: 'Namespace is required', value: /^.*$/ },
23+
{ message: "Use only lowercase alphanumeric characters or '-'", value: /^[a-z0-9-]+$/ },
24+
{ message: "Cannot start/end with '-'", value: /^(?![-]).*[^-]$/ },
25+
{ message: 'Maximum 63 characters required', value: /^.{1,63}$/ },
26+
],
27+
},
28+
isProduction: {
29+
required: true,
30+
pattern: { message: 'token is required', value: /[^]+/ },
31+
},
32+
description: {
33+
pattern: [{ message: 'Maximum 40 characters required', value: /^.{0,40}$/ }],
34+
},
35+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { TagType } from '@devtron-labs/devtron-fe-common-lib'
2+
3+
export interface ClusterEnvironmentDrawerFormProps {
4+
environmentName: string
5+
namespace: string
6+
isProduction: boolean
7+
description: string
8+
}
9+
10+
export interface ClusterEnvironmentDrawerProps extends ClusterEnvironmentDrawerFormProps {
11+
id: string
12+
clusterId: number
13+
prometheusEndpoint: string
14+
reload: () => void
15+
hideClusterDrawer: () => void
16+
isVirtual: boolean
17+
}
18+
19+
export type GetClusterEnvironmentUpdatePayloadType = Pick<
20+
ClusterEnvironmentDrawerProps,
21+
'clusterId' | 'id' | 'prometheusEndpoint' | 'isVirtual'
22+
> &
23+
Partial<Pick<ClusterNamespacesDTO, 'resourceVersion'>> & {
24+
data: ClusterEnvironmentDrawerFormProps
25+
namespaceLabels?: TagType[]
26+
}
27+
28+
export interface ClusterNamespacesLabel {
29+
key: string
30+
value: string
31+
}
32+
33+
export interface ClusterNamespacesDTO {
34+
name: string
35+
labels: ClusterNamespacesLabel[]
36+
resourceVersion: string
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { ClusterNamespacesDTO, GetClusterEnvironmentUpdatePayloadType } from './types'
2+
3+
export const getClusterEnvironmentUpdatePayload = ({
4+
id,
5+
data,
6+
prometheusEndpoint,
7+
clusterId,
8+
namespaceLabels,
9+
resourceVersion,
10+
isVirtual = false,
11+
}: GetClusterEnvironmentUpdatePayloadType) =>
12+
isVirtual
13+
? {
14+
id,
15+
environment_name: data.environmentName,
16+
namespace: data.namespace || '',
17+
IsVirtualEnvironment: true,
18+
cluster_id: clusterId,
19+
description: data.description || '',
20+
}
21+
: {
22+
id,
23+
environment_name: data.environmentName,
24+
cluster_id: clusterId,
25+
prometheus_endpoint: prometheusEndpoint,
26+
namespace: data.namespace || '',
27+
active: true,
28+
default: data.isProduction,
29+
description: data.description || '',
30+
updateLabels: !!namespaceLabels,
31+
...(namespaceLabels
32+
? {
33+
namespaceResourceVersion: resourceVersion,
34+
namespaceLabels: namespaceLabels
35+
.filter(({ key, value }) => !!key.trim() && !!value.trim())
36+
.map(({ key, value }) => ({ key, value })),
37+
}
38+
: {}),
39+
}
40+
41+
export const getClusterNamespaceByName = (namespacesList: ClusterNamespacesDTO[], name: string) =>
42+
namespacesList.find(({ name: _name }) => _name === name)
43+
44+
export const getNamespaceLabels = (clusterNamespace: ClusterNamespacesDTO) =>
45+
clusterNamespace?.labels.map(({ key, value }, index) => ({
46+
id: index,
47+
key,
48+
value,
49+
propagate: true,
50+
isPropagateDisabled: true,
51+
})) ?? [
52+
{
53+
id: 0,
54+
key: '',
55+
value: '',
56+
propagate: true,
57+
isPropagateDisabled: true,
58+
},
59+
]

src/Pages/Shared/ConfigMapSecret/ConfigMapSecretForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ export const ConfigMapSecretForm = React.memo(
935935
value={state.configName.value}
936936
autoFocus
937937
onChange={onConfigNameChange}
938-
handleOnBlur={trimConfigMapName}
938+
onBlur={trimConfigMapName}
939939
placeholder={componentType === CMSecretComponentType.Secret ? 'secret-name' : 'configmap-name'}
940940
isRequiredField
941941
disabled={!!configMapSecretData?.name}

src/components/CIPipelineN/CustomInputOutputVariables.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ const CustomInputOutputVariables = ({ type }: { type: PluginVariableType }) => {
236236
value={variable.name}
237237
name="name"
238238
onChange={(e) => handleInputOutputValueChange(e, index)}
239-
handleOnBlur={handleBlur}
239+
onBlur={handleBlur}
240240
/>
241241
</div>
242242

@@ -297,7 +297,7 @@ const CustomInputOutputVariables = ({ type }: { type: PluginVariableType }) => {
297297
value={variable.description}
298298
name="description"
299299
onChange={(e) => handleInputOutputValueChange(e, index)}
300-
handleOnBlur={handleBlur}
300+
onBlur={handleBlur}
301301
/>
302302
</div>
303303

src/components/ciPipeline/SourceMaterials.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const SourceMaterials: React.FC<SourceMaterialsProps> = (props) => {
194194
SourceTypeMap.BranchFixed,
195195
)
196196
}}
197-
handleOnBlur={onBlur}
197+
onBlur={onBlur}
198198
isRequiredField
199199
error={
200200
errorObj &&

0 commit comments

Comments
 (0)