Project: Headlamp (Observability and Analysis / Observability)
File: lib_k8s_apiProxy.md

title: "Module: lib/k8s/apiProxy" linkTitle: "lib/k8s/apiProxy" slug: "libk8sapiProxy" StreamErrCb: (`err`: `Error` & { `status?`: `number` }, `cancelStreamFunc?`: () => `void`) => `void` (`err`, `cancelStreamFunc?`): `void` The callback that's called when there's an error streaming the results. | Name | Type | | : | : | | `err` | `Error` & { `status?`: `number` } | | `cancelStreamFunc?` | () => `void` | `void` _ StreamResultsCb: (...`args`: `any`[]) => `void` (...`args`): `void` The callback that's called when some results are streamed in. | Name | Type | | : | : | | `...args` | `any`[] | `void` apiFactory(...`args`): `Object` Creates an API client for a single or multiple Kubernetes resources. | Name | Type | Description | | : | : | : | | `...args` | | The arguments to pass to either `singleApiFactory` or `multipleApiFactory`. | `Object` An API client for the specified Kubernetes resource(s). | Name | Type | | : | : | | `apiInfo` | { `group`: `string` ; `resource`: `string` ; `version`: `string` }[] | | `delete` | (`name`: `string`, `queryParams?`: , `cluster?`: `string`) => `Promise`<`any`\> | | `get` | (`name`: `string`, `cb`: , `errCb`: , `queryParams?`: , `cluster?`: `string`) => `Promise`<() => `void`\> | | `isNamespaced` | `boolean` | | `list` | (`cb`: , `errCb`: , `queryParams?`: , `cluster?`: `string`) => `Promise`<() => `void`\> | | `patch` | (`body`: `OpPatch`, `cluster?`: `string`) => `Promise`<`any`\> | | `post` | (`body`: , `queryParams?`: , `cluster?`: `string`) => `Promise`<`any`\> | | `put` | (`body`: , `queryParams?`: , `cluster?`: `string`) => `Promise`<`any`\> | _ apiFactoryWithNamespace(...`args`): `Object` | Name | Type | | : | : | | `...args` | | `Object` | Name | Type | | : | : | | `scale?` | { `get`: (`namespace`: `string`, `name`: `string`, `clusterName?`: `string`) => `Promise`<`any`\> ; `put`: (`body`: { `metadata`: ; `spec`: { `replicas`: `number` } }, `clusterName?`: `string`) => `Promise`<`any`\> } | | `scale.get` | (`namespace`: `string`, `name`: `string`, `clusterName?`: `string`) => `Promise`<`any`\> | | `scale.put` | (`body`: { `metadata`: ; `spec`: { `replicas`: `number` } }, `clusterName?`: `string`) => `Promise`<`any`\> | _ apply(`body`, `clusterName?`): `Promise`<`JSON`\> Applies the provided body to the Kubernetes API. Tries to POST, and if there's a conflict it does a PUT to the api endpoint. | Name | Type | Description | | : | : | : | | `body` | | The kubernetes object body to apply. | | `clusterName?` | `string` | The cluster to apply the body to. By default uses the current cluster (URL defined). | `Promise`<`JSON`\> The response from the kubernetes API server. _ clusterRequest(`path`, `params?`, `queryParams?`): `Promise`<`any`\> Sends a request to the backend. If the cluster is required in the params parameter, it will be used as a request to the respective Kubernetes server. `throws` An ApiError if the response status is not ok. | Name | Type | Description | | : | : | : | | `path` | `string` | The path to the API endpoint. | | `params` | | Optional parameters for the request. | | `queryParams?` | | Optional query parameters for the k8s

