Skip to content

Commit 23bc7ab

Browse files
Copilotfredleger
authored andcommitted
fix: clamp desiredNodes within [minNodes, maxNodes] range
Co-authored-by: fredleger <2778741+fredleger@users.noreply.github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 0135673 commit 23bc7ab

File tree

8 files changed

+121
-28
lines changed

8 files changed

+121
-28
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
2-
"name": "Debian",
3-
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
2+
"name": "github-action-ovh-mks-scaling",
3+
"image": "mcr.microsoft.com/devcontainers/base:debian",
44
"features": {
55
"ghcr.io/devcontainers/features/node:1": {},
6-
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
7+
"moby": false
8+
},
79
"ghcr.io/devcontainers/features/github-cli:1": {}
810
},
911
"remoteEnv": {

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ lint-fix: ## Execute linting and fix
1818

1919
ci: ## Execute all formats and checks
2020
@npm install
21-
@npm audit fix
21+
@npm audit fix || true
2222
@npm run all
2323
$(MAKE) lint-fix
2424

action.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,31 @@ inputs:
4444
nodepool-id:
4545
required: true
4646
description: "The ID of the OVH MKS nodepool"
47-
number-of-nodes:
48-
required: true
49-
description: "The desired number of nodes to scale to"
50-
default: "1"
5147
autoscale:
5248
required: false
5349
description: "Whether to enable autoscaling for the nodepool"
5450
default: "true"
51+
number-of-nodes:
52+
required: true
53+
description: |
54+
The desired number of nodes to scale to.
55+
This value sets the `desiredNodes` property on the OVH API.
56+
It is also used as the default for `min-nodes` and `max-nodes` when they are not provided.
57+
The effective `desiredNodes` sent to the API is clamped between `min-nodes` and `max-nodes`
58+
(i.e. `max(number-of-nodes, min-nodes)` then `min(result, max-nodes)`).
59+
default: "1"
5560
min-nodes:
5661
required: false
5762
description: |
58-
The minimum number of nodes for autoscaling.
59-
Defaults to the value of number-of-nodes if not provided.
63+
The minimum number of nodes for autoscaling (sets `minNodes` on the OVH API).
64+
Defaults to `number-of-nodes` if not provided.
65+
When autoscaling is enabled, the cluster will never scale below this value.
6066
max-nodes:
6167
required: false
6268
description: |
63-
The maximum number of nodes for autoscaling.
64-
Defaults to the value of number-of-nodes if not provided.
69+
The maximum number of nodes for autoscaling (sets `maxNodes` on the OVH API).
70+
Defaults to `number-of-nodes` if not provided.
71+
When autoscaling is enabled, the cluster will never scale above this value.
6572
6673
outputs:
6774
response:

dist/index.js

Lines changed: 33 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@
8787
"tsDevTools": {
8888
"version": "20250623095600-remove-prettier-oxc"
8989
}
90-
}
90+
}

src/services/ovh.service.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,58 @@ describe("OvhService", () => {
337337
);
338338
});
339339

340+
it("should clamp desiredNodes to minNodes when numberOfNodes is below minNodes", async () => {
341+
mockRequestPromised.mockResolvedValue({} as NodepoolUpdateResponse);
342+
343+
await service.scaleNodepool({
344+
projectId: "project-123",
345+
clusterId: "cluster-456",
346+
nodepoolId: "nodepool-789",
347+
numberOfNodes: 1,
348+
autoscale: true,
349+
minNodes: 3,
350+
maxNodes: 10,
351+
});
352+
353+
expect(mockRequestPromised).toHaveBeenCalledWith(
354+
"PUT",
355+
"/cloud/project/project-123/kube/cluster-456/nodepool/nodepool-789",
356+
{
357+
autoscale: true,
358+
autoscaling: {},
359+
minNodes: 3,
360+
maxNodes: 10,
361+
desiredNodes: 3,
362+
}
363+
);
364+
});
365+
366+
it("should clamp desiredNodes to maxNodes when numberOfNodes is above maxNodes", async () => {
367+
mockRequestPromised.mockResolvedValue({} as NodepoolUpdateResponse);
368+
369+
await service.scaleNodepool({
370+
projectId: "project-123",
371+
clusterId: "cluster-456",
372+
nodepoolId: "nodepool-789",
373+
numberOfNodes: 15,
374+
autoscale: true,
375+
minNodes: 3,
376+
maxNodes: 10,
377+
});
378+
379+
expect(mockRequestPromised).toHaveBeenCalledWith(
380+
"PUT",
381+
"/cloud/project/project-123/kube/cluster-456/nodepool/nodepool-789",
382+
{
383+
autoscale: true,
384+
autoscaling: {},
385+
minNodes: 3,
386+
maxNodes: 10,
387+
desiredNodes: 10,
388+
}
389+
);
390+
});
391+
340392
it("should disable autoscale and use numberOfNodes for min/max when autoscale is false and no overrides", async () => {
341393
const mockResponse: NodepoolUpdateResponse = {
342394
autoscale: false,

src/services/ovh.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ export class OvhService {
164164
}) {
165165
const effectiveMinNodes = minNodes ?? numberOfNodes;
166166
const effectiveMaxNodes = maxNodes ?? numberOfNodes;
167+
const effectiveDesiredNodes = Math.min(
168+
Math.max(numberOfNodes, effectiveMinNodes),
169+
effectiveMaxNodes
170+
);
167171

168172
return this.client.requestPromised(
169173
"PUT",
@@ -173,7 +177,7 @@ export class OvhService {
173177
autoscaling: {},
174178
minNodes: effectiveMinNodes,
175179
maxNodes: effectiveMaxNodes,
176-
desiredNodes: numberOfNodes,
180+
desiredNodes: effectiveDesiredNodes,
177181
}
178182
);
179183
}

0 commit comments

Comments
 (0)