feat: support adding VM display name in creation page (#912)

* feat: add VM display name annotation support in edit and list views

Signed-off-by: Andy Lee <andy.lee@suse.com>

* refactor: add display name checkbox and input field

Signed-off-by: Andy Lee <andy.lee@suse.com>

---------

Signed-off-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
Andy Lee 2026-06-05 12:11:07 +08:00 committed by GitHub
parent ae65037083
commit ce2adbdc3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 65 additions and 8 deletions

View File

@ -19,6 +19,7 @@ export const HCI = {
NETWORK_TYPE: 'network.harvesterhci.io/type', NETWORK_TYPE: 'network.harvesterhci.io/type',
VM_NAME: 'harvesterhci.io/vmName', VM_NAME: 'harvesterhci.io/vmName',
VM_NAME_PREFIX: 'harvesterhci.io/vmNamePrefix', VM_NAME_PREFIX: 'harvesterhci.io/vmNamePrefix',
VM_DISPLAY_NAME: 'harvesterhci.io/vmDisplayName',
VM_RESERVED_MEMORY: 'harvesterhci.io/reservedMemory', VM_RESERVED_MEMORY: 'harvesterhci.io/reservedMemory',
MAINTENANCE_STATUS: 'harvesterhci.io/maintain-status', MAINTENANCE_STATUS: 'harvesterhci.io/maintain-status',
HOST_CUSTOM_NAME: 'harvesterhci.io/host-custom-name', HOST_CUSTOM_NAME: 'harvesterhci.io/host-custom-name',

View File

@ -93,22 +93,36 @@ export default {
const hostname = this.value.spec.template.spec.hostname || ''; const hostname = this.value.spec.template.spec.hostname || '';
const customizeDisplayName = !!(this.value.metadata?.annotations?.[HCI_ANNOTATIONS.VM_DISPLAY_NAME]);
return { return {
cloneVM, cloneVM,
count: 2, count: 2,
templateId: '', templateId: '',
templateVersionId: '', templateVersionId: '',
namePrefix: '', namePrefix: '',
isSingle: true, isSingle: true,
isOpen: false, isOpen: false,
hostname, hostname,
isRestartImmediately, isRestartImmediately,
customizeDisplayName,
}; };
}, },
computed: { computed: {
...mapGetters({ t: 'i18n/t' }), ...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() { to() {
return { return {
name: 'harvester-c-cluster-resource', name: 'harvester-c-cluster-resource',
@ -294,6 +308,12 @@ export default {
this.getInitConfig({ value: this.value, init: this.isCreate }); this.getInitConfig({ value: this.value, init: this.isCreate });
} }
}, },
customizeDisplayName(neu) {
if (!neu) {
this.value.setAnnotation(HCI_ANNOTATIONS.VM_DISPLAY_NAME, '');
}
},
}, },
created() { created() {
@ -616,6 +636,33 @@ export default {
</template> </template>
</NameNsDescription> </NameNsDescription>
<div v-if="isSingle">
<div class="row mb-20">
<div class="col span-12">
<Checkbox
v-model:value="customizeDisplayName"
class="check"
type="checkbox"
:label="t('harvester.virtualMachine.input.customizeDisplayName')"
:mode="mode"
/>
</div>
</div>
<div
v-if="customizeDisplayName"
class="row mb-20"
>
<div class="col span-6">
<LabeledInput
v-model:value="displayName"
:mode="mode"
:label="t('harvester.virtualMachine.input.displayName')"
:placeholder="t('harvester.virtualMachine.input.displayNamePlaceholder')"
/>
</div>
</div>
</div>
<Checkbox <Checkbox
v-if="isCreate" v-if="isCreate"
v-model:value="useTemplate" v-model:value="useTemplate"

View File

@ -818,6 +818,9 @@ harvester:
username: Username username: Username
password: Password password: Password
reservedMemory: Reserved Memory reservedMemory: Reserved Memory
customizeDisplayName: Customize virtual machine display name
displayNamePlaceholder: Virtual machine alias name
displayName: Display Name
filesystem: filesystem:
description: Harvester supports filesystem volumes for VM via virtiofs. description: Harvester supports filesystem volumes for VM via virtiofs.
type: Filesystem Type type: Filesystem Type

View File

@ -22,6 +22,8 @@ export const VM_HEADERS = [
{ {
...NAME, ...NAME,
width: 350, width: 350,
value: 'nameDisplay',
sort: ['nameDisplay'],
}, },
NAMESPACE, NAMESPACE,
{ {
@ -244,7 +246,7 @@ export default {
v-if="scope.row.type !== HCI.VMI" v-if="scope.row.type !== HCI.VMI"
:to="scope.row.detailLocation" :to="scope.row.detailLocation"
> >
{{ scope.row.metadata.name }} {{ scope.row.nameDisplay }}
<i <i
v-if="scope.row.encryptedVolumeType !== 'none'" v-if="scope.row.encryptedVolumeType !== 'none'"
v-tooltip="lockIconTooltipMessage(scope.row)" v-tooltip="lockIconTooltipMessage(scope.row)"
@ -253,7 +255,7 @@ export default {
/> />
</router-link> </router-link>
<span v-else> <span v-else>
{{ scope.row.metadata.name }} {{ scope.row.nameDisplay }}
</span> </span>
<ConsoleBar <ConsoleBar
:resource-type="scope.row" :resource-type="scope.row"

View File

@ -1274,6 +1274,10 @@ export default class VirtVm extends HarvesterResource {
return this.$rootGetters['harvester-common/getFeatureEnabled']('schedulingVMBackup'); return this.$rootGetters['harvester-common/getFeatureEnabled']('schedulingVMBackup');
} }
get nameDisplay() {
return this.metadata?.annotations?.[HCI_ANNOTATIONS.VM_DISPLAY_NAME] || this.metadata?.name || this.id;
}
get volumeEncryptionFeatureEnabled() { get volumeEncryptionFeatureEnabled() {
return this.$rootGetters['harvester-common/getFeatureEnabled']('volumeEncryption'); return this.$rootGetters['harvester-common/getFeatureEnabled']('volumeEncryption');
} }