ClusterApi
Provides access to the Cluster API which can be used for managing cluster resources in Rancher UI
Requests are scoped to the cluster currently being viewed. For global Rancher resources (Users, Projects, Settings, etc.) use the Management API instead - see MgmtApi.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Namespaced resource - ID must be in "namespace/name" format
const pod = await resources.cluster.find(K8S.POD, 'default/my-pod-123');
// Cluster-scoped resource - ID is just the name
const node = await resources.cluster.find(K8S.NODE, 'worker-1');
Methods
create()
create<T, I>(data): Promise<I>;
Creates a new resource.
The data object must include a type property identifying the resource type.
This is a raw HTTP operation — it does not check permissions or update the store cache.
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = SteveResource<T>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
data
The resource data to create. Must include a type property (examples in K8S). See also CreateResourceData.
Returns
Promise<I>
The created resource instance.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
const configMap = await api.create({
type: K8S.CONFIG_MAP,
metadata: { name: 'my-config', namespace: 'default' },
data: { key: 'value' }
});
delete()
delete(resourceType, resourceId): Promise<void>;
Deletes a resource by type and ID using HTTP DELETE.
This is a raw HTTP operation — it does not check permissions or update the store cache.
Parameters
resourceType
string
The type of the resource (examples in K8S). See also ResourceType.
resourceId
string
The unique identifier. If namespaced, use namespace/name format.
Returns
Promise<void>
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
await api.delete(K8S.CONFIG_MAP, 'default/my-config');
find()
find<T, I>(
resourceType,
resourceId,
options?): Promise<I>;
Finds a specific resource by its type and ID.
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = ResourceInstance<T>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
resourceType
string
The type of the resource to find (examples in K8S). See also ResourceType.
resourceId
string
The unique identifier of the resource to find. If the resource is namespaced, this should be in the format namespace/name.
options?
Optional find arguments
Returns
Promise<I>
The found resource item or null if not found.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
// Namespaced resource - ID must be in "namespace/name" format
const pod = await api.find(K8S.POD, 'default/my-pod-123');
// Cluster-scoped resource - ID is just the name
const node = await api.find(K8S.NODE, 'worker-1');
findAll()
findAll<T, I>(resourceType, options?): Promise<I[]>;
Fetches all resources of a specific type with advanced options. This method provides additional capabilities like incremental loading and namespace filtering.
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = ResourceInstance<T>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
resourceType
string
The type of the resources to find (examples in K8S). See also ResourceType.
options?
Optional advanced fetch options (incremental loading, namespace filtering, etc.)
Returns
Promise<I[]>
An array of resource items or an empty array if none are found.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
const allPods = await api.findAll(K8S.POD, {
namespaced: ['default', 'kube-system']
});
findFiltered()
Call Signature
findFiltered<T, I>(resourceType, options): Promise<I>;
Finds resources using pagination mode with server-side filtering, sorting, and pagination.
The response is not cached
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = ActionFindPageTransientResponse<ResourceInstance<T>>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
resourceType
string
The type of the resources to find (examples in K8S). See also ResourceType.
options
FindFilteredPageOptionsTransient
Pagination options with server-side filtering and sorting via the Steve API's pagination cache. See FindFilteredPageOptions.
Returns
Promise<I>
Response containing resource items
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
const pods = await api.findFiltered(K8S.POD, {
transient: true,
pagination: {
page: 1,
pageSize: 10,
filters: [],
sort: []
}
});
Call Signature
findFiltered<T, I>(resourceType, options): Promise<I[]>;
Finds resources using pagination mode with server-side filtering, sorting, and pagination.
The response is cached.
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = ResourceInstance<T>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
resourceType
string
The type of the resources to find (examples in K8S). See also ResourceType.
options
Pagination options with server-side filtering and sorting via the Steve API's pagination cache. See FindFilteredPageOptions.
Returns
Promise<I[]>
Response containing resource items
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
const pods = await api.findFiltered(K8S.POD, {
pagination: {
page: 1,
pageSize: 10,
filters: [],
sort: []
}
});
Call Signature
findFiltered<T, I>(resourceType, options): Promise<I>;
Finds resources using label selector matching.