| `Promise`<`any`\> A Promise that resolves to the JSON response from the API server. _ deleteCluster(`cluster`): `Promise`<`any`\> | Name | Type | | : | : | | `cluster` | `string` | `Promise`<`any`\> _ deletePlugin(`name`): `Promise`<`any`\> Deletes the plugin with the specified name from the system. This function sends a DELETE request to the server's plugin management endpoint, targeting the plugin identified by its name. The function handles the request asynchronously and returns a promise that resolves with the server's response to the DELETE operation. `throws` An ApiError if the response status is not ok. `example` // Call to delete a plugin named 'examplePlugin' deletePlugin('examplePlugin') .then(response => console.log('Plugin deleted successfully', response)) .catch(error => console.error('Failed to delete plugin', error)); | Name | Type | Description | | : | : | : | | `name` | `string` | The unique name of the plugin to delete. This identifier is used to construct the URL for the DELETE request. | `Promise`<`any`\> A Promise that resolves to the JSON response from the API server. _ drainNode(`cluster`, `nodeName`): `Promise`<`any`\> Drain a node `throws` {Error} if the request fails `throws` {Error} if the response is not ok This function is used to drain a node. It is used in the node detail page. As draining a node is a long running process, we get the request received message if the request is successful. And then we poll the drain node status endpoint to get the status of the drain node process. | Name | Type | Description | | : | : | : | | `cluster` | `string` | The cluster to drain the node | | `nodeName` | `string` | The node name to drain | `Promise`<`any`\> _ drainNodeStatus(`cluster`, `nodeName`): `Promise`<`DrainNodeStatus`\> Get the status of the drain node process. It is used in the node detail page. As draining a node is a long running process, we poll this endpoint to get the status of the drain node process. `throws` {Error} if the request fails `throws` {Error} if the response is not ok | Name | Type | Description | | : | : | : | | `cluster` | `string` | The cluster to get the status of the drain node process for. | | `nodeName` | `string` | The node name to get the status of the drain node process for. | `Promise`<`DrainNodeStatus`\> The response from the API. @todo: what response? _ listPortForward(`cluster`): `Promise`<`any`\> Lists the port forwards for the specified cluster. | Name | Type | Description | | : | : | : | | `cluster` | `string` | The cluster to list the port forwards. | `Promise`<`any`\> the list of port forwards for the cluster. _ metrics(`url`, `onMetrics`, `onError?`, `cluster?`): `Promise`<() => `void`\> Gets the metrics for the specified resource. Gets new metrics every 10 seconds. | Name | Type | Description | | : | : | : | | `url` | `string` | The url of the resource to get metrics for. | | `onMetrics` | (`arg`: []) => `void` | The function to call with the metrics. | | `onError?` | (`err`: ) => `void` | The function to call if there's an

| | `cluster?` | `string` | The cluster to get metrics for. By default uses the current cluster (URL defined). | `Promise`<() => `void`\> A function to cancel the metrics request. _ patch(`url`, `json`, `autoLogoutOnAuthError?`, `options?`): `Promise`<`any`\> | Name | Type | Default value | | : | : | : | | `url` | `string` | `undefined` | | `json` | `any` | `undefined` | | `autoLogoutOnAuthError` | `boolean` | `true` | | `options` | | `{}` | `Promise`<`any`\> _ post(`url`, `json`, `autoLogoutOnAuthError?`, `options?`): `Promise`<`any`\> | Name | Type | Default value | | : | : | : | | `url` | `string` | `undefined` | | `json` | `object` \| \| `JSON` | `undefined` | | `autoLogoutOnAuthError` | `boolean` | `true` | | `options` | | `{}` | `Promise`<`any`\> _ put(`url`, `json`, `autoLogoutOnAuthError?`, `requestOptions?`): `Promise`<`any`\> | Name | Type | Default value | | : | : | : | | `url` | `string` | `undefined` | | `json` | `Partial`<\> | `undefined` | | `autoLogoutOnAuthError` | `boolean` | `true` | | `requestOptions` | | `{}` | `Promise`<`any`\> _ remove(`url`, `requestOptions?`): `Promise`<`any`\> | Name | Type | | : | : | | `url` | `string` | | `requestOptions` | | `Promise`<`any`\> _ request(`path`, `params?`, `autoLogoutOnAuthError?`, `useCluster?`, `queryParams?`): `Promise`<`any`\> Sends a request to the backend. If the useCluster parameter is true (which it is, by default), it will be treated as a request to the Kubernetes server of the currently defined (in the URL) cluster. `throws` An ApiError if the response status is not ok. | Name | Type | Default value | Description | | : | : | : | : | | `path` | `string` | `undefined` | The path to the API endpoint. | | `params` | | `{}` | Optional parameters for the request. | | `autoLogoutOnAuthError` | `boolean` | `true` | Whether to automatically log out the user if there is an authentication error. | | `useCluster` | `boolean` | `true` | Whether to use the current cluster for the request. | | `queryParams?` | | `undefined` | Optional query parameters for the request. | `Promise`<`any`\> A Promise that resolves to the JSON response from the API server. _ setCluster(`clusterReq`): `Promise`<`any`\> | Name | Type | | : | : | | `clusterReq` | | `Promise`<`any`\> _ startPortForward(`cluster`, `namespace`, `podname`, `containerPort`, `service`, `serviceNamespace`, `port?`, `address?`, `id?`): `Promise`<`any`\> Starts a portforward with the given details. `throws` {Error} if the request fails. | Name | Type | Default value | Description | | : | : | : | : | | `cluster` | `string` | `undefined` | The cluster to portforward for. | | `namespace` | `string` | `undefined` | The namespace to portforward for. | | `podname` | `string` | `undefined` | The pod to portforward for. | | `containerPort` | `string` \| `number` | `undefined` | The container port to portforward for. | | `service` | `string` | `undefined` | The service to portforward for. | | `serviceNamespace` | `string` | `undefined` | The service namespace to portforward for. | | `port?` | `string` | `undefined` | The port to portforward

