fix(app): only show special message when limits change for existing app resource limit [EE-6837] (#11367)
Co-authored-by: testa113 <testa113>pull/11373/head
parent
a2a4c85f2d
commit
3b1d853090
|
@ -290,7 +290,7 @@
|
|||
min-cpu-limit="ctrl.state.sliders.cpu.min"
|
||||
max-memory-limit="ctrl.state.sliders.memory.max"
|
||||
max-cpu-limit="ctrl.state.sliders.cpu.max"
|
||||
validation-data="{isEdit: ctrl.state.isEdit, maxMemoryLimit: ctrl.state.sliders.memory.max, maxCpuLimit: ctrl.state.sliders.cpu.max, isEnvironmentAdmin: ctrl.isAdmin, nodeLimits: ctrl.nodesLimits.nodesLimits}"
|
||||
validation-data="{isExistingCPUReservationUnchanged: ctrl.state.isExistingCPUReservationUnchanged, isExistingMemoryReservationUnchanged: ctrl.state.isExistingMemoryReservationUnchanged, maxMemoryLimit: ctrl.state.sliders.memory.max, maxCpuLimit: ctrl.state.sliders.cpu.max, isEnvironmentAdmin: ctrl.isAdmin, nodeLimits: ctrl.nodesLimits.nodesLimits}"
|
||||
resource-quota-capacity-exceeded="ctrl.resourceQuotaCapacityExceeded()"
|
||||
></resource-reservation-form-section>
|
||||
|
||||
|
|
|
@ -123,6 +123,10 @@ class KubernetesCreateApplicationController {
|
|||
persistedFoldersUseExistingVolumes: false,
|
||||
pullImageValidity: false,
|
||||
nodePortServices: [],
|
||||
// when the namespace available resources changes, and the existing app not has a resource limit that exceeds whats available,
|
||||
// a validation message will be shown. isExistingCPUReservationUnchanged and isExistingMemoryReservationUnchanged (with available resources being exceeded) is used to decide whether to show the message or not.
|
||||
isExistingCPUReservationUnchanged: false,
|
||||
isExistingMemoryReservationUnchanged: false,
|
||||
};
|
||||
|
||||
this.isAdmin = this.Authentication.isAdmin();
|
||||
|
@ -514,6 +518,13 @@ class KubernetesCreateApplicationController {
|
|||
return this.$async(async () => {
|
||||
this.formValues.MemoryLimit = values.memoryLimit;
|
||||
this.formValues.CpuLimit = values.cpuLimit;
|
||||
|
||||
if (this.oldFormValues.CpuLimit !== this.formValues.CpuLimit && this.state.isExistingCPUReservationUnchanged) {
|
||||
this.state.isExistingCPUReservationUnchanged = false;
|
||||
}
|
||||
if (this.oldFormValues.MemoryLimit !== this.formValues.MemoryLimit && this.state.isExistingMemoryReservationUnchanged) {
|
||||
this.state.isExistingMemoryReservationUnchanged = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1063,6 +1074,13 @@ class KubernetesCreateApplicationController {
|
|||
this.originalServicePorts = structuredClone(this.formValues.Services.flatMap((service) => service.Ports));
|
||||
this.originalIngressPaths = structuredClone(this.originalServicePorts.flatMap((port) => port.ingressPaths).filter((ingressPath) => ingressPath.Host));
|
||||
|
||||
if (this.formValues.CpuLimit) {
|
||||
this.state.isExistingCPUReservationUnchanged = true;
|
||||
}
|
||||
if (this.formValues.MemoryLimit) {
|
||||
this.state.isExistingMemoryReservationUnchanged = true;
|
||||
}
|
||||
|
||||
if (this.application.ApplicationKind) {
|
||||
this.state.appType = KubernetesDeploymentTypes[this.application.ApplicationKind.toUpperCase()];
|
||||
if (this.application.ApplicationKind === KubernetesDeploymentTypes.URL) {
|
||||
|
|
|
@ -17,7 +17,8 @@ type ValidationData = {
|
|||
maxCpuLimit: number;
|
||||
isEnvironmentAdmin: boolean;
|
||||
nodeLimits: NodesLimits;
|
||||
isEdit: boolean;
|
||||
isExistingCPUReservationUnchanged: boolean;
|
||||
isExistingMemoryReservationUnchanged: boolean;
|
||||
};
|
||||
|
||||
export function resourceReservationValidation(
|
||||
|
@ -36,15 +37,16 @@ export function resourceReservationValidation(
|
|||
() => !!validationData && validationData.maxMemoryLimit > 0
|
||||
)
|
||||
.max(validationData?.maxMemoryLimit || 0, ({ value }) =>
|
||||
validationData?.isEdit
|
||||
// when the existing reservation is unchanged and exceeds the new limit, show a different error message
|
||||
// https://portainer.atlassian.net/browse/EE-5933?focusedCommentId=29308
|
||||
validationData?.isExistingMemoryReservationUnchanged
|
||||
? `Value must be between 0 and ${validationData?.maxMemoryLimit}MB now - the previous value of ${value} exceeds this.`
|
||||
: `Value must be between 0 and ${validationData?.maxMemoryLimit}MB.`
|
||||
)
|
||||
.test(
|
||||
'hasSuitableNode',
|
||||
`These reservations would exceed the resources currently available in the cluster.`,
|
||||
// eslint-disable-next-line prefer-arrow-callback, func-names
|
||||
function (value: number | undefined, context: TestContext) {
|
||||
(value: number | undefined, context: TestContext) => {
|
||||
if (!validationData || value === undefined) {
|
||||
// explicitely check for undefined, since 0 is a valid value
|
||||
return true;
|
||||
|
@ -70,15 +72,16 @@ export function resourceReservationValidation(
|
|||
() => !!validationData && validationData.maxCpuLimit > 0
|
||||
)
|
||||
.max(validationData?.maxCpuLimit || 0, ({ value }) =>
|
||||
validationData?.isEdit
|
||||
// when the existing reservation is unchanged and exceeds the new limit, show a different error message
|
||||
// https://portainer.atlassian.net/browse/EE-5933?focusedCommentId=29308
|
||||
validationData?.isExistingCPUReservationUnchanged
|
||||
? `Value must be between 0 and ${validationData?.maxCpuLimit} now - the previous value of ${value} exceeds this.`
|
||||
: `Value must be between 0 and ${validationData?.maxCpuLimit}.`
|
||||
)
|
||||
.test(
|
||||
'hasSuitableNode',
|
||||
`These reservations would exceed the resources currently available in the cluster.`,
|
||||
// eslint-disable-next-line prefer-arrow-callback, func-names
|
||||
function (value: number | undefined, context: TestContext) {
|
||||
(value: number | undefined, context: TestContext) => {
|
||||
if (!validationData || value === undefined) {
|
||||
// explicitely check for undefined, since 0 is a valid value
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue