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

Replace Fleet Cluster Nodes Ready column #11041

Merged
Merged
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
18 changes: 9 additions & 9 deletions shell/components/fleet/FleetClusters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default {
STATE,
NAME,
{
name: 'nodesReady',
labelKey: 'tableHeaders.nodesReady',
name: 'bundlesReady',
labelKey: 'tableHeaders.bundlesReady',
value: 'status.display.readyBundles',
sort: 'status.summary.ready',
search: false,
Expand All @@ -47,7 +47,7 @@ export default {
{
name: 'reposReady',
labelKey: 'tableHeaders.reposReady',
value: 'status.display.readyBundles',
value: 'status.readyGitRepos',
sort: 'status.summary.ready',
search: false,
align: 'center',
Expand Down Expand Up @@ -113,19 +113,19 @@ export default {
<span v-else>{{ row.repoInfo.total }}</span>
</template>

<template #cell:nodesReady="{row}">
<template #cell:bundlesReady="{row}">
<span
v-if="!row.nodeInfo"
v-if="row.bundleInfo.noValidData"
class="text-muted"
>&mdash;</span>
<span
v-else-if="row.nodeInfo.unready"
v-else-if="row.bundleInfo.ready !== row.bundleInfo.total"
class="text-warning"
>{{ row.nodeInfo.ready }}/{{ row.nodeInfo.total }}</span>
>{{ row.bundleInfo.ready }}/{{ row.bundleInfo.total }}</span>
<span
v-else
:class="{'text-error': !row.nodeInfo.total}"
>{{ row.nodeInfo.total }}</span>
:class="{'text-error': !row.bundleInfo.total}"
>{{ row.bundleInfo.total }}</span>
</template>
</ResourceTable>
</template>
36 changes: 36 additions & 0 deletions shell/models/__tests__/fleet.cattle.io.cluster.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import FleetCluster from '@shell/models/fleet.cattle.io.cluster';

describe('class FleetCluster', () => {
it('should provide bundleInfo if correct data is present', () => {
const fleetCluster = new FleetCluster({
metadata: {},
spec: {},
status: { display: { readyBundles: '0/1' } },
});

expect(fleetCluster.bundleInfo.ready).toBe(0);
expect(fleetCluster.bundleInfo.total).toBe(1);
expect(Object.getOwnPropertyNames(fleetCluster.bundleInfo)).not.toContain('noValidData');
});
describe('should provide bundleInfo with error', () => {
it.each([
[''],
['/'],
['1/'],
['/1'],
['1/1/2'],
['a/1'],
['a/b'],
['any-string'],
['any-string1/string2']
])('with multiple scenarios of wrongful "readyBundles" data', (readyBundles) => {
const fleetCluster = new FleetCluster({
metadata: {},
spec: {},
status: { display: { readyBundles } },
});

expect(Object.getOwnPropertyNames(fleetCluster.bundleInfo)).toContain('noValidData');
});
});
});
34 changes: 23 additions & 11 deletions shell/models/fleet.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,6 @@ export default class FleetCluster extends SteveModel {
return this.metadata?.state?.name || 'unknown';
}

get nodeInfo() {
const ready = this.status?.agent?.readyNodes || 0;
const unready = this.status?.agent?.nonReadyNodes || 0;

return {
ready,
unready,
total: ready + unready,
};
}

get repoInfo() {
const ready = this.status?.readyGitRepos || 0;
const total = this.status?.desiredReadyGitRepos || 0;
Expand All @@ -141,6 +130,29 @@ export default class FleetCluster extends SteveModel {
};
}

get bundleInfo() {
const bundlesData = {
ready: 0,
total: 0
};
const readyBundles = this.status?.display?.readyBundles;

if (readyBundles && readyBundles.includes('/')) {
const dataArr = readyBundles.split('/');

if (dataArr.length === 2 && parseInt(dataArr[0]) >= 0 && parseInt(dataArr[1]) >= 0) {
bundlesData.ready = parseInt(dataArr[0]);
bundlesData.total = parseInt(dataArr[1]);

return bundlesData;
}
}

bundlesData.noValidData = true;

return bundlesData;
}

get mgmt() {
const mgmt = this.$getters['byId'](MANAGEMENT.CLUSTER, this.metadata?.labels?.[FLEET_LABELS.CLUSTER_NAME]);

Expand Down
Loading