Obtain bundle and resource statuses from GitRepo status

This commit is contained in:
Alejandro Ruiz 2024-12-17 10:25:37 +01:00
parent 1b9d95f3cc
commit 69a89d81d7
1 changed files with 25 additions and 0 deletions

View File

@ -20,6 +20,21 @@ function quacksLikeAHash(str) {
return false;
}
function normalizeStateCounts(data) {
if (!data || data === {}) {
return {
total: 0,
states: {},
};
}
const { desiredReady, ...rest } = data ;
return {
total: desiredReady,
states: rest,
};
}
export default class GitRepo extends SteveModel {
applyDefaults() {
const spec = this.spec || {};
@ -325,6 +340,16 @@ export default class GitRepo extends SteveModel {
return bds.filter((bd) => bd.metadata?.labels?.['fleet.cattle.io/repo-name'] === this.name);
}
get allBundlesStatuses() {
const { nonReadyResources, ...bundlesSummary } = this.status?.summary || {};
return normalizeStateCounts(bundlesSummary);
}
get allResourceStatuses() {
return normalizeStateCounts(this.status?.resourceCounts || {});
}
statusResourceCountsForCluster(clusterId) {
if (!this.targetClusters.some((c) => c.id === clusterId)) {
return {};