Edits history of script submission #10708 for ' Add a Node Pool to a Kubernetes Cluster (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Add a Node Pool to a Kubernetes Cluster
     * To add an additional node pool to a Kubernetes clusters, send a POST request
    to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools` with the following
    attributes.
    
     */
    export async function main(
      auth: Digitalocean,
      cluster_id: string,
      body: { 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;
        }[];
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}/node_pools`,
      );
    
      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 537 days ago