Multicluster SDK for OpenShift Console
A React SDK for working with multicluster OpenShift/Kubernetes resources from the OpenShift Console.
This SDK provides extensions and APIs that dynamic plugins can use to leverage multicluster capabilities provided by Red Hat Advanced Cluster Management (RHACM). It aims to provide similar functionality to the dynamic plugin(https://www.npmjs.com/package/@openshift-console/dynamic-plugin-sdk) SDK but for multicluster scenarios.
Prerequisites
- Red Hat Advanced Cluster Management for Kubernetes 2.15+
Installation
npm install @stolostron/multicluster-sdk
Usage
The multicluster SDK provides components and hooks that enable your dynamic plugins to work with resources across multiple clusters.
Basic Setup
Setup depends on your usage scenarios.
- For pages that deal with a single cluster at a time, you can replace hooks, functions, and components from the dynamic plugin SDK with their drop-in replacements from the multicluster SDK. When a compatible version of RHACM is installed on the cluster and a cluster name is given in the arguments or properties of an SDK API, an implementation that works with data from the specified managed cluster will be used. Otherwise, we fall back to the single cluster implementation from the dynamic plugin SDK and work with data on the local cluster.
- For other APIs that work with multiple clusters at a time (such as functions that leverage RHACM's search capabilities) and do not have an equivalent in the dyanamic plugin SDK, you can call the
useIsFleetAvailable
hook to check if support is available. Because it is not permitted to call hooks conditionally, if you are using these multicluster SDK hooks, then you must call them with arguments that render the hook in a disabled state when fleet support is unavailable. Otherwise you will get empty results or errors. See the API Reference for details.
- If you have entire routes or navigation items or any other type of dynamic plugin extension that should only be enabled when multicluster support is available, you can make them conditional on a flag. RHACM enables flags indicating that it provides the prerequisites of the multicluster SDK. This is a versioned flag and within any version of the multicluster SDK, its name is available as the
REQUIRED_PROVIDER_FLAG
constant.
Working with Resources
// Example code will be added after API stabilization
API Reference
:toolbox: Functions
:gear: fleetK8sCreate
A fleet version of k8sCreate
from
the dynamic plugin SDK that creates a resource on the specified cluster.
The cluster name can be specified in options or the payload, with the value from options taking precedence.
If the cluster name is not specified or matches the name of the hub cluster, the implementation from the dynamic plugin SDK is used.
fleetK8sCreate | <R extends FleetK8sResourceCommon>(options: FleetK8sCreateUpdateOptions<R>) => Promise<R> |
Parameters:
options
: Which are passed as key-value pairs in the map
options.cluster
: - the cluster on which to create the resource
options.model
: - Kubernetes model
options.data
: - payload for the resource to be created
options.path
: - Appends as subpath if provided
options.queryParams
: - The query parameters to be included in the URL.
Returns:
A promise that resolves to the response of the resource created.
In case of failure, the promise gets rejected with HTTP error response.
:link: Source
:gear: fleetK8sDelete
A fleet version of k8sDelete
from
the dynamic plugin SDK that deletes resources from the specified cluster, based on the provided model and resource.
The cluster name can be specified in options or the resource, with the value from options taking precedence.
If the cluster name is not specified or matches the name of the hub cluster, the implementation from the dynamic plugin SDK is used.
The garbage collection works based on 'Foreground' | 'Background', can be configured with propagationPolicy
property in provided model or passed in json.
fleetK8sDelete | <R extends FleetK8sResourceCommon>(options: FleetK8sDeleteOptions<R>) => Promise<R> |
Parameters:
options
: which are passed as key-value pair in the map.
options.cluster
: - the cluster from which to delete the resource
options.model
: - Kubernetes model
options.resource
: - The resource to be deleted.
options.path
: - Appends as subpath if provided.
options.queryParams
: - The query parameters to be included in the URL.
options.requestInit
: - The fetch init object to use. This can have request headers, method, redirect, etc. See more https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules_typedoc_node_modules_typescript_lib_lib_dom_d_.requestinit.html
options.json
: - Can control garbage collection of resources explicitly if provided else will default to model's propagationPolicy
.
Returns:
A promise that resolves to the response of kind Status.
In case of failure promise gets rejected with HTTP error response.
Examples:
{ kind: 'DeleteOptions', apiVersion: 'v1', propagationPolicy }
:link: Source
:gear: fleetK8sGet
A fleet version of k8sGet
from
the dynamic plugin SDK that fetches a resource from the specified cluster, based on the provided options.
If the cluster name is not specified or matches the name of the hub cluster, the implementation from the dynamic plugin SDK is used.
If the name is provided it returns resource, else it returns all the resources matching the model.
fleetK8sGet | <R extends FleetK8sResourceCommon>(options: FleetK8sGetOptions) => Promise<R> |
Parameters:
options
: Which are passed as key-value pairs in the map
options.cluster
: - the cluster from which to fetch the resource
options.model
: - Kubernetes model
options.name
: - The name of the resource, if not provided then it looks for all the resources matching the model.
options.ns
: - The namespace to look into, should not be specified for cluster-scoped resources.
options.path
: - Appends as subpath if provided
options.queryParams
: - The query parameters to be included in the URL.
options.requestInit
: - The fetch init object to use. This can have request headers, method, redirect, etc. See more https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules_typedoc_node_modules_typescript_lib_lib_dom_d_.requestinit.html
Returns:
A promise that resolves to the response as JSON object with a resource if the name is provided, else it returns all the resources matching the model. In case of failure, the promise gets rejected with HTTP error response.
:link: Source
:gear: fleetK8sList
A fleet version of k8sList
from
the dynamic plugin SDK that lists the resources as an array in the specified cluster, based on the provided options.
If the cluster name is not specified or matches the name of the hub cluster, the implementation from the dynamic plugin SDK is used.
fleetK8sList | <R extends FleetK8sResourceCommon>(options: FleetK8sListOptions) => Promise<R[]> |
Parameters:
Returns:
A promise that resolves to the response
:link: Source
:gear: fleetK8sListItems
A fleet version of k8sListItems
from
the dynamic plugin SDK that lists the resources as an array in the specified cluster, based on the provided options.
If the cluster name is not specified or matches the name of the hub cluster, the implementation from the dynamic plugin SDK is used.
fleetK8sListItems | <R extends FleetK8sResourceCommon>(options: FleetK8sListOptions) => Promise<R[]> |
Parameters:
Returns:
A promise that resolves to the response
:link: Source
:gear: fleetK8sPatch
A fleet version of k8sPatch
from
the dynamic plugin SDK that patches any resource on the specified cluster, based on the provided options.
The cluster name can be specified in options or the resource, with the value from options taking precedence.
If the cluster name is not specified or matches the name of the hub cluster, the implementation from the dynamic plugin SDK is used.
When a client needs to perform the partial update, the client can use fleetK8sPatch
.
Alternatively, the client can use fleetK8sUpdate
to replace an existing resource entirely.
See more https://datatracker.ietf.org/doc/html/rfc6902
fleetK8sPatch | <R extends FleetK8sResourceCommon>(options: FleetK8sPatchOptions<R>) => Promise<R> |
Parameters:
options
: Which are passed as key-value pairs in the map.
options.cluster
: - the cluster on which to patch the resource
options.model
: - Kubernetes model
options.resource
: - The resource to be patched.
options.data
: - Only the data to be patched on existing resource with the operation, path, and value.
options.path
: - Appends as subpath if provided.
options.queryParams
: - The query parameters to be included in the URL.
Returns:
A promise that resolves to the response of the resource patched.
In case of failure promise gets rejected with HTTP error response.
:link: Source
:gear: fleetK8sUpdate
A fleet version of k8sPatch
from
the dynamic plugin SDK that updates the entire resource on the specified cluster, based on the provided options.
The cluster name can be specified in options or the payload, with the value from options taking precedence.
If the cluster name is not specified or matches the name of the hub cluster, the implementation from the dynamic plugin SDK is used.
When a client needs to replace an existing resource entirely, the client can use fleetK8sUpdate
.
Alternatively, the client can use fleetK8sPatch
to perform the partial update.
fleetK8sUpdate | <R extends FleetK8sResourceCommon>(options: FleetK8sCreateUpdateOptions<R>) => Promise<R> |
Parameters:
options
: which are passed as key-value pair in the map
options.cluster
: - the cluster on which to update the resource
options.model
: - Kubernetes model
options.data
: - payload for the Kubernetes resource to be updated
options.ns
: - namespace to look into, it should not be specified for cluster-scoped resources.
options.name
: - resource name to be updated.
options.path
: - appends as subpath if provided.
options.queryParams
: - The query parameters to be included in the URL.
Returns:
A promise that resolves to the response of the resource updated.
In case of failure promise gets rejected with HTTP error response.
:link: Source
:gear: FleetResourceEventStream
A multicluster-aware ResourceEventStream component that displays real-time Kubernetes events
for resources on managed clusters. Provides equivalent functionality to the OpenShift console's
ResourceEventStream for resources on managed clusters.
For managed cluster resources, this component establishes a websocket connection to stream
events from the specified cluster. For hub cluster resources or when no cluster is specified,
it falls back to the standard OpenShift console ResourceEventStream component.
FleetResourceEventStream | FC<FleetResourceEventStreamProps> |
Parameters:
props
: - Component properties
props.resource
: - The Kubernetes resource to show events for.
Must include standard K8s metadata (name, namespace, uid, kind) and an optional cluster property.
Returns:
A rendered event stream component showing real-time Kubernetes events
Examples:
// Display events for a resource on a managed cluster
<FleetResourceEventStream
resource={{
metadata: { name: 'my-pod', namespace: 'default', uid: '123' },
kind: 'Pod',
cluster: 'managed-cluster-1'
}}
/>
// Display events for a hub cluster resource (falls back to OpenShift console component)
<FleetResourceEventStream
resource={{
metadata: { name: 'my-deployment', namespace: 'openshift-gitops', uid: '456' },
kind: 'Deployment'
// No cluster property - uses hub cluster
}}
/>
// Display events for a cluster-scoped resource on a managed cluster
<FleetResourceEventStream
resource={{
metadata: { name: 'my-node', uid: '789' },
kind: 'Node',
cluster: 'edge-cluster-2'
}}
/>
:link: Source
:gear: FleetResourceLink
Enhanced ResourceLink component for ACM fleet environments.
Unlike the standard OpenShift ResourceLink which always links to the OpenShift console,
FleetResourceLink provides intelligent routing based on cluster context:
- First-class ACM resources (ManagedCluster) get direct links in all cases
- For hub clusters: Extension-based routing first, then fallback to OpenShift console
- For managed clusters: Extension-based routing first, then fallback to ACM search results
This prevents users from having to jump between different consoles when managing
multi-cluster resources.
FleetResourceLink | React.FC<FleetResourceLinkProps> |
Parameters:
props
: - FleetResourceLinkProps extending ResourceLinkProps with cluster information
props.cluster
: - the target cluster name for the resource
props.groupVersionKind
: - K8s GroupVersionKind for the resource
props.name
: - the resource name
props.namespace
: - the resource namespace (required for namespaced resources)
props.displayName
: - optional display name override
props.className
: - additional CSS classes
props.inline
: - whether to display inline
props.hideIcon
: - whether to hide the resource icon
props.children
: - additional content to render
Examples:
<FleetResourceLink
name="my-vm"
namespace="default"
groupVersionKind={{ group: 'kubevirt.io', version: 'v1', kind: 'VirtualMachine' }}
/>
<FleetResourceLink
name="remote-vm"
namespace="default"
cluster="prod-cluster"
groupVersionKind={{ group: 'kubevirt.io', version: 'v1', kind: 'VirtualMachine' }}
/>
<FleetResourceLink
name="prod-cluster"
groupVersionKind={{ group: 'cluster.open-cluster-management.io', version: 'v1', kind: 'ManagedCluster' }}
/>
:link: Source
:gear: getFleetK8sAPIPath
Function that provides the k8s API path for the fleet.
getFleetK8sAPIPath | (cluster?: string or undefined) => Promise<string> |
Parameters:
cluster
: - The cluster name.
Returns:
The k8s API path for the fleet.
:link: Source
:gear: useFleetAccessReview
Hook that provides information about user access to a given resource.
useFleetAccessReview | ({ group, resource, subresource, verb, name, namespace, cluster, }: FleetAccessReviewResourceAttributes) => [boolean, boolean] |
Parameters:
resourceAttributes
: resource attributes for access review
resourceAttributes.group
: the name of the group to check access for
resourceAttributes.resource
: the name of the resource to check access for
resourceAttributes.subresource
: the name of the subresource to check access for
resourceAttributes.verb
: the "action" to perform; one of 'create' | 'get' | 'list' | 'update' | 'patch' | 'delete' | 'deletecollection' | 'watch' | 'impersonate'
resourceAttributes.name
: the name
resourceAttributes.namespace
: the namespace
resourceAttributes.cluster
: the cluster name to find the resource in
Returns:
Array with isAllowed
and loading
values.
:link: Source
:gear: useFleetClusterNames
Hook that returns names of managed clusters with optional filtering by cluster proxy addon and availability status.
This hook watches ManagedCluster resources and by default filters them to only include clusters
that have both the label feature.open-cluster-management.io/addon-cluster-proxy: available
AND
the condition ManagedClusterConditionAvailable
with status True
.
useFleetClusterNames | (returnAllClusters?: boolean) => [string[], boolean, any] |
Parameters:
returnAllClusters
: - Optional boolean to return all cluster names regardless of labels and conditions.
Defaults to false. When false (default), only returns clusters with the
'feature.open-cluster-management.io/addon-cluster-proxy: available' label AND
'ManagedClusterConditionAvailable' status: 'True'.
When true, returns all cluster names regardless of labels and conditions.
Returns:
A tuple containing:
- clusterNames: Array of cluster names (filtered by default, or all clusters if specified)
- loaded: Boolean indicating if the resource watch has loaded
- error: Any error that occurred during the watch operation
Examples:
const [availableClusterNames, loaded, error] = useFleetClusterNames()
const [allClusterNames, loaded, error] = useFleetClusterNames(true)
const [filteredClusterNames, loaded, error] = useFleetClusterNames(false)
if (!loaded) {
return <Loading />
}
if (error) {
return <ErrorState error={error} />
}
return (
<div>
{availableClusterNames.map(name => (
<div key={name}>{name}</div>
))}
</div>
)
:link: Source
:gear: useFleetK8sAPIPath
Hook that provides the k8s API path for the fleet.
useFleetK8sAPIPath | (cluster?: string or undefined) => [k8sAPIPath: string or undefined, loaded: boolean, error: Error or undefined] |
Parameters:
cluster
: - The cluster name.
Returns:
Array with k8sAPIPath
, loaded
and error
values.
:link: Source
:gear: useFleetK8sWatchResource
A hook for watching Kubernetes resources with support for multi-cluster environments.
It is equivalent to the useK8sWatchResource
hook from the OpenShift Console Dynamic Plugin SDK
but allows you to retrieve data from any cluster managed by Red Hat Advanced Cluster Management.
It automatically detects the hub cluster and handles resource watching on both hub
and remote clusters using WebSocket connections for real-time updates.
useFleetK8sWatchResource | <R extends FleetK8sResourceCommon or FleetK8sResourceCommon[]>(initResource: FleetWatchK8sResource or null) => WatchK8sResult<R> or [undefined, boolean, any] |
Parameters:
initResource
: - The resource to watch. Can be null to disable the watch.
initResource.cluster
: - The managed cluster on which the resource resides; null for the hub cluster
Returns:
A tuple containing the watched resource data, a boolean indicating if the data is loaded,
and any error that occurred. The hook returns live-updating data.
Examples:
const [pods, loaded, error] = useFleetK8sWatchResource({
groupVersionKind: { version: 'v1', kind: 'Pod' },
isList: true,
cluster: 'remote-cluster',
namespace: 'default'
})
const [deployment, loaded, error] = useFleetK8sWatchResource({
groupVersionKind: { group: 'apps', version: 'v1', kind: 'Deployment' },
name: 'my-app',
namespace: 'default'
})
:link: Source
:gear: useFleetPrometheusPoll
useFleetPrometheusPoll | (props: PrometheusPollProps and { cluster?: string or undefined; } and { allClusters?: boolean or undefined; }) => [response: PrometheusResponse or undefined, loaded: boolean, error: unknown] |
:link: Source
:gear: useFleetSearchPoll
A React hook that provides fleet-wide search functionality using the ACM search API.
useFleetSearchPoll | <T extends K8sResourceCommon or K8sResourceCommon[]>(watchOptions: WatchK8sResource, advancedSearchFilters?: AdvancedSearchFilter or undefined, pollInterval?: number or ... 1 more ... or undefined) => [...] |
Parameters:
watchOptions
: - Configuration options for the resource watch
watchOptions.groupVersionKind
: - The group, version, and kind of the resource to search for
watchOptions.limit
: - Maximum number of results to return (defaults to -1 for no limit)
watchOptions.namespace
: - Namespace to search in (only used if namespaced is true)
watchOptions.namespaced
: - Whether the resource is namespaced
watchOptions.name
: - Specific resource name to search for (exact match)
watchOptions.isList
: - Whether to return results as a list or single item
advancedSearch
: - Optional array of additional search filters
advancedSearch[].property
: - The property name to filter on
advancedSearch[].values
: - Array of values to match for the property
pollInterval
: - Optional polling interval in seconds. Defaults to 30 seconds (polling enabled).
- Not specified: polls every 30 seconds
- 0-30 inclusive: polls every 30 seconds (minimum interval)
-
30: polls at the given interval in seconds
- false or negative: disables polling
Returns:
A tuple containing:
data
: The search results formatted as Kubernetes resources, or undefined if no results
loaded
: Boolean indicating if the search has completed (opposite of loading)
error
: Any error that occurred during the search, or undefined if successful
refetch
: A callback that enables you to re-execute the query
Examples:
const [pods, loaded, error] = useFleetSearchPoll({
groupVersionKind: { group: '', version: 'v1', kind: 'Pod' },
namespace: 'default',
namespaced: true,
isList: true
});
const [deployment, loaded, error] = useFleetSearchPoll({
groupVersionKind: { group: 'apps', version: 'v1', kind: 'Deployment' },
name: 'my-deployment',
namespace: 'default',
namespaced: true,
isList: false
}, [
{ property: 'label', values: ['app=my-app'] }
], 60);
const [services, loaded, error] = useFleetSearchPoll({
groupVersionKind: { group: '', version: 'v1', kind: 'Service' },
namespaced: true,
isList: true
}, undefined, false);
:link: Source
:gear: useHubClusterName
Hook that provides hub cluster name.
useHubClusterName | () => [hubClusterName: string or undefined, loaded: boolean, error: any] |
Returns:
Array with hubclustername
, loaded
and error
values.
:link: Source
:gear: useIsFleetAvailable
Hook that determines if the fleet support is available.
Checks if the feature flag with the name corresponding to the REQUIRED_PROVIDER_FLAG
constant is enabled.
Red Hat Advanced Cluster Management enables this feature flag in versions that provide all of the dependencies
required by this version of the multicluster SDK.
useIsFleetAvailable | () => boolean |
Returns:
true
if a version of Red Hat Advanced Cluster Management that is compatible with the multicluster SDK is available; false
otherwise
:link: Source
:gear: useIsFleetObservabilityInstalled
Hook that provides is observability installed.
useIsFleetObservabilityInstalled | () => [isObservabilityInstalled: boolean or undefined, loaded: boolean, error: unknown] |
Returns:
Array with isObservabilityInstalled
, loaded
and error
values.
:link: Source
:wrench: Constants
:gear: REQUIRED_PROVIDER_FLAG
REQUIRED_PROVIDER_FLAG | "MULTICLUSTER_SDK_PROVIDER_1" |
:link: Source
:gear: RESOURCE_ROUTE_TYPE
RESOURCE_ROUTE_TYPE | "acm.resource/route" |
:link: Source
:cocktail: Types
:gear: AdvancedSearchFilter
AdvancedSearchFilter | { property: string; values: string[] }[] |
:link: Source
:gear: Fleet
Fleet | T and { cluster?: string } |
:link: Source
:gear: FleetAccessReviewResourceAttributes
FleetAccessReviewResourceAttributes | Fleet<AccessReviewResourceAttributes> |
:link: Source
:gear: FleetK8sCreateUpdateOptions
FleetK8sCreateUpdateOptions | { model: K8sModel name?: string ns?: string path?: string cluster?: string queryParams?: QueryParams data: R } |
:link: Source
:gear: FleetK8sDeleteOptions
FleetK8sDeleteOptions | { model: K8sModel name?: string ns?: string path?: string cluster?: string queryParams?: QueryParams resource: R requestInit?: RequestInit json?: Record<string, any> } |
:link: Source
:gear: FleetK8sGetOptions
FleetK8sGetOptions | { model: K8sModel name?: string ns?: string path?: string cluster?: string queryParams?: QueryParams requestInit?: RequestInit } |
:link: Source
:gear: FleetK8sListOptions
FleetK8sListOptions | { model: K8sModel queryParams: { [key: string]: any } requestInit?: RequestInit } |
:link: Source
:gear: FleetK8sPatchOptions
FleetK8sPatchOptions | { model: K8sModel name?: string ns?: string path?: string cluster?: string queryParams?: QueryParams resource: R data: Patch[] } |
:link: Source
:gear: FleetK8sResourceCommon
FleetK8sResourceCommon | Fleet<K8sResourceCommon> |
:link: Source
:gear: FleetResourceEventStreamProps
FleetResourceEventStreamProps | { resource: FleetK8sResourceCommon } |
:link: Source
:gear: FleetResourceLinkProps
FleetResourceLinkProps | Fleet<ResourceLinkProps> |
:link: Source
:gear: FleetWatchK8sResource
FleetWatchK8sResource | Fleet<WatchK8sResource> |
:link: Source
:gear: ResourceRoute
This extension allows plugins to customize the route used for resources of the given kind. Search results and resource links will direct to the route returned by the implementing function.
ResourceRoute | ExtensionDeclaration<typeof RESOURCE_ROUTE_TYPE, ResourceRouteProps> |
:link: Source
:gear: ResourceRouteHandler
ResourceRouteHandler | (props: { /** The cluster where the resource is located. */ cluster: string /** The namespace where the resource is located (if the resource is namespace-scoped). */ namespace?: string /** The name of the resource. */ name: string /** The resource, augmented with cluster property. */ resource: FleetK8sResourceCommon /** The model for the resource. */ model: ExtensionK8sModel }) => string or undefined |
:link: Source
:gear: ResourceRouteProps
ResourceRouteProps | { /** The model for which this resource route should be used. */ model: ExtensionK8sGroupKindModel /** The handler function that returns the route path for the resource. */ handler: CodeRef<ResourceRouteHandler> } |
:link: Source
:gear: SearchResult
SearchResult | R extends (infer T)[] ? Fleet<T>[] : Fleet<R> |
:link: Source
:gear: UseFleetK8sWatchResource
UseFleetK8sWatchResource | <R extends FleetK8sResourceCommon or FleetK8sResourceCommon[]>( initResource: FleetWatchK8sResource or null ) => WatchK8sResult<R> or [undefined, boolean, any] |
:link: Source
Utilities
- Fleet resource typing support through TypeScript interfaces
Contributing
All contributions to the repository must be submitted under the terms of the Apache Public License 2.0. For contribution guidelines, see CONTRIBUTING.md.