From 61b06b96ba35bb18d0db384ede28a6b1061c3dec Mon Sep 17 00:00:00 2001 From: "andy.lee" Date: Mon, 9 Sep 2024 11:24:37 +0800 Subject: [PATCH] check harvester resource quota schema to prevent unexpected error --- pkg/harvester/config/harvester.js | 3 +-- .../kubevirt.io.virtualmachine/index.vue | 26 ++++++++++++------- .../list/kubevirt.io.virtualmachine.vue | 13 ++++++---- .../store/harvester-store/actions.ts | 5 +++- .../components/ExplorerProjectsNamespaces.vue | 6 +++-- shell/list/namespace.vue | 17 +++++++++++- 6 files changed, 49 insertions(+), 21 deletions(-) diff --git a/pkg/harvester/config/harvester.js b/pkg/harvester/config/harvester.js index 4ba8a63aa18..000b08deb5d 100644 --- a/pkg/harvester/config/harvester.js +++ b/pkg/harvester/config/harvester.js @@ -24,7 +24,6 @@ import { CONFIGURED_PROVIDERS, SUB_TYPE, ADDRESS, - NS_SNAPSHOT_QUOTA } from '@shell/config/table-headers'; import { @@ -253,7 +252,7 @@ export function init($plugin, store) { // singleVirtualCluster if (isSingleVirtualCluster) { - headers(NAMESPACE, [STATE, NAME_UNLINKED, NS_SNAPSHOT_QUOTA, AGE]); + headers(NAMESPACE, [STATE, NAME_UNLINKED, AGE]); basicType([NAMESPACE]); virtualType({ labelKey: 'harvester.namespace.label', diff --git a/pkg/harvester/detail/kubevirt.io.virtualmachine/index.vue b/pkg/harvester/detail/kubevirt.io.virtualmachine/index.vue index 549607e4d7b..acc433cc827 100644 --- a/pkg/harvester/detail/kubevirt.io.virtualmachine/index.vue +++ b/pkg/harvester/detail/kubevirt.io.virtualmachine/index.vue @@ -59,25 +59,31 @@ export default { data() { return { - switchToCloud: false, + hasResourceQuotaSchema: false, + switchToCloud: false, VM_METRICS_DETAIL_URL, - showVmMetrics: false, + showVmMetrics: false, }; }, async created() { const inStore = this.$store.getters['currentProduct'].inStore; + this.hasResourceQuotaSchema = !!this.$store.getters[`${ inStore }/schemaFor`](HCI.RESOURCE_QUOTA); + const hash = { - pods: this.$store.dispatch(`${ inStore }/findAll`, { type: POD }), - services: this.$store.dispatch(`${ inStore }/findAll`, { type: SERVICE }), - events: this.$store.dispatch(`${ inStore }/findAll`, { type: EVENT }), - allSSHs: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.SSH }), - vmis: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VMI }), - restore: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESTORE }), - resourceQuotas: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESOURCE_QUOTA }), + pods: this.$store.dispatch(`${ inStore }/findAll`, { type: POD }), + services: this.$store.dispatch(`${ inStore }/findAll`, { type: SERVICE }), + events: this.$store.dispatch(`${ inStore }/findAll`, { type: EVENT }), + allSSHs: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.SSH }), + vmis: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VMI }), + restore: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESTORE }), }; + if (this.hasResourceQuotaSchema) { + hash.resourceQuotas = this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESOURCE_QUOTA }); + } + await allHash(hash); setPromiseResult( @@ -198,7 +204,7 @@ export default { - + } = { projects: fetchProjects(), - resourceQuota: dispatch('findAll', { type: HCI.RESOURCE_QUOTA }), virtualCount: dispatch('findAll', { type: COUNT }), virtualNamespaces: dispatch('findAll', { type: NAMESPACE }), settings: dispatch('findAll', { type: HCI.SETTING }), @@ -91,6 +90,10 @@ export default { }, { root: true }), }; + if (getters['schemaFor'](HCI.RESOURCE_QUOTA)) { + hash.resourceQuota = dispatch('findAll', { type: HCI.RESOURCE_QUOTA }); + } + if (getters['schemaFor'](HCI.UPGRADE)) { hash.upgrades = dispatch('findAll', { type: HCI.UPGRADE }); } diff --git a/shell/components/ExplorerProjectsNamespaces.vue b/shell/components/ExplorerProjectsNamespaces.vue index 49178a4851d..b5978f4b90e 100644 --- a/shell/components/ExplorerProjectsNamespaces.vue +++ b/shell/components/ExplorerProjectsNamespaces.vue @@ -3,7 +3,7 @@ import { mapGetters } from 'vuex'; import ResourceTable from '@shell/components/ResourceTable'; import { STATE, AGE, NAME, NS_SNAPSHOT_QUOTA } from '@shell/config/table-headers'; import { uniq } from '@shell/utils/array'; -import { MANAGEMENT, NAMESPACE, VIRTUAL_TYPES } from '@shell/config/types'; +import { MANAGEMENT, NAMESPACE, VIRTUAL_TYPES, HCI } from '@shell/config/types'; import { PROJECT_ID, FLAT_VIEW } from '@shell/config/query-params'; import Masthead from '@shell/components/ResourceList/Masthead'; import { mapPref, GROUP_RESOURCES, ALL_NAMESPACES, DEV } from '@shell/store/prefs'; @@ -36,6 +36,7 @@ export default { async fetch() { const inStore = this.$store.getters['currentStore'](NAMESPACE); + this.harvesterResourceQuotaSchema = this.$store.getters[`${ inStore }/schemaFor`](HCI.RESOURCE_QUOTA); this.schema = this.$store.getters[`${ inStore }/schemaFor`](NAMESPACE); this.projectSchema = this.$store.getters[`management/schemaFor`](MANAGEMENT.PROJECT); @@ -54,6 +55,7 @@ export default { return { loadResources: [NAMESPACE], loadIndeterminate: true, + harvesterResourceQuotaSchema: null, schema: null, projects: [], projectSchema: null, @@ -105,7 +107,7 @@ export default { headers.push(projectHeader); } - if (this.isHarvester) { + if (this.isHarvester && this.harvesterResourceQuotaSchema) { headers.push(NS_SNAPSHOT_QUOTA); } diff --git a/shell/list/namespace.vue b/shell/list/namespace.vue index 1bd3d37b9bc..6ad160fa108 100644 --- a/shell/list/namespace.vue +++ b/shell/list/namespace.vue @@ -1,7 +1,8 @@