Edits history of script submission #11050 for ' Upgrade a Kubernetes Cluster (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Upgrade a Kubernetes Cluster
     * To immediately upgrade a Kubernetes cluster to a newer patch release of
    Kubernetes, send a POST request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/upgrade`.
    The body of the request must specify a version attribute.
    
    Available upgrade versions for a cluster can be fetched from
    `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/upgrades`.
    
     */
    export async function main(
      auth: Digitalocean,
      cluster_id: string,
      body: { version?: string },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}/upgrade`,
      );
    
      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