//native
type Digitalocean = {
token: string;
};
/**
* Create a New Kubernetes Cluster
* To create a new Kubernetes cluster, send a POST request to
`/v2/kubernetes/clusters`. The request must contain at least one node pool
with at least one worker.
The request may contain a maintenance window policy describing a time period
when disruptive maintenance tasks may be carried out. Omitting the policy
implies that a window will be chosen automatically. See
[here](https://docs.digitalocean.com/products/kubernetes/how-to/upgrade-cluster/)
for details.
*/
export async function main(
auth: Digitalocean,
body: {
id?: string;
name: string;
region: string;
version: string;
cluster_subnet?: string;
service_subnet?: string;
vpc_uuid?: string;
ipv4?: string;
endpoint?: string;
tags?: string[];
node_pools: { size?: string } & {
id?: string;
name?: string;
count?: number;
tags?: string[];
labels?: {};
taints?: {
key?: string;
value?: string;
effect?: "NoSchedule" | "PreferNoSchedule" | "NoExecute";
}[];
auto_scale?: false | true;
min_nodes?: number;
max_nodes?: number;
nodes?: {
id?: string;
name?: string;
status?: {
state?: "provisioning" | "running" | "draining" | "deleting";
};
droplet_id?: string;
created_at?: string;
updated_at?: string;
}[];
}[];
maintenance_policy?: {
start_time?: string;
duration?: string;
day?:
| "any"
| "monday"
| "tuesday"
| "wednesday"
| "thursday"
| "friday"
| "saturday"
| "sunday";
};
auto_upgrade?: false | true;
status?: {
state?:
| "provisioning"
| "running"
| "deleting"
| "degraded"
| "error"
| "deleted"
| "upgrading";
message?: string;
};
created_at?: string;
updated_at?: string;
surge_upgrade?: false | true;
ha?: false | true;
registry_enabled?: false | true;
control_plane_firewall?: {
enable?: false | true;
allowed_addresses?: string[];
};
},
) {
const url = new URL(`https://api.digitalocean.com/v2/kubernetes/clusters`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago