0

Recycle a Kubernetes Node Pool

by
Published Dec 20, 2024

The endpoint has been deprecated. Please use the DELETE `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools/$NODE_POOL_ID/nodes/$NODE_ID` method instead.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Recycle a Kubernetes Node Pool
7
 * The endpoint has been deprecated. Please use the DELETE
8
`/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools/$NODE_POOL_ID/nodes/$NODE_ID`
9
method instead.
10

11
 */
12
export async function main(
13
  auth: Digitalocean,
14
  cluster_id: string,
15
  node_pool_id: string,
16
  body: { nodes?: string[] },
17
) {
18
  const url = new URL(
19
    `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}/node_pools/${node_pool_id}/recycle`,
20
  );
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36