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

Check harvester resource quota schema to prevent unknown schema error #1135

Merged
merged 1 commit into from
Sep 9, 2024
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
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]);
Copy link
Collaborator Author

@a110605 a110605 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally add NS_SNAPSHOT_QUOTA header in shell/components/ExplorerProjectsNamespaces.vue and shell/list/namespace.vue

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
Loading