@stolostron/multicluster-sdk
Version:
Provides extensions and APIs that dynamic plugins can use to leverage multicluster capabilities provided by Red Hat Advanced Cluster Management.
47 lines • 3.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fleetK8sList = fleetK8sList;
exports.fleetK8sListItems = fleetK8sListItems;
const dynamic_plugin_sdk_1 = require("@openshift-console/dynamic-plugin-sdk");
const apiRequests_1 = require("../internal/apiRequests");
const isHubRequest_1 = require("../internal/isHubRequest");
/**
* A fleet version of [`k8sList`](https://github.com/openshift/console/blob/main/frontend/packages/console-dynamic-plugin-sdk/docs/api.md#k8slist) from
* the [dynamic plugin SDK](https://www.npmjs.com/package/@openshift-console/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.
* @param options Which are passed as key-value pairs in the map.
* @param options.cluster - the cluster from which to list the resources
* @param options.model - Kubernetes model
* @param options.queryParams - The query parameters to be included in the URL. It can also pass label selectors by using the `labelSelector` key.
* @param options.requestInit - The fetch init object to use. This can have request headers, method, redirect, and so forth. 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
*/
async function fleetK8sList(options) {
const cluster = (0, apiRequests_1.getClusterFromOptions)(options);
const optionsWithoutCluster = (0, apiRequests_1.getOptionsWithoutCluster)(options);
const items = (await (0, isHubRequest_1.isHubRequest)(cluster))
? (0, dynamic_plugin_sdk_1.k8sList)(optionsWithoutCluster)
: (0, dynamic_plugin_sdk_1.consoleFetchJSON)(await (0, apiRequests_1.getResourceURLFromOptions)(options), 'GET', options.requestInit).then((result) => result.items?.map((i) => ({
kind: options.model.kind,
apiVersion: result.apiVersion,
...i,
})));
return (await items)?.map((i) => ({ ...i, cluster }));
}
/**
* A fleet version of [`k8sListItems`](https://github.com/openshift/console/blob/main/frontend/packages/console-dynamic-plugin-sdk/docs/api.md#k8slistitems) from
* the [dynamic plugin SDK](https://www.npmjs.com/package/@openshift-console/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.
* @param options Which are passed as key-value pairs in the map.
* @param options.cluster - the cluster from which to list the resources
* @param options.model - Kubernetes model
* @param options.queryParams - The query parameters to be included in the URL. It can also pass label selectors by using the `labelSelector` key.
* @param options.requestInit - The fetch init object to use. This can have request headers, method, redirect, and so forth. 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
*/
async function fleetK8sListItems(options) {
return fleetK8sList(options);
}
//# sourceMappingURL=fleetK8sList.js.map