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 61b06b9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
3 changes: 1 addition & 2 deletions pkg/harvester/config/harvester.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
CONFIGURED_PROVIDERS,
SUB_TYPE,
ADDRESS,
NS_SNAPSHOT_QUOTA
} from '@shell/config/table-headers';

import {
Expand Down Expand Up @@ -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',
Expand Down
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
17 changes: 16 additions & 1 deletion shell/list/namespace.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
import { mapGetters } from 'vuex';
import { NS_SNAPSHOT_QUOTA } from '../config/table-headers';
import ResourceTable from '@shell/components/ResourceTable';
import { HCI } from '@shell/config/types';
export default {
name: 'ListNamespace',
components: { ResourceTable },
Expand Down Expand Up @@ -30,7 +31,20 @@ export default {
computed: {
...mapGetters(['currentProduct']),
hasHarvesterResourceQuotaSchema() {
const inStore = this.$store.getters['currentProduct'].inStore;
return !!this.$store.getters[`${ inStore }/schemaFor`](HCI.RESOURCE_QUOTA);
},
headers() {
const headersFromSchema = this.$store.getters['type-map/headersFor'](this.schema);
if (this.hasHarvesterResourceQuotaSchema) {
headersFromSchema.splice(2, 0, NS_SNAPSHOT_QUOTA);
}
return headersFromSchema;
},
filterRow() {
if (this.currentProduct.hideSystemResources) {
return this.rows.filter( (N) => {
Expand All @@ -53,6 +67,7 @@ export default {
v-bind="$attrs"
:rows="filterRow"
:groupable="false"
:headers="headers"
:schema="schema"
key-field="_key"
:loading="loading"
Expand Down

0 comments on commit 61b06b9

Please sign in to comment.