Module: lib/k8s/apiProxy
Interfaces
- ApiError
- ApiInfo
- ClusterRequest
- ClusterRequestParams
- QueryParameters
- RequestParams
- StreamArgs
- StreamResultsParams
Type aliases
StreamErrCb
Ƭ StreamErrCb: (err
: Error
& { status?
: number
}, cancelStreamFunc?
: () => void
) => void
Type declaration
▸ (err
, cancelStreamFunc?
): void
The callback that’s called when there’s an error streaming the results.
Parameters
Name | Type |
---|---|
err |
Error & { status? : number } |
cancelStreamFunc? |
() => void |
Returns
void
Defined in
StreamResultsCb
Ƭ StreamResultsCb: (…args
: any
[]) => void
Type declaration
▸ (…args
): void
The callback that’s called when some results are streamed in.
Parameters
Name | Type |
---|---|
...args |
any [] |
Returns
void
Defined in
Functions
apiFactory
▸ apiFactory(…args
): Object
Creates an API client for a single or multiple Kubernetes resources.
Parameters
Name | Type | Description |
---|---|---|
...args |
[group: string, version: string, resource: string] | [group: string, version: string, resource: string][] | The arguments to pass to either singleApiFactory or multipleApiFactory . |
Returns
Object
An API client for the specified Kubernetes resource(s).
Name | Type |
---|---|
apiInfo |
{ group : string ; resource : string ; version : string }[] |
delete |
(name : string , queryParams? :
QueryParameters
, cluster? : string ) => Promise <any > |
get |
(name : string , cb :
StreamResultsCb
, errCb :
StreamErrCb
, queryParams? :
QueryParameters
, cluster? : string ) => Promise <() => void > |
isNamespaced |
boolean |
list |
(cb :
StreamResultsCb
, errCb :
StreamErrCb
, queryParams? :
QueryParameters
, cluster? : string ) => Promise <() => void > |
patch |
(body : OpPatch [], name : string , queryParams? :
QueryParameters
, cluster? : string ) => Promise <any > |
post |
(body :
KubeObjectInterface
, queryParams? :
QueryParameters
, cluster? : string ) => Promise <any > |
put |
(body :
KubeObjectInterface
, queryParams? :
QueryParameters
, cluster? : string ) => Promise <any > |
Defined in
apiFactoryWithNamespace
▸ apiFactoryWithNamespace(…args
): Object
Parameters
Name | Type |
---|---|
...args |
[group: string, version: string, resource: string, includeScale: boolean] | [group: string, version: string, resource: string, includeScale: boolean][] |
Returns
Object
Name | Type |
---|---|
scale? |
{ get : (namespace : string , name : string , clusterName? : string ) => Promise <any > ; put : (body : { metadata :
KubeMetadata
; spec : { replicas : number } }, clusterName? : string ) => Promise <any > } |
scale.get |
(namespace : string , name : string , clusterName? : string ) => Promise <any > |
scale.put |
(body : { metadata :
KubeMetadata
; spec : { replicas : number } }, clusterName? : string ) => Promise <any > |
Defined in
apply
▸ 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.
Parameters
Name | Type | Description |
---|---|---|
body |
KubeObjectInterface
|
The kubernetes object body to apply. |
clusterName? |
string |
The cluster to apply the body to. By default uses the current cluster (URL defined). |
Returns
Promise
<JSON
>
The response from the kubernetes API server.
Defined in
clusterRequest
▸ 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.
Parameters
Name | Type | Description |
---|---|---|
path |
string |
The path to the API endpoint. |
params |
ClusterRequestParams
|
Optional parameters for the request. |
queryParams? |
QueryParameters
|
Optional query parameters for the k8s request. |
Returns
Promise
<any
>
A Promise that resolves to the JSON response from the API server.
Defined in
deleteCluster
▸ deleteCluster(cluster
): Promise
<any
>
Parameters
Name | Type |
---|---|
cluster |
string |
Returns
Promise
<any
>
Defined in
deletePlugin
▸ 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));
Parameters
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. |
Returns
Promise
<any
>
— A Promise that resolves to the JSON response from the API server.
Defined in
drainNode
▸ 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.
Parameters
Name | Type | Description |
---|---|---|
cluster |
string |
The cluster to drain the node |
nodeName |
string |
The node name to drain |
Returns
Promise
<any
>
Defined in
drainNodeStatus
▸ 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
Parameters
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. |
Returns
Promise
<DrainNodeStatus
>
- The response from the API.
Defined in
listPortForward
▸ listPortForward(cluster
): Promise
<any
>
Lists the port forwards for the specified cluster.
Parameters
Name | Type | Description |
---|---|---|
cluster |
string |
The cluster to list the port forwards. |
Returns
Promise
<any
>
the list of port forwards for the cluster.
Defined in
metrics
▸ metrics(url
, onMetrics
, onError?
, cluster?
): Promise
<() => void
>
Gets the metrics for the specified resource. Gets new metrics every 10 seconds.
Parameters
Name | Type | Description |
---|---|---|
url |
string |
The url of the resource to get metrics for. |
onMetrics |
(arg :
KubeMetrics
[]) => void |
The function to call with the metrics. |
onError? |
(err :
ApiError
) => void |
The function to call if there’s an error. |
cluster? |
string |
The cluster to get metrics for. By default uses the current cluster (URL defined). |
Returns
Promise
<() => void
>
A function to cancel the metrics request.
Defined in
patch
▸ patch(url
, json
, autoLogoutOnAuthError?
, options?
): Promise
<any
>
Parameters
Name | Type | Default value |
---|---|---|
url |
string |
undefined |
json |
any |
undefined |
autoLogoutOnAuthError |
boolean |
true |
options |
ClusterRequestParams
|
{} |
Returns
Promise
<any
>
Defined in
post
▸ post(url
, json
, autoLogoutOnAuthError?
, options?
): Promise
<any
>
Parameters
Name | Type | Default value |
---|---|---|
url |
string |
undefined |
json |
object |
KubeObjectInterface
| JSON |
undefined |
autoLogoutOnAuthError |
boolean |
true |
options |
ClusterRequestParams
|
{} |
Returns
Promise
<any
>
Defined in
put
▸ put(url
, json
, autoLogoutOnAuthError?
, requestOptions?
): Promise
<any
>
Parameters
Name | Type | Default value |
---|---|---|
url |
string |
undefined |
json |
Partial <
KubeObjectInterface
> |
undefined |
autoLogoutOnAuthError |
boolean |
true |
requestOptions |
ClusterRequestParams
|
{} |
Returns
Promise
<any
>
Defined in
remove
▸ remove(url
, requestOptions?
): Promise
<any
>
Parameters
Name | Type |
---|---|
url |
string |
requestOptions |
ClusterRequestParams
|
Returns
Promise
<any
>
Defined in
request
▸ 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.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
path |
string |
undefined |
The path to the API endpoint. |
params |
RequestParams
|
{} |
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? |
QueryParameters
|
undefined |
Optional query parameters for the request. |
Returns
Promise
<any
>
A Promise that resolves to the JSON response from the API server.
Defined in
setCluster
▸ setCluster(clusterReq
): Promise
<any
>
Parameters
Name | Type |
---|---|
clusterReq |
ClusterRequest
|
Returns
Promise
<any
>
Defined in
startPortForward
▸ 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.
Parameters
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 for. |
address |
string |
'' |
- |
id |
string |
'' |
The id to portforward for. |
Returns
Promise
<any
>
The response from the API.
Defined in
stopOrDeletePortForward
▸ stopOrDeletePortForward(cluster
, id
, stopOrDelete?
): Promise
<string
>
Stops or deletes a portforward with the specified details.
throws
{Error} if the request fails.
Parameters
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. |
Returns
Promise
<string
>
The response from the API.
Defined in
stream
▸ stream(url
, cb
, args
): Object
Establishes a WebSocket connection to the specified URL and streams the results to the provided callback function.
Parameters
Name | Type | Description |
---|---|---|
url |
string |
The URL to connect to. |
cb |
StreamResultsCb
|
The callback function to receive the streamed results. |
args |
StreamArgs
|
Additional arguments to configure the stream. |
Returns
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 |
Defined in
streamResult
▸ streamResult(url
, name
, cb
, errCb
, queryParams?
, cluster?
): Promise
<() => void
>
Streams the results of a Kubernetes API request into a ‘cb’ callback.
Parameters
Name | Type | Description |
---|---|---|
url |
string |
The URL of the Kubernetes API endpoint. |
name |
string |
The name of the Kubernetes API resource. |
cb |
StreamResultsCb
|
The callback function to execute when the stream receives data. |
errCb |
StreamErrCb
|
The callback function to execute when an error occurs. |
queryParams? |
QueryParameters
|
The query parameters to include in the API request. |
cluster? |
string |
- |
Returns
Promise
<() => void
>
A function to cancel the stream.
Defined in
streamResults
▸ streamResults(url
, cb
, errCb
, queryParams
): Promise
<() => void
>
Streams the results of a Kubernetes API request.
Parameters
Name | Type | Description |
---|---|---|
url |
string |
The URL of the Kubernetes API endpoint. |
cb |
StreamResultsCb
|
The callback function to execute when the stream receives data. |
errCb |
StreamErrCb
|
The callback function to execute when an error occurs. |
queryParams |
undefined |
QueryParameters
|
The query parameters to include in the API request. |
Returns
Promise
<() => void
>
A function to cancel the stream.
Defined in
streamResultsForCluster
▸ streamResultsForCluster(url
, params
, queryParams
): Promise
<() => void
>
Parameters
Name | Type |
---|---|
url |
string |
params |
StreamResultsParams
|
queryParams |
undefined |
QueryParameters
|
Returns
Promise
<() => void
>
Defined in
testAuth
▸ testAuth(cluster?
): Promise
<any
>
Parameters
Name | Type | Default value |
---|---|---|
cluster |
string |
'' |
Returns
Promise
<any
>
Defined in
testClusterHealth
▸ testClusterHealth(cluster?
): Promise
<any
>
Parameters
Name | Type |
---|---|
cluster? |
string |
Returns
Promise
<any
>