@stolostron/multicluster-sdk 0.10.3 → 0.10.4-preview2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/fleetK8sCreate.js +18 -7
- package/lib/api/fleetK8sCreate.js.map +1 -1
- package/lib/api/fleetK8sDelete.js +21 -9
- package/lib/api/fleetK8sDelete.js.map +1 -1
- package/lib/api/fleetK8sGet.js +18 -7
- package/lib/api/fleetK8sGet.js.map +1 -1
- package/lib/api/fleetK8sList.js +26 -13
- package/lib/api/fleetK8sList.js.map +1 -1
- package/lib/api/fleetK8sPatch.js +21 -10
- package/lib/api/fleetK8sPatch.js.map +1 -1
- package/lib/api/fleetK8sUpdate.js +18 -7
- package/lib/api/fleetK8sUpdate.js.map +1 -1
- package/lib/api/getFleetK8sAPIPath.js +12 -3
- package/lib/api/getFleetK8sAPIPath.js.map +1 -1
- package/lib/api/useFleetAccessReview.js +2 -1
- package/lib/api/useFleetAccessReview.js.map +1 -1
- package/lib/api/useFleetK8sWatchResource.d.ts +2 -1
- package/lib/api/useFleetK8sWatchResource.d.ts.map +1 -1
- package/lib/api/useFleetK8sWatchResource.js +15 -3
- package/lib/api/useFleetK8sWatchResource.js.map +1 -1
- package/lib/api/useFleetK8sWatchResources.d.ts +2 -1
- package/lib/api/useFleetK8sWatchResources.d.ts.map +1 -1
- package/lib/api/useFleetK8sWatchResources.js +9 -7
- package/lib/api/useFleetK8sWatchResources.js.map +1 -1
- package/lib/api/useFleetSearchPoll.js +7 -6
- package/lib/api/useFleetSearchPoll.js.map +1 -1
- package/lib/components/FleetResourceEventStream.d.ts +11 -11
- package/lib/components/FleetResourceEventStream.d.ts.map +1 -1
- package/lib/components/FleetResourceEventStream.js +59 -86
- package/lib/components/FleetResourceEventStream.js.map +1 -1
- package/lib/components/FleetResourceLink.js +23 -10
- package/lib/components/FleetResourceLink.js.map +1 -1
- package/lib/internal/FleetResourceEventStream/EventComponent.js +1 -1
- package/lib/internal/FleetResourceEventStream/EventComponent.js.map +1 -1
- package/lib/internal/FleetResourceEventStream/EventStreamList.js +9 -4
- package/lib/internal/FleetResourceEventStream/EventStreamList.js.map +1 -1
- package/lib/internal/FleetResourceEventStream/utils.js +2 -1
- package/lib/internal/FleetResourceEventStream/utils.js.map +1 -1
- package/lib/internal/apiRequests.d.ts +1 -9
- package/lib/internal/apiRequests.d.ts.map +1 -1
- package/lib/internal/apiRequests.js +43 -56
- package/lib/internal/apiRequests.js.map +1 -1
- package/lib/internal/cachedHubConfiguration.js +11 -2
- package/lib/internal/cachedHubConfiguration.js.map +1 -1
- package/lib/internal/clusterUtils.js +8 -5
- package/lib/internal/clusterUtils.js.map +1 -1
- package/lib/internal/components/FleetK8sWatchResourceStoreViewer.d.ts +2 -0
- package/lib/internal/components/FleetK8sWatchResourceStoreViewer.d.ts.map +1 -0
- package/lib/internal/components/FleetK8sWatchResourceStoreViewer.js +28 -0
- package/lib/internal/components/FleetK8sWatchResourceStoreViewer.js.map +1 -0
- package/lib/internal/fleetK8sWatchResource.d.ts +1 -2
- package/lib/internal/fleetK8sWatchResource.d.ts.map +1 -1
- package/lib/internal/fleetK8sWatchResource.js +52 -144
- package/lib/internal/fleetK8sWatchResource.js.map +1 -1
- package/lib/internal/fleetK8sWatchResourceStore.d.ts +6 -3
- package/lib/internal/fleetK8sWatchResourceStore.d.ts.map +1 -1
- package/lib/internal/fleetK8sWatchResourceStore.js +51 -58
- package/lib/internal/fleetK8sWatchResourceStore.js.map +1 -1
- package/lib/internal/isHubRequest.js +14 -2
- package/lib/internal/isHubRequest.js.map +1 -1
- package/lib/internal/requirements.js +5 -4
- package/lib/internal/requirements.js.map +1 -1
- package/lib/internal/resourceRouteUtils.js +3 -3
- package/lib/internal/resourceRouteUtils.js.map +1 -1
- package/lib/internal/search/convertSearchItemToResource.js +18 -19
- package/lib/internal/search/convertSearchItemToResource.js.map +1 -1
- package/lib/internal/search/search-client.js +1 -4
- package/lib/internal/search/search-client.js.map +1 -1
- package/lib/internal/search/search-sdk.js +24 -24
- package/lib/internal/search/search-sdk.js.map +1 -1
- package/lib/internal/search/searchUtils.js +1 -1
- package/lib/internal/search/searchUtils.js.map +1 -1
- package/lib/internal/useFleetClustersInternal.js +4 -8
- package/lib/internal/useFleetClustersInternal.js.map +1 -1
- package/lib/internal/useHubConfigurationItem.js +2 -1
- package/lib/internal/useHubConfigurationItem.js.map +1 -1
- package/lib/internal/useSafeFetch.js +9 -6
- package/lib/internal/useSafeFetch.js.map +1 -1
- package/lib/internal/utils.js +13 -1
- package/lib/internal/utils.js.map +1 -1
- package/lib/setupTests.js +26 -23
- package/lib/setupTests.js.map +1 -1
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/types/fleet.d.ts +4 -1
- package/lib/types/fleet.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
2
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
23
|
+
exports.buildResourceURL = exports.getResourcePath = void 0;
|
|
4
24
|
exports.getClusterFromOptions = getClusterFromOptions;
|
|
5
25
|
exports.getNamespaceFromOptions = getNamespaceFromOptions;
|
|
6
26
|
exports.getNameFromOptions = getNameFromOptions;
|
|
@@ -8,7 +28,6 @@ exports.getOptionsWithoutCluster = getOptionsWithoutCluster;
|
|
|
8
28
|
exports.getResourceURLFromOptions = getResourceURLFromOptions;
|
|
9
29
|
const constants_1 = require("../internal/constants");
|
|
10
30
|
const getFleetK8sAPIPath_1 = require("../api/getFleetK8sAPIPath");
|
|
11
|
-
const requirements_1 = require("./requirements");
|
|
12
31
|
const isFleetK8sAPIOptionsWithData = (options) => {
|
|
13
32
|
const data = options.data;
|
|
14
33
|
return typeof data === 'object' && !Array.isArray(data);
|
|
@@ -55,72 +74,40 @@ const buildResourceURL = (params) => {
|
|
|
55
74
|
};
|
|
56
75
|
exports.buildResourceURL = buildResourceURL;
|
|
57
76
|
function getClusterFromOptions(options) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
77
|
+
var _a;
|
|
78
|
+
return ((_a = options.cluster) !== null && _a !== void 0 ? _a : ((isFleetK8sAPIOptionsWithData(options) && options.data.cluster) ||
|
|
79
|
+
(isFleetK8sAPIOptionsWithResource(options) && options.resource.cluster) ||
|
|
80
|
+
undefined));
|
|
62
81
|
}
|
|
63
82
|
function getNamespaceFromOptions(options) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
var _a, _b, _c, _d;
|
|
84
|
+
return ((_a = options.ns) !== null && _a !== void 0 ? _a : ((isFleetK8sAPIOptionsWithData(options) && ((_b = options.data.metadata) === null || _b === void 0 ? void 0 : _b.namespace)) ||
|
|
85
|
+
(isFleetK8sAPIOptionsWithResource(options) && ((_c = options.resource.metadata) === null || _c === void 0 ? void 0 : _c.namespace)) ||
|
|
86
|
+
((_d = options.queryParams) === null || _d === void 0 ? void 0 : _d.ns) ||
|
|
87
|
+
undefined));
|
|
69
88
|
}
|
|
70
89
|
function getNameFromOptions(options) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
var _a, _b, _c;
|
|
91
|
+
return ((_a = options.name) !== null && _a !== void 0 ? _a : ((isFleetK8sAPIOptionsWithData(options) && ((_b = options.data.metadata) === null || _b === void 0 ? void 0 : _b.name)) ||
|
|
92
|
+
(isFleetK8sAPIOptionsWithResource(options) && ((_c = options.resource.metadata) === null || _c === void 0 ? void 0 : _c.name)) ||
|
|
93
|
+
undefined));
|
|
75
94
|
}
|
|
76
95
|
function getOptionsWithoutCluster(options) {
|
|
77
|
-
const { cluster: _optionsCluster,
|
|
96
|
+
const { cluster: _optionsCluster } = options, optionsWithoutCluster = __rest(options, ["cluster"]);
|
|
78
97
|
if (isFleetK8sAPIOptionsWithData(options)) {
|
|
79
|
-
const { cluster: _dataCluster,
|
|
80
|
-
return {
|
|
98
|
+
const _a = options.data, { cluster: _dataCluster } = _a, dataWithoutCluster = __rest(_a, ["cluster"]);
|
|
99
|
+
return Object.assign(Object.assign({}, optionsWithoutCluster), { data: dataWithoutCluster });
|
|
81
100
|
}
|
|
82
101
|
else if (isFleetK8sAPIOptionsWithResource(options)) {
|
|
83
|
-
const { cluster: _resourceCluster,
|
|
84
|
-
return {
|
|
102
|
+
const _b = options.resource, { cluster: _resourceCluster } = _b, resourceWithoutCluster = __rest(_b, ["cluster"]);
|
|
103
|
+
return Object.assign(Object.assign({}, optionsWithoutCluster), { resource: resourceWithoutCluster });
|
|
85
104
|
}
|
|
86
105
|
return optionsWithoutCluster;
|
|
87
106
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
basePath,
|
|
92
|
-
...options,
|
|
93
|
-
cluster: getClusterFromOptions(options),
|
|
94
|
-
ns: getNamespaceFromOptions(options),
|
|
95
|
-
name: collection ? undefined : getNameFromOptions(options),
|
|
107
|
+
function getResourceURLFromOptions(options_1) {
|
|
108
|
+
return __awaiter(this, arguments, void 0, function* (options, collection = false) {
|
|
109
|
+
const basePath = yield (0, getFleetK8sAPIPath_1.getFleetK8sAPIPath)(getClusterFromOptions(options));
|
|
110
|
+
return (0, exports.buildResourceURL)(Object.assign(Object.assign({ basePath }, options), { cluster: getClusterFromOptions(options), ns: getNamespaceFromOptions(options), name: collection ? undefined : getNameFromOptions(options) }));
|
|
96
111
|
});
|
|
97
112
|
}
|
|
98
|
-
const fleetWatch = (model, query = {}, backendURL) => {
|
|
99
|
-
const queryParams = { watch: 'true' };
|
|
100
|
-
const { labelSelector } = query;
|
|
101
|
-
if (labelSelector) {
|
|
102
|
-
const encodedSelector = (0, requirements_1.selectorToString)(labelSelector);
|
|
103
|
-
if (encodedSelector) {
|
|
104
|
-
queryParams.labelSelector = encodedSelector;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (query.fieldSelector) {
|
|
108
|
-
queryParams.fieldSelector = query.fieldSelector;
|
|
109
|
-
}
|
|
110
|
-
if (query.resourceVersion) {
|
|
111
|
-
queryParams.resourceVersion = query.resourceVersion;
|
|
112
|
-
}
|
|
113
|
-
if (query.allowWatchBookmarks) {
|
|
114
|
-
queryParams.allowWatchBookmarks = 'true';
|
|
115
|
-
}
|
|
116
|
-
const requestPath = (0, exports.buildResourceURL)({
|
|
117
|
-
model,
|
|
118
|
-
cluster: query.cluster,
|
|
119
|
-
queryParams,
|
|
120
|
-
ns: query.ns,
|
|
121
|
-
basePath: backendURL,
|
|
122
|
-
});
|
|
123
|
-
return new WebSocket(requestPath);
|
|
124
|
-
};
|
|
125
|
-
exports.fleetWatch = fleetWatch;
|
|
126
113
|
//# sourceMappingURL=apiRequests.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiRequests.js","sourceRoot":"","sources":["../../src/internal/apiRequests.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apiRequests.js","sourceRoot":"","sources":["../../src/internal/apiRequests.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwFA,sDAOC;AAED,0DAQC;AAED,gDAOC;AAED,4DAUC;AAED,8DAYC;AAxID,qDAAyD;AACzD,kEAA8D;AAe9D,MAAM,4BAA4B,GAAG,CACnC,OAA2B,EACoC,EAAE;IACjE,MAAM,IAAI,GAAI,OAA8D,CAAC,IAAI,CAAA;IACjF,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AACzD,CAAC,CAAA;AAED,MAAM,gCAAgC,GAAG,CACvC,OAA2B,EACwC,EAAE;IACrE,MAAM,QAAQ,GAAI,OAAkE,CAAC,QAAQ,CAAA;IAC7F,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AACjE,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,EAAE,QAAQ,GAAG,MAAM,EAAE,UAAU,EAAY,EAAU,EAAE;IAC5E,MAAM,QAAQ,GAAG,QAAQ,KAAK,MAAM,IAAI,UAAU,KAAK,IAAI,CAAA;IAC3D,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAA;IAErC,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,CAAC;QAC1B,CAAC,IAAI,GAAG,QAAQ,GAAG,CAAA;IACrB,CAAC;IAED,CAAC,IAAI,UAAU,CAAA;IACf,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,CAAC,WAAwB,EA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__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.getCachedHubConfiguration = exports.fetchHubConfiguration = void 0;
|
|
4
13
|
/* Copyright Contributors to the Open Cluster Management project */
|
|
@@ -7,7 +16,7 @@ const constants_1 = require("./constants");
|
|
|
7
16
|
const FLEET_CONFIGURATION_URL = '/hub';
|
|
8
17
|
let cachedHubConfiguration = undefined;
|
|
9
18
|
let fetchPromise = undefined;
|
|
10
|
-
const fetchHubConfiguration =
|
|
19
|
+
const fetchHubConfiguration = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
20
|
if (cachedHubConfiguration) {
|
|
12
21
|
return cachedHubConfiguration;
|
|
13
22
|
}
|
|
@@ -19,7 +28,7 @@ const fetchHubConfiguration = async () => {
|
|
|
19
28
|
return hc;
|
|
20
29
|
});
|
|
21
30
|
return fetchPromise;
|
|
22
|
-
};
|
|
31
|
+
});
|
|
23
32
|
exports.fetchHubConfiguration = fetchHubConfiguration;
|
|
24
33
|
const getCachedHubConfiguration = () => {
|
|
25
34
|
return cachedHubConfiguration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cachedHubConfiguration.js","sourceRoot":"","sources":["../../src/internal/cachedHubConfiguration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cachedHubConfiguration.js","sourceRoot":"","sources":["../../src/internal/cachedHubConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mEAAmE;AACnE,8EAAwE;AACxE,2CAAyC;AAEzC,MAAM,uBAAuB,GAAG,MAAM,CAAA;AAStC,IAAI,sBAAsB,GAAiC,SAAS,CAAA;AACpE,IAAI,YAAY,GAAsD,SAAS,CAAA;AAExE,MAAM,qBAAqB,GAAG,GAAgD,EAAE;IACrF,IAAI,sBAAsB,EAAE,CAAC;QAC3B,OAAO,sBAAsB,CAAA;IAC/B,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,YAAY,GAAI,IAAA,qCAAgB,EAAC,uBAAW,GAAG,uBAAuB,EAAE,KAAK,CAA+B,CAAC,IAAI,CAC/G,CAAC,EAAE,EAAE,EAAE;QACL,sBAAsB,GAAG,EAAE,CAAA;QAC3B,OAAO,EAAE,CAAA;IACX,CAAC,CACF,CAAA;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAhBY,QAAA,qBAAqB,yBAgBjC;AAEM,MAAM,yBAAyB,GAAG,GAAiC,EAAE;IAC1E,OAAO,sBAAsB,CAAA;AAC/B,CAAC,CAAA;AAFY,QAAA,yBAAyB,6BAErC"}
|
|
@@ -4,7 +4,7 @@ exports.filterClusters = exports.getClusterSetName = exports.isClusterAvailable
|
|
|
4
4
|
/**
|
|
5
5
|
* Helper function to check for condition - similar to checkForCondition from status-conditions.ts
|
|
6
6
|
*/
|
|
7
|
-
const checkForCondition = (condition, conditions, status) => conditions
|
|
7
|
+
const checkForCondition = (condition, conditions, status) => { var _a; return ((_a = conditions === null || conditions === void 0 ? void 0 : conditions.find((c) => c.type === condition)) === null || _a === void 0 ? void 0 : _a.status) === (status !== null && status !== void 0 ? status : 'True'); };
|
|
8
8
|
exports.checkForCondition = checkForCondition;
|
|
9
9
|
/**
|
|
10
10
|
* Checks if a managed cluster meets the default filtering criteria:
|
|
@@ -12,8 +12,9 @@ exports.checkForCondition = checkForCondition;
|
|
|
12
12
|
* - Has ManagedClusterConditionAvailable status: 'True'
|
|
13
13
|
*/
|
|
14
14
|
const isClusterAvailable = (cluster) => {
|
|
15
|
-
|
|
16
|
-
const
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
const hasClusterProxyLabel = ((_b = (_a = cluster.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b['feature.open-cluster-management.io/addon-cluster-proxy']) === 'available';
|
|
17
|
+
const conditions = ((_c = cluster === null || cluster === void 0 ? void 0 : cluster.status) === null || _c === void 0 ? void 0 : _c.conditions) || [];
|
|
17
18
|
const isAvailable = (0, exports.checkForCondition)('ManagedClusterConditionAvailable', conditions);
|
|
18
19
|
return hasClusterProxyLabel && isAvailable;
|
|
19
20
|
};
|
|
@@ -23,7 +24,8 @@ exports.isClusterAvailable = isClusterAvailable;
|
|
|
23
24
|
* Returns the cluster set label value or 'default' if not present.
|
|
24
25
|
*/
|
|
25
26
|
const getClusterSetName = (cluster) => {
|
|
26
|
-
|
|
27
|
+
var _a, _b;
|
|
28
|
+
return ((_b = (_a = cluster.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b['cluster.open-cluster-management.io/clusterset']) || 'default';
|
|
27
29
|
};
|
|
28
30
|
exports.getClusterSetName = getClusterSetName;
|
|
29
31
|
/**
|
|
@@ -33,7 +35,8 @@ exports.getClusterSetName = getClusterSetName;
|
|
|
33
35
|
*/
|
|
34
36
|
const filterClusters = (clusters, includeAll) => {
|
|
35
37
|
return clusters.filter((cluster) => {
|
|
36
|
-
|
|
38
|
+
var _a;
|
|
39
|
+
if (!((_a = cluster.metadata) === null || _a === void 0 ? void 0 : _a.name)) {
|
|
37
40
|
return false;
|
|
38
41
|
}
|
|
39
42
|
return includeAll || (0, exports.isClusterAvailable)(cluster);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clusterUtils.js","sourceRoot":"","sources":["../../src/internal/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AAED;;;;GAIG;AACI,MAAM,cAAc,GAAG,CAAC,QAA6B,EAAE,UAAmB,EAAuB,EAAE;IACxG,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;;QACjC,IAAI,CAAC,CAAA,MAAA,OAAO,CAAC,QAAQ,0CAAE,IAAI,CAAA,EAAE,CAAC;YAC5B,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,UAAU,IAAI,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAA;IAClD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AARY,QAAA,cAAc,kBAQ1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FleetK8sWatchResourceStoreViewer.d.ts","sourceRoot":"","sources":["../../../src/internal/components/FleetK8sWatchResourceStoreViewer.tsx"],"names":[],"mappings":"AAeA,eAAO,MAAM,gCAAgC,+CAiC5C,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FleetK8sWatchResourceStoreViewer = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
/* Copyright Contributors to the Open Cluster Management project */
|
|
7
|
+
const react_core_1 = require("@patternfly/react-core");
|
|
8
|
+
const fleetK8sWatchResourceStore_1 = require("../fleetK8sWatchResourceStore");
|
|
9
|
+
const TimestampAge = ({ timestamp }) => {
|
|
10
|
+
const [now, updateNow] = (0, react_1.useState)(Date.now());
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
const interval = setInterval(() => updateNow(Date.now), 100);
|
|
13
|
+
return () => clearInterval(interval);
|
|
14
|
+
}, []);
|
|
15
|
+
return timestamp ? Math.round((now - timestamp) / 1000) : 0;
|
|
16
|
+
};
|
|
17
|
+
const FleetK8sWatchResourceStoreViewer = () => {
|
|
18
|
+
const cache = (0, fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore)((state) => state.cache);
|
|
19
|
+
const keys = Object.keys(cache).sort();
|
|
20
|
+
return ((0, jsx_runtime_1.jsxs)("table", { style: { tableLayout: 'fixed', width: '100%' }, children: [(0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { style: { width: '50%' }, children: "Key" }), (0, jsx_runtime_1.jsx)("th", { children: "Age" }), (0, jsx_runtime_1.jsx)("th", { children: "Poll status" }), (0, jsx_runtime_1.jsx)("th", { children: "Last poll" }), (0, jsx_runtime_1.jsx)("th", { children: "Reference count" }), (0, jsx_runtime_1.jsx)("th", { children: "Resource version" }), (0, jsx_runtime_1.jsx)("th", { children: "Timeout" })] }), Array.from(keys)
|
|
21
|
+
.sort()
|
|
22
|
+
.map((key) => {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
24
|
+
return ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsx)(react_core_1.Truncate, { position: "start", content: key }) }), (0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsx)(TimestampAge, { timestamp: (_a = cache[key]) === null || _a === void 0 ? void 0 : _a.timestamp }) }), (0, jsx_runtime_1.jsx)("td", { children: (_c = (_b = cache[key]) === null || _b === void 0 ? void 0 : _b.pollStatus) !== null && _c !== void 0 ? _c : 'Idle' }), (0, jsx_runtime_1.jsx)("td", { children: ((_d = cache[key]) === null || _d === void 0 ? void 0 : _d.lastPollAt) ? (0, jsx_runtime_1.jsx)(TimestampAge, { timestamp: cache[key].lastPollAt }) : '—' }), (0, jsx_runtime_1.jsx)("td", { children: (_e = cache[key]) === null || _e === void 0 ? void 0 : _e.refCount }), (0, jsx_runtime_1.jsx)("td", { children: (_f = cache[key]) === null || _f === void 0 ? void 0 : _f.resourceVersion }), (0, jsx_runtime_1.jsx)("td", { children: (_j = (_h = (_g = cache[key]) === null || _g === void 0 ? void 0 : _g.timeout) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : 'N/A' })] }, key));
|
|
25
|
+
})] }));
|
|
26
|
+
};
|
|
27
|
+
exports.FleetK8sWatchResourceStoreViewer = FleetK8sWatchResourceStoreViewer;
|
|
28
|
+
//# sourceMappingURL=FleetK8sWatchResourceStoreViewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FleetK8sWatchResourceStoreViewer.js","sourceRoot":"","sources":["../../../src/internal/components/FleetK8sWatchResourceStoreViewer.tsx"],"names":[],"mappings":";;;;AAAA,iCAA+C;AAE/C,mEAAmE;AACnE,uDAAiD;AACjD,8EAA6E;AAE7E,MAAM,YAAY,GAA8B,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;IAChE,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAC7C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;QAC5D,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtC,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7D,CAAC,CAAA;AAEM,MAAM,gCAAgC,GAAG,GAAG,EAAE;IACnD,MAAM,KAAK,GAAG,IAAA,0DAA6B,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACnE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,I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/dynamic-plugin-sdk';
|
|
|
3
3
|
export declare const getRequestPathFromResource: (resource: FleetWatchK8sResource, model: K8sModel, basePath: string) => string;
|
|
4
4
|
export declare function useGetInitialResult(): <R extends FleetK8sResourceCommon | FleetK8sResourceCommon[]>(resource?: FleetWatchK8sResource | null, model?: K8sModel, basePath?: string) => FleetWatchK8sResultsObject<R>;
|
|
5
5
|
export declare const subscribe: <R extends FleetK8sResourceCommon | FleetK8sResourceCommon[]>(resource: FleetWatchK8sResource, requestPath: string, setResult: (result: FleetWatchK8sResultsObject<R>) => void) => () => void;
|
|
6
|
-
export declare const startWatch: (resource: FleetWatchK8sResource, model: K8sModel, basePath: string) => Promise<void>;
|
|
6
|
+
export declare const startWatch: (resource: FleetWatchK8sResource, model: K8sModel, basePath: string, pollInterval?: number) => Promise<void>;
|
|
7
7
|
export declare const stopWatch: (resource: FleetWatchK8sResource, model: K8sModel, basePath: string) => void;
|
|
8
|
-
export declare const handleWebsocketEvent: <R extends FleetK8sResourceCommon | FleetK8sResourceCommon[]>(event: any, requestPath: string, isList: boolean | undefined, cluster: string) => void;
|
|
9
8
|
//# sourceMappingURL=fleetK8sWatchResource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fleetK8sWatchResource.d.ts","sourceRoot":"","sources":["../../src/internal/fleetK8sWatchResource.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"fleetK8sWatchResource.d.ts","sourceRoot":"","sources":["../../src/internal/fleetK8sWatchResource.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAIpG,OAAO,EAAoB,KAAK,QAAQ,EAA0B,MAAM,uCAAuC,CAAA;AAU/G,eAAO,MAAM,0BAA0B,GAAI,UAAU,qBAAqB,EAAE,OAAO,QAAQ,EAAE,UAAU,MAAM,WAa5G,CAAA;AAwDD,wBAAgB,mBAAmB,KAI9B,CAAC,SAAS,sBAAsB,GAAG,sBAAsB,EAAE,aAC/C,qBAAqB,GAAG,IAAI,UAC/B,QAAQ,aACL,MAAM,mCAsBtB;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,sBAAsB,GAAG,sBAAsB,EAAE,EACnF,UAAU,qBAAqB,EAC/B,aAAa,MAAM,EACnB,WAAW,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC,KAAK,IAAI,eAY3D,CAAA;AAED,eAAO,MAAM,UAAU,GACrB,UAAU,qBAAqB,EAC/B,OAAO,QAAQ,EACf,UAAU,MAAM,EAChB,eAAe,MAAM,kBAetB,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,UAAU,qBAAqB,EAAE,OAAO,QAAQ,EAAE,UAAU,MAAM,SAI3F,CAAA"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Copyright Contributors to the Open Cluster Management project */
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
3
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
13
|
+
exports.stopWatch = exports.startWatch = exports.subscribe = exports.getRequestPathFromResource = void 0;
|
|
5
14
|
exports.useGetInitialResult = useGetInitialResult;
|
|
6
15
|
const fleetK8sWatchResourceStore_1 = require("./fleetK8sWatchResourceStore");
|
|
7
16
|
// Type imports
|
|
@@ -11,6 +20,8 @@ const apiRequests_1 = require("./apiRequests");
|
|
|
11
20
|
const constants_1 = require("./constants");
|
|
12
21
|
const api_1 = require("../api");
|
|
13
22
|
const react_1 = require("react");
|
|
23
|
+
const MIN_POLL_INTERVAL_SECONDS = 10;
|
|
24
|
+
const DEFAULT_POLL_INTERVAL_SECONDS = 10;
|
|
14
25
|
const getRequestPathFromResource = (resource, model, basePath) => {
|
|
15
26
|
const { cluster, name, namespace, fieldSelector, selector } = resource;
|
|
16
27
|
return (0, apiRequests_1.buildResourceURL)({
|
|
@@ -18,74 +29,29 @@ const getRequestPathFromResource = (resource, model, basePath) => {
|
|
|
18
29
|
ns: namespace,
|
|
19
30
|
name,
|
|
20
31
|
cluster,
|
|
21
|
-
queryParams: {
|
|
22
|
-
...(fieldSelector ? { fieldSelector: fieldSelector } : {}),
|
|
23
|
-
labelSelector: (0, requirements_1.selectorToString)(selector || {}),
|
|
24
|
-
},
|
|
32
|
+
queryParams: Object.assign(Object.assign({}, (fieldSelector ? { fieldSelector: fieldSelector } : {})), { labelSelector: (0, requirements_1.selectorToString)(selector || {}) }),
|
|
25
33
|
basePath,
|
|
26
34
|
});
|
|
27
35
|
};
|
|
28
36
|
exports.getRequestPathFromResource = getRequestPathFromResource;
|
|
29
37
|
const getDefaultData = (resource) => {
|
|
30
|
-
const { isList } = resource
|
|
38
|
+
const { isList } = resource !== null && resource !== void 0 ? resource : {};
|
|
31
39
|
return isList ? [] : undefined;
|
|
32
40
|
};
|
|
33
41
|
const handleError = (err, requestPath, resource) => {
|
|
34
42
|
const store = fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.getState();
|
|
35
43
|
store.setResult(requestPath, getDefaultData(resource), true, err);
|
|
36
44
|
};
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const store = fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.getState();
|
|
40
|
-
const cachedResult = store.getResult(requestPath);
|
|
41
|
-
const resourceVersion = store.getResourceVersion(requestPath);
|
|
42
|
-
try {
|
|
43
|
-
const socket = (0, apiRequests_1.fleetWatch)(model, {
|
|
44
|
-
ns: namespace,
|
|
45
|
-
cluster,
|
|
46
|
-
fieldSelector: name ? `metadata.name=${name}` : undefined,
|
|
47
|
-
labelSelector: selector || undefined,
|
|
48
|
-
resourceVersion: isList ? resourceVersion : undefined,
|
|
49
|
-
allowWatchBookmarks: isList,
|
|
50
|
-
}, basePath);
|
|
51
|
-
store.setSocket(requestPath, socket);
|
|
52
|
-
socket.onmessage = (event) => {
|
|
53
|
-
try {
|
|
54
|
-
// Handle WebSocket event - this will update the store and notify all subscribers
|
|
55
|
-
(0, exports.handleWebsocketEvent)(event, requestPath, isList, cluster);
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
console.error('Failed to parse WebSocket message', e);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
socket.onclose = (event) => {
|
|
62
|
-
if (event.wasClean) {
|
|
63
|
-
// assume data is fresh up to this point
|
|
64
|
-
store.touchEntry(requestPath);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
console.error('WebSocket did not close cleanly:', event);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
socket.onerror = (err) => {
|
|
71
|
-
console.error('WebSocket error:', err);
|
|
72
|
-
store.setResult(requestPath, cachedResult?.data, true, err);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
handleError(err, requestPath, resource);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const loadInitialData = async (requestPath, resource) => {
|
|
45
|
+
const loadInitialData = (requestPath, resource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
var _a;
|
|
80
47
|
const { cluster, isList } = resource;
|
|
81
48
|
const store = fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.getState();
|
|
82
49
|
try {
|
|
83
|
-
|
|
84
|
-
const data = await (0, dynamic_plugin_sdk_1.consoleFetchJSON)(requestPath, 'GET');
|
|
50
|
+
const data = yield (0, dynamic_plugin_sdk_1.consoleFetchJSON)(requestPath, 'GET');
|
|
85
51
|
const processedData = isList
|
|
86
|
-
? data.items.map((i) => ({ cluster,
|
|
87
|
-
: { cluster,
|
|
88
|
-
const resourceVersion = isList ? data
|
|
52
|
+
? data.items.map((i) => (Object.assign({ cluster }, i)))
|
|
53
|
+
: Object.assign({ cluster }, data);
|
|
54
|
+
const resourceVersion = isList ? (_a = data === null || data === void 0 ? void 0 : data.metadata) === null || _a === void 0 ? void 0 : _a.resourceVersion : undefined;
|
|
89
55
|
store.setResult(requestPath, processedData, true, undefined, resourceVersion);
|
|
90
56
|
}
|
|
91
57
|
catch (err) {
|
|
@@ -93,29 +59,30 @@ const loadInitialData = async (requestPath, resource) => {
|
|
|
93
59
|
return false;
|
|
94
60
|
}
|
|
95
61
|
return true;
|
|
96
|
-
};
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
else {
|
|
107
|
-
// Socket may have disconnected; reconnect
|
|
108
|
-
entry.socket?.close();
|
|
109
|
-
if (await loadInitialData(requestPath, resource)) {
|
|
110
|
-
// only start watch if initial load succeeds
|
|
111
|
-
openFleetWatchSocket(requestPath, resource, model, basePath);
|
|
112
|
-
}
|
|
113
|
-
// check again after default interval
|
|
114
|
-
setTimeout(() => checkFleetWatchSocket(requestPath, resource, model, basePath), (0, fleetK8sWatchResourceStore_1.getSocketMonitoringInterval)());
|
|
115
|
-
}
|
|
116
|
-
}
|
|
62
|
+
});
|
|
63
|
+
const pollData = (requestPath, resource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const store = fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.getState();
|
|
65
|
+
const entry = store.cache[requestPath];
|
|
66
|
+
if (!entry || entry.refCount <= 0)
|
|
67
|
+
return;
|
|
68
|
+
store.setPollStatus(requestPath, 'Polling');
|
|
69
|
+
try {
|
|
70
|
+
yield loadInitialData(requestPath, resource);
|
|
71
|
+
store.setPollStatus(requestPath, 'Idle');
|
|
117
72
|
}
|
|
118
|
-
|
|
73
|
+
catch (_a) {
|
|
74
|
+
store.setPollStatus(requestPath, 'Error');
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const startPolling = (requestPath, resource, pollInterval) => {
|
|
78
|
+
const store = fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.getState();
|
|
79
|
+
const existingEntry = store.cache[requestPath];
|
|
80
|
+
if (existingEntry === null || existingEntry === void 0 ? void 0 : existingEntry.pollTimer) {
|
|
81
|
+
clearInterval(existingEntry.pollTimer);
|
|
82
|
+
}
|
|
83
|
+
const timer = setInterval(() => pollData(requestPath, resource), pollInterval);
|
|
84
|
+
store.setPollTimer(requestPath, timer);
|
|
85
|
+
store.setPollStatus(requestPath, 'Idle');
|
|
119
86
|
};
|
|
120
87
|
function useGetInitialResult() {
|
|
121
88
|
const isFleetAvailable = (0, api_1.useIsFleetAvailable)();
|
|
@@ -129,23 +96,20 @@ function useGetInitialResult() {
|
|
|
129
96
|
return store.getResult(requestPath);
|
|
130
97
|
}
|
|
131
98
|
}
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
const isProbablyFleetQuery = !!resource?.cluster && resource?.cluster !== hubClusterName;
|
|
99
|
+
const waitingForHubClusterName = !!(resource === null || resource === void 0 ? void 0 : resource.cluster) && !hubClusterNameLoaded;
|
|
100
|
+
const isProbablyFleetQuery = !!(resource === null || resource === void 0 ? void 0 : resource.cluster) && (resource === null || resource === void 0 ? void 0 : resource.cluster) !== hubClusterName;
|
|
135
101
|
let loadError = undefined;
|
|
136
102
|
if (waitingForHubClusterName) {
|
|
137
|
-
// if we are still waiting for hub name to load, we should return any error fetching the hub name
|
|
138
103
|
loadError = hubClusterNameLoadedError;
|
|
139
104
|
}
|
|
140
105
|
else if (isProbablyFleetQuery && !isFleetAvailable) {
|
|
141
|
-
// if we need to use fleet support but it it not available, we return an error
|
|
142
106
|
loadError = constants_1.NO_FLEET_AVAILABLE_ERROR;
|
|
143
107
|
}
|
|
144
108
|
return { data: getDefaultData(resource), loaded: false, loadError };
|
|
145
109
|
}, [isFleetAvailable, hubClusterName, hubClusterNameLoaded, hubClusterNameLoadedError]);
|
|
146
110
|
}
|
|
147
111
|
const subscribe = (resource, requestPath, setResult) => {
|
|
148
|
-
return fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.subscribe((state) => state.cache[requestPath]
|
|
112
|
+
return fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.subscribe((state) => { var _a; return (_a = state.cache[requestPath]) === null || _a === void 0 ? void 0 : _a.result; }, (result) => {
|
|
149
113
|
if (result) {
|
|
150
114
|
setResult(result);
|
|
151
115
|
}
|
|
@@ -155,21 +119,19 @@ const subscribe = (resource, requestPath, setResult) => {
|
|
|
155
119
|
});
|
|
156
120
|
};
|
|
157
121
|
exports.subscribe = subscribe;
|
|
158
|
-
const startWatch =
|
|
122
|
+
const startWatch = (resource, model, basePath, pollInterval) => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
const intervalSeconds = Math.max(pollInterval !== null && pollInterval !== void 0 ? pollInterval : DEFAULT_POLL_INTERVAL_SECONDS, MIN_POLL_INTERVAL_SECONDS);
|
|
124
|
+
const effectiveInterval = intervalSeconds * 1000;
|
|
159
125
|
const requestPath = (0, exports.getRequestPathFromResource)(resource, model, basePath);
|
|
160
126
|
const store = fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.getState();
|
|
161
127
|
store.incrementRefCount(requestPath);
|
|
162
|
-
// if we are the first subscriber, we are responsible for getting the initial data and watching for updates
|
|
163
128
|
if (store.getRefCount(requestPath) === 1) {
|
|
164
|
-
// if there is a cached value that is not expired, we can skip the initial fetch
|
|
165
129
|
const entry = store.cache[requestPath];
|
|
166
|
-
if ((entry && (0, fleetK8sWatchResourceStore_1.isCacheEntryValid)(entry)) || (
|
|
167
|
-
|
|
168
|
-
openFleetWatchSocket(requestPath, resource, model, basePath);
|
|
130
|
+
if ((entry && (0, fleetK8sWatchResourceStore_1.isCacheEntryValid)(entry)) || (yield loadInitialData(requestPath, resource))) {
|
|
131
|
+
startPolling(requestPath, resource, effectiveInterval);
|
|
169
132
|
}
|
|
170
|
-
monitorFleetWatchSocket(requestPath, resource, model, basePath);
|
|
171
133
|
}
|
|
172
|
-
};
|
|
134
|
+
});
|
|
173
135
|
exports.startWatch = startWatch;
|
|
174
136
|
const stopWatch = (resource, model, basePath) => {
|
|
175
137
|
const requestPath = (0, exports.getRequestPathFromResource)(resource, model, basePath);
|
|
@@ -177,58 +139,4 @@ const stopWatch = (resource, model, basePath) => {
|
|
|
177
139
|
store.decrementRefCount(requestPath);
|
|
178
140
|
};
|
|
179
141
|
exports.stopWatch = stopWatch;
|
|
180
|
-
const handleWebsocketEvent = (event, requestPath, isList, cluster) => {
|
|
181
|
-
if (!event) {
|
|
182
|
-
console.warn('Received undefined event', event);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const eventDataParsed = JSON.parse(event.data);
|
|
186
|
-
const eventType = eventDataParsed?.type;
|
|
187
|
-
const object = eventDataParsed?.object;
|
|
188
|
-
if (!object)
|
|
189
|
-
return;
|
|
190
|
-
const store = fleetK8sWatchResourceStore_1.useFleetK8sWatchResourceStore.getState();
|
|
191
|
-
if (!isList) {
|
|
192
|
-
const currentEntry = store.getResult(requestPath);
|
|
193
|
-
if (eventType === 'ADDED' && currentEntry?.data)
|
|
194
|
-
return;
|
|
195
|
-
const processedEventData = { cluster, ...object };
|
|
196
|
-
if (processedEventData) {
|
|
197
|
-
// Update the store with the new data - this will notify all subscribers
|
|
198
|
-
store.setResult(requestPath, processedEventData, true);
|
|
199
|
-
}
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const currentEntry = store.getResult(requestPath);
|
|
203
|
-
const storedData = currentEntry?.data;
|
|
204
|
-
if (!storedData) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (eventType === 'DELETED') {
|
|
208
|
-
const updatedData = storedData.filter((i) => i.metadata?.uid !== object?.metadata?.uid);
|
|
209
|
-
store.setResult(requestPath, updatedData, true);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (eventType === 'BOOKMARK') {
|
|
213
|
-
store.setResult(requestPath, storedData, true, undefined, object?.metadata?.resourceVersion);
|
|
214
|
-
}
|
|
215
|
-
if (eventType !== 'ADDED' && eventType !== 'MODIFIED') {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
if (!object?.metadata?.uid) {
|
|
219
|
-
console.warn('Event object does not have a metadata.uid', eventDataParsed);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const objectExists = storedData.some((i) => i.metadata?.uid === object?.metadata?.uid);
|
|
223
|
-
if (objectExists && eventType === 'MODIFIED') {
|
|
224
|
-
const updatedData = storedData.map((i) => (i.metadata?.uid === object?.metadata?.uid ? { cluster, ...object } : i));
|
|
225
|
-
store.setResult(requestPath, updatedData, true);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (!objectExists) {
|
|
229
|
-
const updatedData = [...storedData, { cluster, ...object }];
|
|
230
|
-
store.setResult(requestPath, updatedData, true);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
exports.handleWebsocketEvent = handleWebsocketEvent;
|
|
234
142
|
//# sourceMappingURL=fleetK8sWatchResource.js.map
|