|
1 | | -import { getInput, setOutput, setFailed } from '@actions/core'; |
2 | | -import { readFile } from 'node:fs/promises'; |
3 | | -import ovh from 'ovh'; |
| 1 | +import { getInput, setOutput, setFailed } from "@actions/core"; |
| 2 | +import ovh from "ovh"; |
4 | 3 |
|
5 | | -try { |
6 | | - const ovhEndpoint = getInput('endpoint'); |
7 | | - const ovhRegion = getInput('region'); |
8 | | - const ovhProjectId = getInput('project_id'); |
9 | | - const ovhClusterId = getInput('cluster_id'); |
10 | | - const ovhNodepoolId = getInput('nodepool_id'); |
11 | | - const nodesNumber = getInput('number_of_nodes'); |
| 4 | +const ovhEndpoint = getInput("endpoint"); |
| 5 | +const ovhProjectId = getInput("project_id"); |
| 6 | +const ovhClusterId = getInput("cluster_id"); |
| 7 | +const ovhNodepoolId = getInput("nodepool_id"); |
| 8 | +const nodesNumber = getInput("number_of_nodes"); |
| 9 | + |
| 10 | +// setup OVH api client |
| 11 | +const client = ovh({ |
| 12 | + endpoint: ovhEndpoint, |
| 13 | + appKey: process.env.OVH_APPLICATION_KEY, |
| 14 | + appSecret: process.env.OVH_APPLICATION_SECRET, |
| 15 | + consumerKey: process.env.OVH_CONSUMER_KEY, |
| 16 | +}); |
12 | 17 |
|
13 | | - // setup OVH api client |
14 | | - const client = ovh({ |
15 | | - endpoint: ovhEndpoint, |
16 | | - appKey: process.env.OVH_APP_KEY, |
17 | | - appSecret: process.env.OVH_APP_SECRET, |
18 | | - consumerKey: process.env.OVH_CONSUMER_KEY, |
19 | | - }); |
| 18 | +// Call the OVH API to scale the nodepool |
| 19 | +// see https://eu.api.ovh.com/console/?section=%2Fcloud&branch=v1#put-/cloud/project/-serviceName-/kube/-kubeId-/nodepool/-nodePoolId- |
| 20 | +// curl -X PUT "https://eu.api.ovh.com/v1/cloud/project//kube//nodepool/" \ |
| 21 | +// -H "content-type: application/json" \ |
| 22 | +// -d '{"autoscale":false,"autoscaling":{"scaleDownUnneededTimeSeconds":0,"scaleDownUnreadyTimeSeconds":0,"scaleDownUtilizationThreshold":0},"desiredNodes":0,"maxNodes":0,"minNodes":0,"nodesToRemove":["string"],"template":{"metadata":{"annotations":{"any-key":"string"},"finalizers":["string"],"labels":{"any-key":"string"}},"spec":{"taints":[{"effect":"NoExecute","key":"string","value":"string"}],"unschedulable":false}}}' \ |
20 | 23 |
|
21 | | - // Call the OVH API to scale the nodepool |
22 | | - // see https://eu.api.ovh.com/console/?section=%2Fcloud&branch=v1#put-/cloud/project/-serviceName-/kube/-kubeId-/nodepool/-nodePoolId- |
23 | | - // curl -X PUT "https://eu.api.ovh.com/v1/cloud/project//kube//nodepool/" \ |
24 | | - // -H "content-type: application/json" \ |
25 | | - // -d '{"autoscale":false,"autoscaling":{"scaleDownUnneededTimeSeconds":0,"scaleDownUnreadyTimeSeconds":0,"scaleDownUtilizationThreshold":0},"desiredNodes":0,"maxNodes":0,"minNodes":0,"nodesToRemove":["string"],"template":{"metadata":{"annotations":{"any-key":"string"},"finalizers":["string"],"labels":{"any-key":"string"}},"spec":{"taints":[{"effect":"NoExecute","key":"string","value":"string"}],"unschedulable":false}}}' \ |
| 24 | +console.log("Scaling nodepool with the following parameters:", { |
| 25 | + endpoint: ovhEndpoint, |
| 26 | + projectId: ovhProjectId, |
| 27 | + clusterId: ovhClusterId, |
| 28 | + nodepoolId: ovhNodepoolId, |
| 29 | + desiredNodes: parseInt(nodesNumber), |
| 30 | + url: `/cloud/project/${ovhProjectId}/kube/${ovhClusterId}/nodepool/${ovhNodepoolId}`, |
| 31 | + method: "PUT", |
| 32 | + body: { |
| 33 | + autoscale: false, |
| 34 | + autoscaling: {}, |
| 35 | + minNodes: parseInt(nodesNumber), |
| 36 | + maxNodes: parseInt(nodesNumber), |
| 37 | + desiredNodes: parseInt(nodesNumber), |
| 38 | + }, |
| 39 | +}); |
| 40 | + |
| 41 | +let response; |
| 42 | +try { |
| 43 | + response = await client.requestPromised( |
| 44 | + "PUT", |
| 45 | + `/cloud/project/${ovhProjectId}/kube/${ovhClusterId}/nodepool/${ovhNodepoolId}`, |
| 46 | + { |
| 47 | + autoscale: false, |
| 48 | + autoscaling: {}, |
| 49 | + minNodes: parseInt(nodesNumber), |
| 50 | + maxNodes: parseInt(nodesNumber), |
| 51 | + desiredNodes: parseInt(nodesNumber), |
| 52 | + } |
| 53 | + ); |
26 | 54 |
|
27 | | - const response = await client.requestPromised('PUT', `/v1/cloud/project/${ovhProjectId}/kube/${ovhClusterId}/nodepool/${ovhNodepoolId}`, { |
28 | | - "desiredNodes": nodesNumber, |
29 | | - }); |
30 | | - setOutput("response", response) |
| 55 | + console.log("OVH API response:", response.code); |
| 56 | + setOutput("response", response); |
31 | 57 | } catch (err) { |
32 | | - setFailed(err.message) |
| 58 | + // Handle OVH API 204 No Content as success |
| 59 | + if (err && err.error === 204) { |
| 60 | + console.log("OVH API returned 204 No Content (success)"); |
| 61 | + setOutput("response", { code: 204, message: "No Content (success)" }); |
| 62 | + } else { |
| 63 | + setFailed(`Action error: ${err && err.message ? err.message : JSON.stringify(err)}`); |
| 64 | + } |
33 | 65 | } |
0 commit comments