0

Update a Kubernetes Cluster

by
Published Dec 20, 2024

To update a Kubernetes cluster, send a PUT request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID` and specify one or more of the attributes below.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Update a Kubernetes Cluster
7
 * To update a Kubernetes cluster, send a PUT request to
8
`/v2/kubernetes/clusters/$K8S_CLUSTER_ID` and specify one or more of the
9
attributes below.
10

11
 */
12
export async function main(
13
  auth: Digitalocean,
14
  cluster_id: string,
15
  body: {
16
    name: string;
17
    tags?: string[];
18
    maintenance_policy?: {
19
      start_time?: string;
20
      duration?: string;
21
      day?:
22
        | "any"
23
        | "monday"
24
        | "tuesday"
25
        | "wednesday"
26
        | "thursday"
27
        | "friday"
28
        | "saturday"
29
        | "sunday";
30
    };
31
    auto_upgrade?: false | true;
32
    surge_upgrade?: false | true;
33
    ha?: false | true;
34
    control_plane_firewall?: {
35
      enable?: false | true;
36
      allowed_addresses?: string[];
37
    };
38
  },
39
) {
40
  const url = new URL(
41
    `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}`,
42
  );
43

44
  const response = await fetch(url, {
45
    method: "PUT",
46
    headers: {
47
      "Content-Type": "application/json",
48
      Authorization: "Bearer " + auth.token,
49
    },
50
    body: JSON.stringify(body),
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.json();
57
}
58