-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(resourceLimits): calculate limits correctly
this fixes a couple places that fomerly presented misleading information: when deploying a single app and scaling it, we might run into the case that our former calculations came to the conclusion to display some limits (because of unintended side effects of default values). when having a look at the tasks of either such an app or a scaled pod, we would also see wrong information for the tasks. they would each claim to reserve / be limited at their `own claim * scale` because the calculation did not distinguish the `ServicesTable` from the `TasksTable`. We now got some unit tests that you can look at to get a feeling for what values we show! Closes COPS-6555
- Loading branch information
1 parent
0cb95e9
commit 69d94db
Showing
7 changed files
with
118 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
plugins/services/src/js/columns/__tests__/resourceLimits-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { getResourceLimits, ResourceLimits } from "../resourceLimits"; | ||
import Application from "../../structs/Application"; | ||
import Pod from "../../structs/Pod"; | ||
|
||
const app = ( | ||
resourceLimits: ResourceLimits = { cpus: 1, mem: 256 }, | ||
instances = 2 | ||
) => new Application({ instances, resourceLimits }); | ||
|
||
const podContainer = (opts: any = {}) => ({ | ||
resourceLimits: { cpus: 1, mem: 256 }, | ||
...opts, | ||
}); | ||
|
||
// opts is passed to the second container | ||
const pod = (opts: any[] = []) => | ||
new Pod({ | ||
spec: { | ||
containers: [podContainer(opts[0]), podContainer(opts[1])], | ||
scaling: { instances: 2 }, | ||
}, | ||
}); | ||
|
||
describe("getResourceLimits for apps", () => { | ||
it("does not incorporate scale by default", () => { | ||
expect(getResourceLimits(app())).toEqual({ | ||
cpus: 1, | ||
mem: 256, | ||
}); | ||
}); | ||
it("can compute scaled values", () => { | ||
expect(getResourceLimits(app(), true)).toEqual({ | ||
cpus: 2, | ||
mem: 512, | ||
}); | ||
}); | ||
it("returns null when no resourceLimits are set", () => { | ||
expect( | ||
getResourceLimits(app({ cpus: undefined, mem: undefined }), true) | ||
).toEqual({ | ||
cpus: undefined, | ||
mem: undefined, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("getResourceLimits for pods", () => { | ||
it("computes something sensible ", () => { | ||
expect(getResourceLimits(pod())).toEqual({ | ||
cpus: 2, | ||
mem: 512, | ||
}); | ||
}); | ||
it("can compute scaled values", () => { | ||
expect(getResourceLimits(pod(), true)).toEqual({ | ||
cpus: 4, | ||
mem: 1024, | ||
}); | ||
}); | ||
it("incorporates resources when calculating limits", () => { | ||
expect( | ||
getResourceLimits( | ||
pod([ | ||
{ resources: { mem: 128 }, resourceLimits: { mem: 256 } }, | ||
{ resources: { mem: 128 }, resourceLimits: { mem: undefined } }, | ||
]) | ||
) | ||
).toEqual({ cpus: undefined, mem: 384 }); | ||
}); | ||
it("incorporates resources when calculating limits", () => { | ||
expect( | ||
getResourceLimits( | ||
pod([ | ||
{ resources: { mem: 128 }, resourceLimits: { mem: 256 } }, | ||
{ resources: { mem: 128 }, resourceLimits: { mem: undefined } }, | ||
]), | ||
true | ||
) | ||
).toEqual({ cpus: undefined, mem: 768 }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters