UNPKG

@stolostron/multicluster-sdk

Version:

Provides extensions and APIs that dynamic plugins can use to leverage multicluster capabilities provided by Red Hat Advanced Cluster Management.

51 lines 3.32 kB
import { FleetResourcesObject, FleetWatchK8sResources, FleetWatchK8sResults } from '../types'; /** * A hook for watching multiple Kubernetes resources with support for multi-cluster environments. * It is equivalent to the [`useK8sWatchResources`](https://github.com/openshift/console/blob/main/frontend/packages/console-dynamic-plugin-sdk/docs/api.md#usek8swatchresources) * hook from the [OpenShift Console Dynamic Plugin SDK](https://www.npmjs.com/package/@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. * * @param initResources - An object where each key represents a resource identifier and each value is a resource watch configuration. Can be null to disable all watches. * @param initResources[key].cluster - The managed cluster on which the resource resides; null or undefined for the hub cluster * @param initResources[key].groupVersionKind - The group, version, and kind of the resource (e.g., `{ group: 'apps', version: 'v1', kind: 'Deployment' }`) * @param initResources[key].name - The name of the resource (for watching a specific resource) * @param initResources[key].namespace - The namespace of the resource * @param initResources[key].isList - Whether to watch a list of resources (true) or a single resource (false) * @param initResources[key].selector - Label selector to filter resources (e.g., `{ matchLabels: { app: 'myapp' } }`) * @param initResources[key].fieldSelector - Field selector to filter resources (e.g., `status.phase=Running`) * @param initResources[key].limit - Maximum number of resources to return (not supported yet) * @param initResources[key].namespaced - Whether the resource is namespaced (not supported yet) * @param initResources[key].optional - If true, errors will not be thrown when the resource is not found (not supported yet) * @param initResources[key].partialMetadata - If true, only fetch metadata for the resources (not supported yet) * @returns An object with the same keys as initResources, where each value contains the watched resource data, * a boolean indicating if the data is loaded, and any error that occurred. The hook returns live-updating data. * * @example * ```typescript * // Watch multiple resources on different clusters * const result = useFleetK8sWatchResources({ * pods: { * groupVersionKind: { version: 'v1', kind: 'Pod' }, * isList: true, * cluster: 'remote-cluster-1', * namespace: 'default' * }, * deployments: { * groupVersionKind: { group: 'apps', version: 'v1', kind: 'Deployment' }, * isList: true, * cluster: 'remote-cluster-2', * namespace: 'default' * } * }) * * // Access individual resources * const { pods, deployments } = result * console.log(pods.data, pods.loaded, pods.loadError) * console.log(deployments.data, deployments.loaded, deployments.loadError) * ``` */ export declare function useFleetK8sWatchResources<R extends FleetResourcesObject>(initResources: FleetWatchK8sResources<R> | null): FleetWatchK8sResults<R>; //# sourceMappingURL=useFleetK8sWatchResources.d.ts.map