Skip to content

Commit 89f3e20

Browse files
authored
added form limits for workbench, PVC, and project resource names (#3698)
1 parent c98a99c commit 89f3e20

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

frontend/src/concepts/k8s/K8sNameDescriptionField/__tests__/utils.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
handleUpdateLogic,
33
isK8sNameDescriptionDataValid,
44
LimitNameResourceType,
5+
resourceTypeLimits,
56
setupDefaults,
67
} from '~/concepts/k8s/K8sNameDescriptionField/utils';
78
import { K8sNameDescriptionFieldData } from '~/concepts/k8s/K8sNameDescriptionField/types';
@@ -74,6 +75,81 @@ describe('setupDefaults', () => {
7475
}),
7576
);
7677
});
78+
79+
it('should limit PVC resource name', () => {
80+
expect(
81+
setupDefaults({
82+
initialData: mockProjectK8sResource({
83+
displayName:
84+
'this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test ',
85+
k8sName: '',
86+
description: 'my description',
87+
}),
88+
limitNameResourceType: LimitNameResourceType.PVC,
89+
}),
90+
).toEqual(
91+
mockK8sNameDescriptionFieldData({
92+
name: 'this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test ',
93+
description: 'my description',
94+
k8sName: {
95+
value: 'this-is-a-test-this-is-a-test-this-is-a-test-this-is-a-test-thi',
96+
state: {
97+
immutable: false,
98+
maxLength: resourceTypeLimits[LimitNameResourceType.PVC],
99+
},
100+
},
101+
}),
102+
);
103+
});
104+
105+
it('should limit project/workbench resource name', () => {
106+
expect(
107+
setupDefaults({
108+
initialData: mockProjectK8sResource({
109+
displayName:
110+
'this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test ',
111+
k8sName: '',
112+
description: 'my description',
113+
}),
114+
limitNameResourceType: LimitNameResourceType.PROJECT,
115+
}),
116+
).toEqual(
117+
mockK8sNameDescriptionFieldData({
118+
name: 'this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test ',
119+
description: 'my description',
120+
k8sName: {
121+
value: 'this-is-a-test-this-is-a-test',
122+
state: {
123+
immutable: false,
124+
maxLength: resourceTypeLimits[LimitNameResourceType.PROJECT],
125+
},
126+
},
127+
}),
128+
);
129+
expect(
130+
setupDefaults({
131+
initialData: mockProjectK8sResource({
132+
displayName:
133+
'this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test ',
134+
k8sName: '',
135+
description: 'my description',
136+
}),
137+
limitNameResourceType: LimitNameResourceType.WORKBENCH,
138+
}),
139+
).toEqual(
140+
mockK8sNameDescriptionFieldData({
141+
name: 'this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test ',
142+
description: 'my description',
143+
k8sName: {
144+
value: 'this-is-a-test-this-is-a-test',
145+
state: {
146+
immutable: false,
147+
maxLength: resourceTypeLimits[LimitNameResourceType.WORKBENCH],
148+
},
149+
},
150+
}),
151+
);
152+
});
77153
});
78154

79155
describe('handleUpdateLogic', () => {

frontend/src/concepts/k8s/K8sNameDescriptionField/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,19 @@ export enum LimitNameResourceType {
3131
/** Workbenches create routes */
3232
WORKBENCH,
3333
// TODO: Support Model Serving?
34+
PVC,
3435
}
3536
/** K8s max DNS subdomain name length */
3637
const MAX_RESOURCE_NAME_LENGTH = 253;
3738

39+
const MAX_PVC_NAME_LENGTH = 63;
40+
41+
export const resourceTypeLimits: Record<LimitNameResourceType, number> = {
42+
[LimitNameResourceType.PROJECT]: ROUTE_BASED_NAME_LENGTH,
43+
[LimitNameResourceType.WORKBENCH]: ROUTE_BASED_NAME_LENGTH,
44+
[LimitNameResourceType.PVC]: MAX_PVC_NAME_LENGTH,
45+
};
46+
3847
export const isK8sNameDescriptionType = (
3948
x?: K8sNameDescriptionType | K8sResourceCommon,
4049
): x is K8sNameDescriptionType => !!x && 'k8sName' in x;
@@ -64,7 +73,7 @@ export const setupDefaults = ({
6473
}
6574

6675
if (limitNameResourceType != null) {
67-
configuredMaxLength = ROUTE_BASED_NAME_LENGTH;
76+
configuredMaxLength = resourceTypeLimits[limitNameResourceType];
6877
}
6978

7079
return handleUpdateLogic({

frontend/src/pages/projects/screens/spawner/storage/CreateNewStorageSection.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { PersistentVolumeClaimKind } from '~/k8sTypes';
88
import K8sNameDescriptionField, {
99
useK8sNameDescriptionFieldData,
1010
} from '~/concepts/k8s/K8sNameDescriptionField/K8sNameDescriptionField';
11-
import { isK8sNameDescriptionDataValid } from '~/concepts/k8s/K8sNameDescriptionField/utils';
11+
import {
12+
isK8sNameDescriptionDataValid,
13+
LimitNameResourceType,
14+
} from '~/concepts/k8s/K8sNameDescriptionField/utils';
1215
import StorageClassSelect from './StorageClassSelect';
1316

1417
type CreateNewStorageSectionProps<D extends StorageData> = {
@@ -44,6 +47,7 @@ const CreateNewStorageSection = <D extends StorageData>({
4447
k8sName: data.k8sName,
4548
description: data.description,
4649
},
50+
limitNameResourceType: LimitNameResourceType.PVC,
4751
editableK8sName,
4852
});
4953

0 commit comments

Comments
 (0)