mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-11-22 16:47:34 +08:00
When Longhorn installation is deferred, vmstate-persistence StorageClass is not created. Add prerequisite guidance in the VM form:
- Disable persistent TPM and EFI options when vmstate-persistence is unavailable
- Create mode: clear selections and show banner explaining how to add
Longhorn disk or create vmstate-persistence SC manually
- Edit mode: preserve existing values, keep options disabled, show banner
- Hide banner when vmstate-persistence exists or in View mode
(cherry picked from commit b3961a3483)
Signed-off-by: pohanhuang <pohan.huang@suse.com>
Co-authored-by: Po Han Huang <pohan.huang@suse.com>
This commit is contained in:
1 parent
8ac059b2d6
commit
e7e1a937d5
3 files changed
+189
No files matched your search
@@ -1,6 +1,12 @@
|
|||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { STORAGE_CLASS } from '@shell/config/types';
|
||||||
import VM_MIXIN from '@pkg/harvester/mixins/harvester-vm';
|
import VM_MIXIN from '@pkg/harvester/mixins/harvester-vm';
|
||||||
import HarvesterEditVM from '../index.vue';
|
import HarvesterEditVM from '../index.vue';
|
||||||
|
|
||||||
|
const vmFormSource = readFileSync(resolve(__dirname, '../index.vue'), 'utf8');
|
||||||
|
const translations = readFileSync(resolve(__dirname, '../../../l10n/en-us.yaml'), 'utf8');
|
||||||
|
|
||||||
function saveWith(userScript) {
|
function saveWith(userScript) {
|
||||||
const buttonCb = jest.fn();
|
const buttonCb = jest.fn();
|
||||||
const form = {
|
const form = {
|
||||||
@@ -20,6 +26,106 @@ function saveWith(userScript) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('page: kubevirt.io.virtualmachine edit', () => {
|
describe('page: kubevirt.io.virtualmachine edit', () => {
|
||||||
|
it('shows the persistent state storage hint only when vmstate-persistence is missing', () => {
|
||||||
|
const hasVMStateStorageClass = HarvesterEditVM.computed.hasVMStateStorageClass;
|
||||||
|
const storageClasses = (storageClassNames) => ({
|
||||||
|
inStore: 'harvester',
|
||||||
|
$store: { getters: { 'harvester/all': (type) => type === STORAGE_CLASS ? storageClassNames.map((name) => ({ metadata: { name } })) : [] } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(hasVMStateStorageClass.call(storageClasses([]))).toBe(false);
|
||||||
|
expect(hasVMStateStorageClass.call(storageClasses(['vmstate-persistence']))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('waits for StorageClasses before treating vmstate-persistence as unavailable', () => {
|
||||||
|
const vmStateStorageClassUnavailable = HarvesterEditVM.computed.vmStateStorageClassUnavailable;
|
||||||
|
|
||||||
|
expect(vmStateStorageClassUnavailable.call({ hasVMStateStorageClass: false, storageClassesLoaded: false })).toBe(false);
|
||||||
|
expect(vmStateStorageClassUnavailable.call({ hasVMStateStorageClass: false, storageClassesLoaded: true })).toBe(true);
|
||||||
|
expect(vmStateStorageClassUnavailable.call({ hasVMStateStorageClass: true, storageClassesLoaded: true })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the persistent state storage banner outside view mode when vmstate-persistence is unavailable', () => {
|
||||||
|
const showPersistentStateStorageBanner = HarvesterEditVM.computed.showPersistentStateStorageBanner;
|
||||||
|
|
||||||
|
expect(showPersistentStateStorageBanner.call({ mode: 'create', vmStateStorageClassUnavailable: true })).toBe(true);
|
||||||
|
expect(showPersistentStateStorageBanner.call({ mode: 'edit', vmStateStorageClassUnavailable: true })).toBe(true);
|
||||||
|
expect(showPersistentStateStorageBanner.call({ mode: 'create', vmStateStorageClassUnavailable: false })).toBe(false);
|
||||||
|
expect(showPersistentStateStorageBanner.call({ mode: 'view', vmStateStorageClassUnavailable: true })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('blocks new persistent state without vmstate-persistence while allowing it to be turned off', () => {
|
||||||
|
const isPersistentStateControlDisabled = HarvesterEditVM.methods.isPersistentStateControlDisabled;
|
||||||
|
|
||||||
|
expect(isPersistentStateControlDisabled.call({ vmStateStorageClassUnavailable: false }, false)).toBe(false);
|
||||||
|
expect(isPersistentStateControlDisabled.call({ vmStateStorageClassUnavailable: true }, false)).toBe(true);
|
||||||
|
expect(isPersistentStateControlDisabled.call({ vmStateStorageClassUnavailable: true }, true)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('marks StorageClasses as loaded after the VM data fetch completes', async() => {
|
||||||
|
const form = { storageClassesLoaded: false };
|
||||||
|
const fetch = jest.spyOn(VM_MIXIN, 'fetch').mockImplementation().mockResolvedValue();
|
||||||
|
|
||||||
|
await HarvesterEditVM.fetch.call(form);
|
||||||
|
fetch.mockRestore();
|
||||||
|
|
||||||
|
expect(form.storageClassesLoaded).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('links persistent state guidance to Storage Classes', () => {
|
||||||
|
const toStorageClass = HarvesterEditVM.computed.toStorageClass;
|
||||||
|
|
||||||
|
expect(toStorageClass.call({ $store: { getters: { clusterId: 'c-1' } } })).toStrictEqual({
|
||||||
|
name: 'harvester-c-cluster-resource',
|
||||||
|
params: { cluster: 'c-1', resource: 'harvesterhci.io.storage' },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('describes creating the StorageClass without non-breaking spaces around guidance links', () => {
|
||||||
|
expect(translations).toContain('middle: or create the class on the');
|
||||||
|
expect(vmFormSource).not.toContain(' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears persistent state selections only for create mode without vmstate-persistence', () => {
|
||||||
|
const clearPersistentState = HarvesterEditVM.methods.clearPersistentStateWithoutStorageClass;
|
||||||
|
|
||||||
|
const createForm = {
|
||||||
|
efiPersistentStateEnabled: true,
|
||||||
|
mode: 'create',
|
||||||
|
tpmPersistentStateEnabled: true,
|
||||||
|
vmStateStorageClassUnavailable: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
clearPersistentState.call(createForm);
|
||||||
|
|
||||||
|
expect(createForm.tpmPersistentStateEnabled).toBe(false);
|
||||||
|
expect(createForm.efiPersistentStateEnabled).toBe(false);
|
||||||
|
|
||||||
|
const editForm = {
|
||||||
|
efiPersistentStateEnabled: true,
|
||||||
|
mode: 'edit',
|
||||||
|
tpmPersistentStateEnabled: true,
|
||||||
|
vmStateStorageClassUnavailable: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
clearPersistentState.call(editForm);
|
||||||
|
|
||||||
|
expect(editForm.tpmPersistentStateEnabled).toBe(true);
|
||||||
|
expect(editForm.efiPersistentStateEnabled).toBe(true);
|
||||||
|
|
||||||
|
const storageClassForm = {
|
||||||
|
efiPersistentStateEnabled: true,
|
||||||
|
mode: 'create',
|
||||||
|
tpmPersistentStateEnabled: true,
|
||||||
|
vmStateStorageClassUnavailable: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
clearPersistentState.call(storageClassForm);
|
||||||
|
|
||||||
|
expect(storageClassForm.tpmPersistentStateEnabled).toBe(true);
|
||||||
|
expect(storageClassForm.efiPersistentStateEnabled).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('should stop the save when the cloud config is invalid', () => {
|
it('should stop the save when the cloud config is invalid', () => {
|
||||||
const { form, buttonCb } = saveWith('#cloud-config\nsome words\n');
|
const { form, buttonCb } = saveWith('#cloud-config\nsome words\n');
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { clear } from '@shell/utils/array';
|
|||||||
import { saferDump } from '@shell/utils/create-yaml';
|
import { saferDump } from '@shell/utils/create-yaml';
|
||||||
import { exceptionToErrorsArray } from '@shell/utils/error';
|
import { exceptionToErrorsArray } from '@shell/utils/error';
|
||||||
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
||||||
|
import { INTERNAL_STORAGE_CLASS } from '../../config/types';
|
||||||
import { BEFORE_SAVE_HOOKS, AFTER_SAVE_HOOKS } from '@shell/mixins/child-hook';
|
import { BEFORE_SAVE_HOOKS, AFTER_SAVE_HOOKS } from '@shell/mixins/child-hook';
|
||||||
import CreateEditView from '@shell/mixins/create-edit-view';
|
import CreateEditView from '@shell/mixins/create-edit-view';
|
||||||
import { parseVolumeClaimTemplates } from '@pkg/utils/vm';
|
import { parseVolumeClaimTemplates } from '@pkg/utils/vm';
|
||||||
@@ -40,6 +41,7 @@ import Reserved from './VirtualMachineReserved';
|
|||||||
import Filesystem from './VirtualMachineFilesystem';
|
import Filesystem from './VirtualMachineFilesystem';
|
||||||
import { Banner } from '@components/Banner';
|
import { Banner } from '@components/Banner';
|
||||||
import MessageLink from '@shell/components/MessageLink';
|
import MessageLink from '@shell/components/MessageLink';
|
||||||
|
import { STORAGE_CLASS } from '@shell/config/types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'HarvesterEditVM',
|
name: 'HarvesterEditVM',
|
||||||
@@ -89,6 +91,11 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async fetch() {
|
||||||
|
await VM_MIXIN.fetch.call(this);
|
||||||
|
this.storageClassesLoaded = true;
|
||||||
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
const cloneVM = clone(this.value);
|
const cloneVM = clone(this.value);
|
||||||
const isRestartImmediately = this.value.actualState === 'Running';
|
const isRestartImmediately = this.value.actualState === 'Running';
|
||||||
@@ -111,12 +118,27 @@ export default {
|
|||||||
hostname,
|
hostname,
|
||||||
isRestartImmediately,
|
isRestartImmediately,
|
||||||
customizeDisplayName,
|
customizeDisplayName,
|
||||||
|
storageClassesLoaded: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({ t: 'i18n/t' }),
|
...mapGetters({ t: 'i18n/t' }),
|
||||||
|
|
||||||
|
hasVMStateStorageClass() {
|
||||||
|
const storageClasses = this.$store.getters[`${ this.inStore }/all`](STORAGE_CLASS) || [];
|
||||||
|
|
||||||
|
return storageClasses.some((storageClass) => storageClass.metadata?.name === INTERNAL_STORAGE_CLASS.VMSTATE_PERSISTENCE);
|
||||||
|
},
|
||||||
|
|
||||||
|
vmStateStorageClassUnavailable() {
|
||||||
|
return this.storageClassesLoaded && !this.hasVMStateStorageClass;
|
||||||
|
},
|
||||||
|
|
||||||
|
showPersistentStateStorageBanner() {
|
||||||
|
return this.mode !== 'view' && this.vmStateStorageClassUnavailable;
|
||||||
|
},
|
||||||
|
|
||||||
// VM display name is stored as an annotation; bind a dedicated input to it
|
// VM display name is stored as an annotation; bind a dedicated input to it
|
||||||
// so we don't have to mutate metadata.name (which would break the k8s PUT).
|
// so we don't have to mutate metadata.name (which would break the k8s PUT).
|
||||||
displayName: {
|
displayName: {
|
||||||
@@ -135,6 +157,13 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toStorageClass() {
|
||||||
|
return {
|
||||||
|
name: 'harvester-c-cluster-resource',
|
||||||
|
params: { cluster: this.$store.getters['clusterId'], resource: HCI.STORAGE },
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
machineTypeOptions() {
|
machineTypeOptions() {
|
||||||
return this.machineTypes.map((type) => {
|
return this.machineTypes.map((type) => {
|
||||||
if (!type) return { label: 'None', value: '' };
|
if (!type) return { label: 'None', value: '' };
|
||||||
@@ -245,6 +274,25 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
hasVMStateStorageClass: {
|
||||||
|
handler() {
|
||||||
|
this.clearPersistentStateWithoutStorageClass();
|
||||||
|
},
|
||||||
|
immediate: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
storageClassesLoaded() {
|
||||||
|
this.clearPersistentStateWithoutStorageClass();
|
||||||
|
},
|
||||||
|
|
||||||
|
tpmPersistentStateEnabled() {
|
||||||
|
this.clearPersistentStateWithoutStorageClass();
|
||||||
|
},
|
||||||
|
|
||||||
|
efiPersistentStateEnabled() {
|
||||||
|
this.clearPersistentStateWithoutStorageClass();
|
||||||
|
},
|
||||||
|
|
||||||
templateId: {
|
templateId: {
|
||||||
async handler(id, old) {
|
async handler(id, old) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -367,6 +415,17 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
isPersistentStateControlDisabled(persistentStateEnabled) {
|
||||||
|
return this.vmStateStorageClassUnavailable && !persistentStateEnabled;
|
||||||
|
},
|
||||||
|
|
||||||
|
clearPersistentStateWithoutStorageClass() {
|
||||||
|
if (this.mode === 'create' && this.vmStateStorageClassUnavailable) {
|
||||||
|
this.tpmPersistentStateEnabled = false;
|
||||||
|
this.efiPersistentStateEnabled = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
cancelAction() {
|
cancelAction() {
|
||||||
const { fromPage = HCI.VM } = this.$route?.query; // default back to VM list page
|
const { fromPage = HCI.VM } = this.$route?.query; // default back to VM list page
|
||||||
const cancelOverride = {
|
const cancelOverride = {
|
||||||
@@ -807,6 +866,7 @@ export default {
|
|||||||
<Checkbox
|
<Checkbox
|
||||||
v-if="value.tpmPersistentStateFeatureEnabled && tpmEnabled"
|
v-if="value.tpmPersistentStateFeatureEnabled && tpmEnabled"
|
||||||
v-model:value="tpmPersistentStateEnabled"
|
v-model:value="tpmPersistentStateEnabled"
|
||||||
|
:disabled="isPersistentStateControlDisabled(tpmPersistentStateEnabled)"
|
||||||
class="check"
|
class="check"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
:label="t('harvester.virtualMachine.systemOptions.tpmPersistentState')"
|
:label="t('harvester.virtualMachine.systemOptions.tpmPersistentState')"
|
||||||
@@ -824,6 +884,7 @@ export default {
|
|||||||
<Checkbox
|
<Checkbox
|
||||||
v-if="value.efiPersistentStateFeatureEnabled && efiEnabled"
|
v-if="value.efiPersistentStateFeatureEnabled && efiEnabled"
|
||||||
v-model:value="efiPersistentStateEnabled"
|
v-model:value="efiPersistentStateEnabled"
|
||||||
|
:disabled="isPersistentStateControlDisabled(efiPersistentStateEnabled)"
|
||||||
class="check"
|
class="check"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
:label="t('harvester.virtualMachine.systemOptions.efiPersistentState')"
|
:label="t('harvester.virtualMachine.systemOptions.efiPersistentState')"
|
||||||
@@ -840,6 +901,22 @@ export default {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Banner
|
||||||
|
v-if="showPersistentStateStorageBanner"
|
||||||
|
color="info"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
{{ t('harvester.virtualMachine.systemOptions.persistentStateStorageClassUnavailable.prefix') }}
|
||||||
|
<router-link :to="to">
|
||||||
|
{{ t('harvester.virtualMachine.systemOptions.persistentStateStorageClassUnavailable.host') }}
|
||||||
|
</router-link>
|
||||||
|
{{ t('harvester.virtualMachine.systemOptions.persistentStateStorageClassUnavailable.middle') }}
|
||||||
|
<router-link :to="toStorageClass">
|
||||||
|
{{ t('harvester.virtualMachine.systemOptions.persistentStateStorageClassUnavailable.storageClass') }}
|
||||||
|
</router-link>{{ t('harvester.virtualMachine.systemOptions.persistentStateStorageClassUnavailable.suffix') }}
|
||||||
|
</span>
|
||||||
|
</Banner>
|
||||||
|
|
||||||
<Banner
|
<Banner
|
||||||
v-if="showCpuPinningBanner"
|
v-if="showCpuPinningBanner"
|
||||||
:color="mode === 'create' ? 'info' : 'warning'"
|
:color="mode === 'create' ? 'info' : 'warning'"
|
||||||
|
|||||||
@@ -829,6 +829,12 @@ harvester:
|
|||||||
tpmPersistentState: TPM Persistent State
|
tpmPersistentState: TPM Persistent State
|
||||||
efiEnabled: Booting in EFI mode
|
efiEnabled: Booting in EFI mode
|
||||||
efiPersistentState: EFI Persistent State
|
efiPersistentState: EFI Persistent State
|
||||||
|
persistentStateStorageClassUnavailable:
|
||||||
|
prefix: Persistent TPM and EFI state require the vmstate-persistence StorageClass. Add a Longhorn disk on the
|
||||||
|
host: Hosts page
|
||||||
|
middle: or create the class on the
|
||||||
|
storageClass: Storage Classes page
|
||||||
|
suffix: .
|
||||||
secureBoot: Secure Boot
|
secureBoot: Secure Boot
|
||||||
usbTip: Provides an absolute pointer device which often helps with getting a consistent mouse cursor position in VNC.
|
usbTip: Provides an absolute pointer device which often helps with getting a consistent mouse cursor position in VNC.
|
||||||
sshTitle: Add Public SSH Key
|
sshTitle: Add Public SSH Key
|
||||||
|
|||||||
Reference in new issue
Block a user