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.

46 lines 2.62 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFleetK8sAPIPath = exports.useFleetK8sAPIPath = void 0; /* Copyright Contributors to the Open Cluster Management project */ const dynamic_plugin_sdk_1 = require("@openshift-console/dynamic-plugin-sdk"); const apiRequests_1 = require("./apiRequests"); const constants_1 = require("../internal/constants"); const models_1 = require("../internal/models"); const useHubClusterName_1 = require("./useHubClusterName"); const useFleetK8sAPIPath = (cluster) => { const [hubClusterName, loaded, error] = (0, useHubClusterName_1.useHubClusterName)(); if (!loaded) return [undefined, false, error]; if (!cluster || cluster === hubClusterName) return [constants_1.BASE_K8S_API_PATH, true, undefined]; return [`${(0, apiRequests_1.getBackendUrl)()}/${constants_1.MANAGED_CLUSTER_API_PATH}/${cluster}`, loaded, error]; }; exports.useFleetK8sAPIPath = useFleetK8sAPIPath; let cachedHubClusterName = undefined; const getFleetK8sAPIPath = (cluster) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; if (!cachedHubClusterName) { const hubClusters = yield (0, dynamic_plugin_sdk_1.k8sListItems)({ model: models_1.ManagedClusterModel, queryParams: { labelSelector: { matchLabels: { [constants_1.LOCAL_CLUSTER_LABEL]: true } } }, }); cachedHubClusterName = (_b = (_a = hubClusters === null || hubClusters === void 0 ? void 0 : hubClusters[0]) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.name; } if (cluster && cachedHubClusterName !== cluster) { return `${(0, apiRequests_1.getBackendUrl)()}/${constants_1.MANAGED_CLUSTER_API_PATH}/${cluster}`; } else { return constants_1.BASE_K8S_API_PATH; } }); exports.getFleetK8sAPIPath = getFleetK8sAPIPath; //# sourceMappingURL=useFleetK8sAPIPath.js.map