Edits history of script submission #11037 for ' Update a Node Pool in a Kubernetes Cluster (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update a Node Pool in a Kubernetes Cluster
     * To update the name of a node pool, edit the tags applied to it, or adjust its
    number of nodes, send a PUT request to
    `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/node_pools/$NODE_POOL_ID` with the
    following attributes.
    
     */
    export async function main(
      auth: Digitalocean,
      cluster_id: string,
      node_pool_id: string,
      body: {
        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/${node_pool_id}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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