fix: create new secret on vm creation (#614) (#628)

* fix: create new secret on vm creation



* fix: ensure parseVM result is immutable



---------


(cherry picked from commit 0b37467f7637639209c27570bfe5633a41b96ac0)

Signed-off-by: Caio Torres <caio.torres@suse.com>
Co-authored-by: Caio Torres <caio.torres@suse.com>
This commit is contained in:
mergify[bot] 2025-11-27 17:42:46 +08:00 committed by GitHub
parent 4b2e92ea15
commit f391f018de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 13 deletions

View File

@ -490,6 +490,7 @@ export default {
if (this.isSingle) {
if (!this.value.spec.template.spec.hostname) {
this.value.spec.template.spec['hostname'] = this.value.metadata.name;
this.spec.template.spec['hostname'] = this.value.metadata.name;
}
}

View File

@ -273,7 +273,7 @@ export default {
needNewSecret() {
// When creating a template it is always necessary to create a new secret.
return this.isCreate ? true : this.showYaml ? false : this.resourceType === HCI.VM_VERSION;
return this.showYaml ? false : this.resourceType === HCI.VM_VERSION || this.isCreate;
},
defaultTerminationSetting() {
@ -708,17 +708,7 @@ export default {
const volumeClaimTemplates = [];
disk.forEach( (R, index) => {
const prefixName = this.value.metadata?.name || '';
let dataVolumeName = '';
if (R.source === SOURCE_TYPE.ATTACH_VOLUME) {
dataVolumeName = R.volumeName;
} else if (this.isClone || !this.hasCreateVolumes.includes(R.realName)) {
dataVolumeName = `${ prefixName }-${ R.name }-${ randomStr(5).toLowerCase() }`;
} else {
dataVolumeName = R.realName;
}
const dataVolumeName = this.parseDataVolumeName(R);
const _disk = this.parseDisk(R, index);
const _volume = this.parseVolume(R, dataVolumeName);
@ -1013,6 +1003,25 @@ export default {
this['cpuMemoryHotplugEnabled'] = cpuMemoryHotplugEnabled;
},
parseDataVolumeName(R) {
const prefixName = this.value.metadata?.name || '';
let dataVolumeName = '';
if (!R.dataVolumeName) {
if (R.source === SOURCE_TYPE.ATTACH_VOLUME) {
dataVolumeName = R.volumeName;
} else if (this.isClone || !this.hasCreateVolumes.includes(R.realName)) {
dataVolumeName = `${ prefixName }-${ R.name }-${ randomStr(5).toLowerCase() }`;
} else {
dataVolumeName = R.realName;
}
R.dataVolumeName = dataVolumeName;
}
return R.dataVolumeName;
},
parseDisk(R, index) {
const out = { name: R.name };
@ -1638,7 +1647,7 @@ export default {
secretRef: {
handler(secret) {
if (secret && this.resourceType !== HCI.BACKUP) {
if (secret && this.resourceType !== HCI.BACKUP && this.resourceType !== HCI.VM) {
this.secretName = secret?.metadata.name;
}
},