diff --git a/pkg/harvester/config/labels-annotations.js b/pkg/harvester/config/labels-annotations.js index 9f2f039a..df87e361 100644 --- a/pkg/harvester/config/labels-annotations.js +++ b/pkg/harvester/config/labels-annotations.js @@ -19,6 +19,7 @@ export const HCI = { NETWORK_TYPE: 'network.harvesterhci.io/type', VM_NAME: 'harvesterhci.io/vmName', VM_NAME_PREFIX: 'harvesterhci.io/vmNamePrefix', + VM_DISPLAY_NAME: 'harvesterhci.io/vmDisplayName', VM_RESERVED_MEMORY: 'harvesterhci.io/reservedMemory', MAINTENANCE_STATUS: 'harvesterhci.io/maintain-status', HOST_CUSTOM_NAME: 'harvesterhci.io/host-custom-name', diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue index f477548b..6b0dff5a 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue @@ -93,22 +93,36 @@ export default { const hostname = this.value.spec.template.spec.hostname || ''; + const customizeDisplayName = !!(this.value.metadata?.annotations?.[HCI_ANNOTATIONS.VM_DISPLAY_NAME]); + return { cloneVM, - count: 2, - templateId: '', - templateVersionId: '', - namePrefix: '', - isSingle: true, - isOpen: false, + count: 2, + templateId: '', + templateVersionId: '', + namePrefix: '', + isSingle: true, + isOpen: false, hostname, isRestartImmediately, + customizeDisplayName, }; }, computed: { ...mapGetters({ t: 'i18n/t' }), + // 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). + displayName: { + get() { + return this.value.metadata?.annotations?.[HCI_ANNOTATIONS.VM_DISPLAY_NAME] || ''; + }, + set(val) { + this.value.setAnnotation(HCI_ANNOTATIONS.VM_DISPLAY_NAME, val); + }, + }, + to() { return { name: 'harvester-c-cluster-resource', @@ -294,6 +308,12 @@ export default { this.getInitConfig({ value: this.value, init: this.isCreate }); } }, + + customizeDisplayName(neu) { + if (!neu) { + this.value.setAnnotation(HCI_ANNOTATIONS.VM_DISPLAY_NAME, ''); + } + }, }, created() { @@ -616,6 +636,33 @@ export default { +