mirror of
https://github.com/portainer/portainer.git
synced 2025-07-20 22:09:41 +02:00
feat(k8s): review the resource assignement when creating a kubernetes application EE-437 (#5254)
* feat(nodes limits)Review the resource assignement when creating a Kubernetes application EE-437 * feat(nodes limits) review feedback EE-437 * feat(nodes limits) workaround for lodash cloneDeep not working in production mode EE-437 * feat(nodes limits) calculate max cpu of slide bar with floor function instead of round function EE-437 * feat(nodes limits) another review feedback EE-437 * feat(nodes limits) cleanup code EE-437 * feat(nodes limits) EE-437 pr feedback update * feat(nodes limits) EE-437 rebase onto develop branch * feat(nodes limits) EE-437 another pr feedback update Co-authored-by: Simon Meng <simon.meng@portainer.io>
This commit is contained in:
parent
0ffbe6a42e
commit
c597ae96e2
10 changed files with 453 additions and 42 deletions
65
app/kubernetes/models/nodes-limits/models.js
Normal file
65
app/kubernetes/models/nodes-limits/models.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
import _ from 'lodash-es';
|
||||
|
||||
/**
|
||||
* NodesLimits Model
|
||||
*/
|
||||
export class KubernetesNodesLimits {
|
||||
constructor(nodesLimits) {
|
||||
this.MaxCPU = 0;
|
||||
this.MaxMemory = 0;
|
||||
this.nodesLimits = this.convertCPU(nodesLimits);
|
||||
|
||||
this.calculateMaxCPUMemory();
|
||||
}
|
||||
|
||||
convertCPU(nodesLimits) {
|
||||
_.forEach(nodesLimits, (value) => {
|
||||
if (value.CPU) {
|
||||
value.CPU /= 1000.0;
|
||||
}
|
||||
});
|
||||
return nodesLimits;
|
||||
}
|
||||
|
||||
calculateMaxCPUMemory() {
|
||||
const nodesLimitsArray = Object.values(this.nodesLimits);
|
||||
this.MaxCPU = _.maxBy(nodesLimitsArray, 'CPU').CPU;
|
||||
this.MaxMemory = _.maxBy(nodesLimitsArray, 'Memory').Memory;
|
||||
}
|
||||
|
||||
// check if there is enough cpu and memory to allocate containers in replica mode
|
||||
overflowForReplica(cpu, memory, instances) {
|
||||
_.forEach(this.nodesLimits, (value) => {
|
||||
instances -= Math.min(Math.floor(value.CPU / cpu), Math.floor(value.Memory / memory));
|
||||
});
|
||||
|
||||
return instances > 0;
|
||||
}
|
||||
|
||||
// check if there is enough cpu and memory to allocate containers in global mode
|
||||
overflowForGlobal(cpu, memory) {
|
||||
let overflow = false;
|
||||
|
||||
_.forEach(this.nodesLimits, (value) => {
|
||||
if (cpu > value.CPU || memory > value.Memory) {
|
||||
overflow = true;
|
||||
}
|
||||
});
|
||||
|
||||
return overflow;
|
||||
}
|
||||
|
||||
excludesPods(pods, cpuLimit, memoryLimit) {
|
||||
const nodesLimits = this.nodesLimits;
|
||||
|
||||
_.forEach(pods, (value) => {
|
||||
const node = value.Node;
|
||||
if (node && nodesLimits[node]) {
|
||||
nodesLimits[node].CPU += cpuLimit;
|
||||
nodesLimits[node].Memory += memoryLimit;
|
||||
}
|
||||
});
|
||||
|
||||
this.calculateMaxCPUMemory();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue