Skip to content

Commit 6c5fa37

Browse files
committed
fix: set max cpu/ram values for 1 gpu + translation
1 parent 0fba437 commit 6c5fa37

File tree

8 files changed

+47
-32
lines changed

8 files changed

+47
-32
lines changed

frontend/src/app/resource-form/form-gpus/form-gpus.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ <h3>
1818
{{ v }}
1919
</mat-option>
2020
</mat-select>
21+
<mat-hint>{{ message }}</mat-hint>
2122
</mat-form-field>
2223

2324
<mat-form-field class="wide" appearance="outline">

frontend/src/app/resource-form/form-gpus/form-gpus.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Input } from '@angular/core';
1+
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
22
import { FormGroup, ValidatorFn, AbstractControl } from '@angular/forms';
33
import { Subscription } from 'rxjs';
44
import { GPUVendor } from 'src/app/utils/types';
@@ -12,12 +12,16 @@ import { TranslateService } from '@ngx-translate/core';
1212
export class FormGpusComponent implements OnInit {
1313
@Input() parentForm: FormGroup;
1414
@Input() vendors: GPUVendor[];
15+
@Output() gpuValueEvent = new EventEmitter<string>();
16+
1517
private gpuCtrl: FormGroup;
1618
subscriptions = new Subscription();
1719

1820
maxGPUs = 16;
1921
gpusCount = ['1'];
2022

23+
message: string;
24+
2125
constructor(private translate: TranslateService) {}
2226

2327
ngOnInit() {
@@ -32,10 +36,13 @@ export class FormGpusComponent implements OnInit {
3236
this.subscriptions.add(
3337
this.gpuCtrl.get('num').valueChanges.subscribe((n: string) => {
3438
if (n === 'none') {
39+
this.message = "";
3540
this.gpuCtrl.get('vendor').disable();
3641
} else {
42+
this.message = this.translate.instant('formGpus.specsWarningMessage')
3743
this.gpuCtrl.get('vendor').enable();
3844
}
45+
this.gpuValueEvent.emit(n)
3946
}),
4047
);
4148
}

frontend/src/app/resource-form/form-specs/form-specs.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h3>
1212
<mat-form-field appearance="outline">
1313
<mat-label>{{ "formSpecs.lblCpu" | translate }}</mat-label>
1414
<input
15+
[attr.disabled]="readonlySpecs ? '' : null"
1516
matInput
1617
placeholder="{{ 'formSpecs.plhCpu' | translate }}"
1718
formControlName="cpu"
@@ -23,6 +24,7 @@ <h3>
2324
<mat-form-field appearance="outline">
2425
<mat-label>{{ "formSpecs.lblMemory" | translate }}</mat-label>
2526
<input
27+
[attr.disabled]="readonlySpecs ? '' : null"
2628
matInput
2729
placeholder="{{ 'formSpecs.plhMemory' | translate }}"
2830
formControlName="memory"

frontend/src/app/resource-form/form-specs/form-specs.component.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ function resourcesValidator(): ValidatorFn {
2525
const cpu = parseFloat(control.get("cpu").value);
2626
const ram = parseFloat(control.get("memory").value);
2727
const errors = {};
28-
2928
const max = MAX_FOR_GPU.get(gpu);
30-
if (cpu > max.cpu) {
31-
errors["maxCpu"] = {max: max.cpu, gpu};
32-
}
33-
if (ram > max.ram) {
34-
errors["maxRam"] = {max: max.ram, gpu};
29+
if (gpu == 0) {
30+
if (cpu > max.cpu) {
31+
errors["maxCpu"] = {max: max.cpu, gpu};
32+
}
33+
if (ram > max.ram) {
34+
errors["maxRam"] = {max: max.ram, gpu};
35+
}
3536
}
36-
3737
return Object.entries(errors).length > 0 ? errors : null;
3838
};
3939
}
@@ -47,8 +47,10 @@ export class FormSpecsComponent implements OnInit {
4747
@Input() parentForm: FormGroup;
4848
@Input() readonlyCPU: boolean;
4949
@Input() readonlyMemory: boolean;
50+
@Input() readonlySpecs: boolean;
5051

5152
constructor(private translate: TranslateService) {}
53+
5254
ngOnInit() {
5355
this.parentForm
5456
.get("cpu")
@@ -85,44 +87,27 @@ export class FormSpecsComponent implements OnInit {
8587
cpuErrorMessage(): string {
8688
let e: any;
8789
const errs = this.parentForm.get("cpu").errors || {};
88-
8990
if (errs.required)
9091
return this.translate.instant("formSpecs.errorCpuRequired");
9192
if (errs.pattern) return this.translate.instant("formSpecs.errorCpuNumber");
9293
if ((e = errs.min))
9394
return this.translate.instant("formSpecs.errorCpuMin", {min: `${e.min}`});
9495
if (this.parentForm.hasError("maxCpu")) {
9596
e = this.parentForm.errors.maxCpu;
96-
return (
97-
this.translate.instant("formSpecs.errorCpuMax", {max: `${e.max}`}) +
98-
(e.gpu > 0
99-
? this.translate.instant("formSpecs.errorCpuMaxLimit", {
100-
gpu: `${e.gpu}`
101-
})
102-
: "")
103-
);
97+
return this.translate.instant("formSpecs.errorCpuMax", {max: `${e.max}`});
10498
}
10599
}
106100

107101
memoryErrorMessage(): string {
108102
let e: any;
109103
const errs = this.parentForm.get("memory").errors || {};
110-
111104
if (errs.required || errs.pattern)
112105
return this.translate.instant("formSpecs.errorRamRequired");
113106
if ((e = errs.min))
114107
return this.translate.instant("formSpecs.errorRamMin", {min: `${e.min}`});
115-
116108
if (this.parentForm.hasError("maxRam")) {
117109
e = this.parentForm.errors.maxRam;
118-
return (
119-
this.translate.instant("formSpecs.errorRamMax", {max: `${e.max}`}) +
120-
(e.gpu > 0
121-
? this.translate.instant("formSpecs.errorRamMaxLimit", {
122-
gpu: `${e.gpu}`
123-
})
124-
: "")
125-
);
110+
return this.translate.instant("formSpecs.errorRamMax", {max: `${e.max}`});
126111
}
127112
}
128113
}

frontend/src/app/resource-form/resource-form.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
[hideVersion]="config?.image?.hideVersion"
1313
></app-form-image>
1414

15-
<app-form-specs [parentForm]="formCtrl"></app-form-specs>
15+
<app-form-specs
16+
[parentForm]="formCtrl"
17+
[readonlySpecs]="readonlySpecs"
18+
></app-form-specs>
1619

1720
<app-form-workspace-volume
1821
[parentForm]="formCtrl"
@@ -37,6 +40,7 @@
3740
<app-form-gpus
3841
[parentForm]="formCtrl"
3942
[vendors]="config?.gpus?.value.vendors"
43+
(gpuValueEvent)="checkGPU($event)"
4044
></app-form-gpus>
4145

4246
<app-form-advanced-options

frontend/src/app/resource-form/resource-form.component.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class ResourceFormComponent implements OnInit, OnDestroy {
2727

2828
subscriptions = new Subscription();
2929

30+
readonlySpecs: boolean;
31+
3032
constructor(
3133
private namespaceService: NamespaceService,
3234
private k8s: KubernetesService,
@@ -103,4 +105,15 @@ export class ResourceFormComponent implements OnInit, OnDestroy {
103105
}
104106
});
105107
}
108+
109+
// Automatically set values of CPU and Memory if GPU is 1
110+
checkGPU(gpu: string) {
111+
if (gpu == "none") {
112+
this.readonlySpecs = false;
113+
} else {
114+
this.readonlySpecs = true;
115+
this.formCtrl.get("cpu").setValue("5");
116+
this.formCtrl.get("memory").setValue("96Gi");
117+
}
118+
}
106119
}

frontend/src/assets/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"lblNumGpu": "Number of GPUs",
7070
"optNone": "None",
7171
"lblGpuVendor": "GPU Vendor",
72-
"errorGpuVendorRequired": "You must also specify the GPU Vendor for the assigned GPUs"
72+
"errorGpuVendorRequired": "You must also specify the GPU Vendor for the assigned GPUs",
73+
"specsWarningMessage": "Selecting 1 GPU will automatically set 5 CPUs and 96Gi of memory."
7374
},
7475
"formImage": {
7576
"h3Image": "Image",

frontend/src/assets/i18n/fr.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
"lblNumGpu": "Nombre GPUs",
7070
"optNone": "Aucun",
7171
"lblGpuVendor": "Vendeur de GPU",
72-
"errorGpuVendorRequired": "Vous devez spécifier le vendeur des GPUs assignés"
72+
"errorGpuVendorRequired": "Vous devez spécifier le vendeur des GPUs assignés",
73+
"specsWarningMessage": "La sélection de 1 GPU définira automatiquement 5 processeurs et 96Gi de la mémoire."
74+
7375
},
7476
"formImage": {
7577
"h3Image": "Image",
@@ -103,13 +105,13 @@
103105
"errorCpuNumber": "Doit être un nombre",
104106
"errorCpuMin": "Spécifier au moins {{min}} CPUs",
105107
"errorCpuMax": "Ne peut excéder {{max}} CPUs",
106-
"errorCpuMaxLimit": " avec {{gpu}} GPU(s) sélectionné",
108+
"errorCpuMaxLimit": " avec {{gpu}} GPU(s) sélectionné(s)",
107109
"lblMemory": "Mémoire",
108110
"plhMemory": "Quantié de mémoire",
109111
"errorRamRequired": "Spécifier la quantité de mémoire (ex. 2Gi)",
110112
"errorRamMin": "Spécifier au moins {{min}}Gi de mémoire",
111113
"errorRamMax": "Ne peut excéder {{max}}Gi de mémoire",
112-
"errorRamMaxLimit": " avec {{gpu}} GPU(s) sélectionné"
114+
"errorRamMaxLimit": " avec {{gpu}} GPU(s) sélectionné(s)"
113115
},
114116
"formWorkspaceVolume": {
115117
"h3WorkspaceVolume": "Volume d'espace de travail",

0 commit comments

Comments
 (0)