| | `address` | `string` | `''` | - | | `id` | `string` | `''` | The id to portforward for. | `Promise`<`any`\> The response from the API. _ stopOrDeletePortForward(`cluster`, `id`, `stopOrDelete?`): `Promise`<`string`\> Stops or deletes a portforward with the specified details. `throws` {Error} if the request fails. | Name | Type | Default value | Description | | : | : | : | : | | `cluster` | `string` | `undefined` | The cluster to portforward for. | | `id` | `string` | `undefined` | The id to portforward for. | | `stopOrDelete` | `boolean` | `true` | Whether to stop or delete the portforward. True for stop, false for delete. | `Promise`<`string`\> The response from the API. _ stream(`url`, `cb`, `args`): `Object` Establishes a WebSocket connection to the specified URL and streams the results to the provided callback function. | Name | Type | Description | | : | : | : | | `url` | `string` | The URL to connect to. | | `cb` | | The callback function to receive the streamed results. | | `args` | | Additional arguments to configure the stream. | `Object` An object with two functions: `cancel`, which can be called to cancel the stream, and `getSocket`, which returns the WebSocket object. | Name | Type | | : | : | | `cancel` | () => `void` | | `getSocket` | () => ``null`` \| `WebSocket` | _ streamResult(`url`, `name`, `cb`, `errCb`, `queryParams?`, `cluster?`): `Promise`<() => `void`\> Streams the results of a Kubernetes API request into a 'cb' callback. | Name | Type | Description | | : | : | : | | `url` | `string` | The URL of the Kubernetes API endpoint. | | `name` | `string` | The name of the Kubernetes API resource. | | `cb` | | The callback function to execute when the stream receives data. | | `errCb` | | The callback function to execute when an error occurs. | | `queryParams?` | | The query parameters to include in the API request. | | `cluster?` | `string` | - | `Promise`<() => `void`\> A function to cancel the stream. _ streamResults(`url`, `cb`, `errCb`, `queryParams`): `Promise`<() => `void`\> Streams the results of a Kubernetes API request. | Name | Type | Description | | : | : | : | | `url` | `string` | The URL of the Kubernetes API endpoint. | | `cb` | | The callback function to execute when the stream receives data. | | `errCb` | | The callback function to execute when an error occurs. | | `queryParams` | `undefined` \| | The query parameters to include in the API request. | `Promise`<() => `void`\> A function to cancel the stream. _ streamResultsForCluster(`url`, `params`, `queryParams`): `Promise`<() => `void`\> | Name | Type | | : | : | | `url` | `string` | | `params` | | | `queryParams` | `undefined` \| | `Promise`<() => `void`\> _ testAuth(`cluster?`): `Promise`<`any`\> | Name | Type | Default value | | : | : | : | | `cluster` | `string` | `''` | `Promise`<`any`\> _ testClusterHealth(`cluster?`): `Promise`<`any`\> | Name | Type | | : | : | | `cluster?` | `string` | `Promise`<`any`\>