0

Fetch Clusterlint Diagnostics for a Kubernetes Cluster

by
Published Dec 20, 2024

To request clusterlint diagnostics for your cluster, send a GET request to `/v2/kubernetes/clusters/$K8S_CLUSTER_ID/clusterlint`. If the `run_id` query parameter is provided, then the diagnostics for the specific run is fetched. By default, the latest results are shown. To find out how to address clusterlint feedback, please refer to [the clusterlint check documentation](https://github.com/digitalocean/clusterlint/blob/master/checks.md).

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Fetch Clusterlint Diagnostics for a Kubernetes Cluster
7
 * To request clusterlint diagnostics for your cluster, send a GET request to
8
`/v2/kubernetes/clusters/$K8S_CLUSTER_ID/clusterlint`. If the `run_id` query
9
parameter is provided, then the diagnostics for the specific run is fetched.
10
By default, the latest results are shown.
11

12
To find out how to address clusterlint feedback, please refer to
13
[the clusterlint check documentation](https://github.com/digitalocean/clusterlint/blob/master/checks.md).
14

15
 */
16
export async function main(
17
  auth: Digitalocean,
18
  cluster_id: string,
19
  run_id: string | undefined,
20
) {
21
  const url = new URL(
22
    `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_id}/clusterlint`,
23
  );
24
  for (const [k, v] of [["run_id", run_id]]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42