Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify handling of GitRepo status resources #13244

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions shell/components/fleet/FleetResources.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import SortableTable from '@shell/components/SortableTable';
import { AGE } from '@shell/config/table-headers';

export default {
name: 'FleetResources',
Expand Down Expand Up @@ -65,7 +64,6 @@ export default {
sort: 'namespace',
label: 'Namespace',
},
{ ...AGE }
];
},
}
Expand Down
3 changes: 0 additions & 3 deletions shell/detail/fleet.cattle.io.cluster.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export default {
},

computed: {
allBundleDeployments() {
return this.value.bundleDeployments;
},
clusterId() {
return this.value.id;
},
Expand Down
11 changes: 2 additions & 9 deletions shell/detail/fleet.cattle.io.gitrepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ export default {

data() {
return {
allFleetClusters: [],
allBundles: [],
allBundleDeployments: [],
allFleetClusters: [],
allBundles: [],
};
},
computed: {
Expand Down Expand Up @@ -86,11 +85,6 @@ export default {
opt: { excludeFields: ['metadata.managedFields', 'spec.resources'] },
},

allBundleDeployments: {
inStoreType: 'management',
type: FLEET.BUNDLE_DEPLOYMENT
},

allFleetClusters: {
inStoreType: 'management',
type: FLEET.CLUSTER
Expand All @@ -101,7 +95,6 @@ export default {
}
}, this.$store);

this.allBundleDeployments = allDispatches.allBundleDeployments || [];
this.allBundles = allDispatches.allBundles || [];
this.allFleetClusters = allDispatches.allFleetClusters || [];
},
Expand Down
168 changes: 68 additions & 100 deletions shell/models/fleet.cattle.io.gitrepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,43 +330,23 @@ export default class GitRepo extends SteveModel {
}

get bundleDeployments() {
const bds = this.$getters['all'](FLEET.BUNDLE_DEPLOYMENT);

return bds.filter((bd) => bd.metadata?.labels?.['fleet.cattle.io/repo-name'] === this.name);
return this.$getters['matching'](FLEET.BUNDLE_DEPLOYMENT, { 'fleet.cattle.io/repo-name': this.name });
}

get allBundlesStatuses() {
const bundleDeploymentCountsPerBundle = this.bundleDeployments.reduce((acc, bd) => {
const bundleId = FleetUtils.bundleIdFromBundleDeploymentLabels(bd.metadata?.labels);
const state = mapStateToEnum(FleetUtils.bundleDeploymentState(bd));

if (!acc[bundleId]) {
acc[bundleId] = {
total: 0,
states: { [STATES_ENUM.READY]: 0 },
};
}
acc[bundleId].total++;

if (!acc[bundleId].states[state]) {
acc[bundleId].states[state] = 0;
}
acc[bundleId].states[state]++;

return acc;
}, {});
const bundleIds = Object.keys(bundleDeploymentCountsPerBundle);

return bundleIds.reduce((acc, bundleId) => {
const state = primaryDisplayStatusFromCount(bundleDeploymentCountsPerBundle[bundleId].states);
return this.bundles.reduce((acc, bundle) => {
const { nonReadyResources, ...summary } = bundle.status?.summary;
const bdCounts = normalizeStateCounts(summary);
const state = primaryDisplayStatusFromCount(bdCounts.states);

if (!acc.states[state]) {
acc.states[state] = 0;
}
acc.states[state]++;
acc.total++;

return acc;
}, { total: bundleIds.length, states: { [STATES_ENUM.READY]: 0 } } );
}, { total: 0, states: { [STATES_ENUM.READY]: 0 } } );
}

get allResourceStatuses() {
Expand All @@ -378,91 +358,79 @@ export default class GitRepo extends SteveModel {
return {};
}

return this.bundleDeployments
.filter((bd) => FleetUtils.clusterIdFromBundleDeploymentLabels(bd.metadata?.labels) === clusterId)
.map((bd) => FleetUtils.resourcesFromBundleDeploymentStatus(bd.status))
.flat()
.map((r) => r.state)
.reduce((prev, state) => {
if (!prev[state]) {
prev[state] = 0;
}
prev[state]++;
prev.desiredReady++;

return prev;
}, { desiredReady: 0 });
return this.status?.perClusterResourceCounts[clusterId] || { desiredReady: 0 };
}

get resourcesStatuses() {
const bundleDeployments = this.bundleDeployments || [];
if (isEmpty(this.status?.resources)) {
return [];
}

const clusters = (this.targetClusters || []).reduce((res, c) => {
res[c.id] = c;

return res;
}, {});
const resources = this.status?.resources?.reduce((acc, resourceInfo) => {
const { perClusterState, ...resource } = resourceInfo;

const out = [];

for (const bd of bundleDeployments) {
const clusterId = FleetUtils.clusterIdFromBundleDeploymentLabels(bd.metadata?.labels);
const c = clusters[clusterId];

if (!c) {
continue;
}

const resources = FleetUtils.resourcesFromBundleDeploymentStatus(bd.status);

resources.forEach((r) => {
const id = FleetUtils.resourceId(r);
const type = FleetUtils.resourceType(r);
const state = r.state;

const color = colorForState(state).replace('text-', 'bg-');
const display = stateDisplay(state);

const detailLocation = {
name: `c-cluster-product-resource${ r.namespace ? '-namespace' : '' }-id`,
params: {
product: NAME,
cluster: c.metadata.labels[FLEET_ANNOTATIONS.CLUSTER_NAME], // explorer uses the "management" Cluster name, which differs from the Fleet Cluster name
resource: type,
namespace: r.namespace,
id: r.name,
}
};

const key = `${ c.id }-${ type }-${ r.namespace }-${ r.name }`;

out.push({
key,
tableKey: key,

// Needed?
id,
type,
clusterId: c.id,

// columns, see FleetResources.vue
state: mapStateToEnum(state),
clusterName: c.nameDisplay,
apiVersion: r.apiVersion,
kind: r.kind,
name: r.name,
namespace: r.namespace,
creationTimestamp: r.createdAt,

// other properties
stateBackground: color,
stateDisplay: display,
stateSort: stateSort(color, display),
detailLocation,
Object.entries(perClusterState).forEach(([state, clusterIds]) => {
clusterIds.filter((id) => !!clusters[id]).forEach((clusterId) => {
acc.push(Object.assign({ clusterId, state }, resource));
});
});
}

return out;
return acc;
}, []);

return resources.map((r) => {
const {
namespace, name, clusterId, state
} = r;
const id = FleetUtils.resourceId(r);
const type = FleetUtils.resourceType(r);
const c = clusters[clusterId];

const color = colorForState(state).replace('text-', 'bg-');
const display = stateDisplay(state);

const detailLocation = {
name: `c-cluster-product-resource${ r.namespace ? '-namespace' : '' }-id`,
params: {
product: NAME,
cluster: c.metadata.labels[FLEET_ANNOTATIONS.CLUSTER_NAME], // explorer uses the "management" Cluster name, which differs from the Fleet Cluster name
resource: type,
namespace,
id: name,
}
};

const key = `${ clusterId }-${ type }-${ namespace }-${ name }`;

return {
key,
tableKey: key,

// Needed?
id,
type,
clusterId,

// columns, see FleetResources.vue
state: mapStateToEnum(state),
clusterName: c.nameDisplay,
apiVersion: r.apiVersion,
kind: r.kind,
name: r.name,
namespace: r.namespace,

// other properties
stateBackground: color,
stateDisplay: display,
stateSort: stateSort(color, display),
detailLocation,
};
});
}

get clusterInfo() {
Expand Down
5 changes: 0 additions & 5 deletions shell/pages/c/_cluster/fleet/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ export default {
inStoreType: 'management',
type: FLEET.CLUSTER_GROUP
},
allBundleDeployments: {
inStoreType: 'management',
type: FLEET.BUNDLE_DEPLOYMENT,
},
allBundles: {
inStoreType: 'management',
type: FLEET.BUNDLE,
opt: { excludeFields: ['metadata.managedFields', 'spec.resources'] },
skipWait: true,
},
gitRepos: {
inStoreType: 'management',
Expand Down
Loading