Skip to content

Commit de77bc6

Browse files
rushk014xingzhang-suse
authored andcommitted
Feat: Registries configuration - Detail: Recent scans table
1 parent 7c2017d commit de77bc6

File tree

4 files changed

+88
-26
lines changed

4 files changed

+88
-26
lines changed

pkg/sbombastic-image-vulnerability-scanner/components/RegistryDetails.vue

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="resource-header">
66
<div class="resource-header-name-state">
77
<span class="resource-header-name">
8-
<RouterLink to="../">{{ t('imageScanner.registries.title') }}:</RouterLink>
8+
<RouterLink :to="`/c/${this.$route.params.cluster}/${ this.PRODUCT_NAME }/${ this.RESOURCE.REGISTRY }/`">{{ t('imageScanner.registries.title') }}:</RouterLink>
99
{{ $route.params.id }}
1010
</span>
1111
<RegisterStatusBadge :status="registryStatus" />
@@ -41,7 +41,7 @@
4141

4242
<script>
4343
import { BadgeState } from '@rancher/components';
44-
import { RESOURCE } from '@sbombastic-image-vulnerability-scanner/types';
44+
import { PRODUCT_NAME, RESOURCE } from '@sbombastic-image-vulnerability-scanner/types';
4545
import ResourceTable from "@shell/components/ResourceTable";
4646
import RancherMeta from './common/RancherMeta.vue';
4747
import RegisterStatusBadge from './common/RegisterStatusBadge.vue';
@@ -57,20 +57,29 @@
5757
},
5858
data() {
5959
return {
60+
PRODUCT_NAME,
61+
RESOURCE,
6062
registryStatus: null,
6163
registryMetadata: [],
6264
scanHistory: [],
6365
headers: REGISTRY_SCAN_HISTORY_TABLE
6466
}
6567
},
6668
async fetch() {
67-
await this.$store.dispatch('cluster/find', { type: RESOURCE.SCAN_JOB, id: `${this.$route.params.ns}/${this.$route.params.id}` });
68-
let scanJob = this.$store.getters['cluster/byId'](RESOURCE.SCAN_JOB, `${this.$route.params.ns}/${this.$route.params.id}`);
6969
70-
await this.$store.dispatch('cluster/find', { type: RESOURCE.REGISTRY, id: `${this.$route.params.ns}/${scanJob.spec.registry}` });
71-
let registry = this.$store.getters['cluster/byId'](RESOURCE.REGISTRY, `${this.$route.params.ns}/${scanJob.spec.registry}`);
70+
await this.$store.dispatch('cluster/find', { type: RESOURCE.REGISTRY, id: `${this.$route.params.ns}/${this.$route.params.id}` });
71+
let registry = this.$store.getters['cluster/byId'](RESOURCE.REGISTRY, `${this.$route.params.ns}/${this.$route.params.id}`);
7272
73-
this.registryStatus = (registry.status.conditions[0].type.toLowerCase() === "discovering" ? "InProgress" : registry.status.conditions[0].type).toLowerCase();
73+
74+
await this.$store.dispatch('cluster/findAll', { type: RESOURCE.SCAN_JOB });
75+
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB);
76+
77+
// filter scan jobs for the current registry
78+
scanJobs = scanJobs.filter((job) => {
79+
return job.spec.registry === registry.metadata.name;
80+
});
81+
82+
this.registryStatus = this.getRegistryStatus(registry);
7483
this.registryMetadata = [
7584
{
7685
type: 'text',
@@ -100,17 +109,29 @@
100109
value: registry.metadata.schedule || '',
101110
}
102111
];
103-
104-
this.scanHistory = scanJob.status.conditions.map((rec) => {
105-
return {
106-
status: rec.type.toLowerCase(),
107-
timestamp: rec.lastUpdateTime,
108-
progress: rec.progress || 0,
109-
imagesScanned: rec.imagesScanned || 0,
110-
imagesFound: rec.imagesFound || 0,
111-
errors: rec.errors || []
112+
113+
this.scanHistory = scanJobs.map((rec) => {
114+
rec.status.statusResult = rec.status.conditions.filter(condition => {
115+
return condition.status === "True";
116+
})[0] || {
117+
type: "Pending",
118+
lastTransitionTime: null,
112119
};
120+
rec.status['scannedImagesCount'] = this.$route.params.id === 'kw-controller' ? 1000 : 500;
121+
rec.status['imagesCount'] = 2000;
122+
return rec;
113123
});
124+
125+
console.log("Scan history:", this.scanHistory);
126+
},
127+
methods: {
128+
getRegistryStatus(registry) {
129+
if (!registry || !registry.status || !registry.status.conditions || !registry.status.conditions.length) {
130+
return null;
131+
}
132+
let status = registry.status.conditions[0].type.toLowerCase() === "discovering" ? "InProgress" : registry.status.conditions[0].type;
133+
return status.toLowerCase();
134+
},
114135
},
115136
}
116137
</script>

pkg/sbombastic-image-vulnerability-scanner/config/table-headers.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,47 @@ export const REGISTRY_SCAN_HISTORY_TABLE = [
6363
{
6464
name: "status",
6565
labelKey: "imageScanner.registries.configuration.scanTable.header.status",
66-
value: "status",
66+
value: "status.statusResult.type",
6767
formatter: "RegistryStatusCellBadge",
6868
sort: "status",
6969
},
7070
{
7171
name: "since",
7272
labelKey: "imageScanner.registries.configuration.scanTable.header.since",
73-
value: "timestamp",
73+
value: "status.statusResult.lastTransitionTime",
7474
formatter: "Date",
7575
sort: "timestamp",
7676
},
7777
{
7878
name: "progress",
7979
labelKey: "imageScanner.registries.configuration.scanTable.header.progress",
80-
value: "progress",
81-
getValue: (row: any) => row.progress.toString(),
80+
getValue: (row: any) => {
81+
let progress = Math.round(
82+
(row.status.scannedImagesCount / row.status.imagesCount) * 100
83+
);
84+
return { progress };
85+
},
8286
formatter: "ProgressCell",
8387
sort: "progress",
8488
},
8589
{
8690
name: "imagesScanned",
8791
labelKey:
8892
"imageScanner.registries.configuration.scanTable.header.imagesScanned",
89-
value: "imagesScanned",
93+
value: "status.scannedImagesCount",
9094
sort: "imagesScanned",
9195
},
9296
{
9397
name: "imagesFound",
9498
labelKey:
9599
"imageScanner.registries.configuration.scanTable.header.imagesFound",
96-
value: "imagesFound",
100+
value: "status.imagesCount",
97101
sort: "imagesFound",
98102
},
99103
{
100104
name: "errors",
101-
labelKey: "imageScanner.registries.configuration.scanTable.header.errors",
102-
value: "errors",
105+
labelKey: "imageScanner.registries.configuration.scanTable.header.error",
106+
value: "status.statusResult.message",
103107
sort: "errors",
104108
},
105109
];
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script>
2+
import CreateEditView from '@shell/mixins/create-edit-view';
3+
import RegistryDetails from '@sbombastic-image-vulnerability-scanner/components/RegistryDetails.vue';
4+
import { RESOURCE } from '@sbombastic-image-vulnerability-scanner/types';
5+
import { _CREATE } from '@shell/config/query-params';
6+
import Loading from '@shell/components/Loading';
7+
8+
export default {
9+
name: 'CruRegistry',
10+
11+
props: {
12+
mode: {
13+
type: String,
14+
default: _CREATE,
15+
},
16+
value: {
17+
type: Object,
18+
required: true,
19+
},
20+
},
21+
22+
components: { RegistryDetails, Loading },
23+
24+
mixins: [CreateEditView],
25+
26+
data() {
27+
return { resource: RESOURCE.REGISTRY };
28+
}
29+
};
30+
</script>
31+
32+
<template>
33+
<Loading v-if="$fetchState.pending" />
34+
<div v-else>
35+
{{ value | escapeHtml }}
36+
</div>
37+
</template>

pkg/sbombastic-image-vulnerability-scanner/l10n/en-us.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ imageScanner:
5858
progress: Progress
5959
imagesScanned: Images scan
6060
imagesFound: Images found
61-
errors: Error(s)
61+
error: Error
6262
messages:
6363
registryScanFailed: Registry scan failed
6464
registryScanComplete: Registry scan complete
@@ -130,4 +130,4 @@ imageScanner:
130130
ago: ago
131131

132132
typeLabel:
133-
sbombastic.rancher.io.registry: Registries configuration
133+
sbombastic.rancher.io.registry: Registries configuration

0 commit comments

Comments
 (0)