Skip to content

Commit

Permalink
check harvester resource quota schema to prevent unexpected error
Browse files Browse the repository at this point in the history
  • Loading branch information
a110605 committed Sep 9, 2024
1 parent 810f105 commit 1e8fe1f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
26 changes: 16 additions & 10 deletions pkg/harvester/detail/kubevirt.io.virtualmachine/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -198,7 +204,7 @@ export default {
<OverviewKeypairs v-model="value" />
</Tab>
<Tab name="quotas" :label="t('harvester.tab.quotas')" :weight="3">
<Tab v-if="hasResourceQuotaSchema" name="quotas" :label="t('harvester.tab.quotas')" :weight="3">
<LabelValue
:name="t('harvester.snapshot.totalSnapshotSize')"
:value="totalSnapshotSize"
Expand Down
13 changes: 8 additions & 5 deletions pkg/harvester/list/kubevirt.io.virtualmachine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ export default {
async fetch() {
const inStore = this.$store.getters['currentProduct'].inStore;
const _hash = {
vms: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VM }),
pod: this.$store.dispatch(`${ inStore }/findAll`, { type: POD }),
restore: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESTORE }),
backups: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.BACKUP }),
resourceQuotas: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESOURCE_QUOTA }),
vms: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VM }),
pod: this.$store.dispatch(`${ inStore }/findAll`, { type: POD }),
restore: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESTORE }),
backups: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.BACKUP }),
};
if (this.$store.getters[`${ inStore }/schemaFor`](HCI.RESOURCE_QUOTA)) {
_hash.resourceQuotas = this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESOURCE_QUOTA });
}
if (this.$store.getters[`${ inStore }/schemaFor`](NODE)) {
_hash.nodes = this.$store.dispatch(`${ inStore }/findAll`, { type: NODE });
this.hasNode = true;
Expand Down
5 changes: 4 additions & 1 deletion pkg/harvester/store/harvester-store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export default {

const hash: { [key: string]: Promise<any>} = {
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 }),
Expand All @@ -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 });
}
Expand Down
6 changes: 4 additions & 2 deletions shell/components/ExplorerProjectsNamespaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -54,6 +55,7 @@ export default {
return {
loadResources: [NAMESPACE],
loadIndeterminate: true,
harvesterResourceQuotaSchema: null,
schema: null,
projects: [],
projectSchema: null,
Expand Down Expand Up @@ -105,7 +107,7 @@ export default {
headers.push(projectHeader);
}
if (this.isHarvester) {
if (this.isHarvester && this.harvesterResourceQuotaSchema) {
headers.push(NS_SNAPSHOT_QUOTA);
}
Expand Down

0 comments on commit 1e8fe1f

Please sign in to comment.