fix sshkey is not added to cloud init user data immediately

Signed-off-by: andy.lee <andy.lee@suse.com>
This commit is contained in:
andy.lee 2025-02-18 16:38:29 +08:00
parent 923f36a5c3
commit e2daa1ea0c
No known key found for this signature in database
GPG Key ID: 10911689462678C7
3 changed files with 21 additions and 14 deletions

View File

@ -6,8 +6,7 @@ import { LabeledInput } from '@components/Form/LabeledInput';
import LabeledSelect from '@shell/components/form/LabeledSelect'; import LabeledSelect from '@shell/components/form/LabeledSelect';
import ModalWithCard from '@shell/components/ModalWithCard'; import ModalWithCard from '@shell/components/ModalWithCard';
import { clone } from '@shell/utils/object'; import { _VIEW, _EDIT } from '@shell/config/query-params';
import { _VIEW } from '@shell/config/query-params';
import { NAMESPACE } from '@shell/config/types'; import { NAMESPACE } from '@shell/config/types';
import { HCI } from '../../types'; import { HCI } from '../../types';
@ -91,6 +90,9 @@ export default {
}, },
sshOption() { sshOption() {
if (this.mode === _VIEW || this.mode === _EDIT) {
return [];
}
const out = this.$store.getters['harvester/all'](HCI.SSH).map( (O) => { const out = this.$store.getters['harvester/all'](HCI.SSH).map( (O) => {
return { return {
label: O.id, label: O.id,
@ -126,10 +128,9 @@ export default {
this.checkedSsh = neu; this.checkedSsh = neu;
}, },
checkedSsh(val, old) { checkedSsh(val) {
if ( val.includes(_NEW)) { // if click on Create a New...
this['checkedSsh'] = old; if (val.includes(_NEW)) {
this.update();
this.show(); this.show();
} }
} }
@ -175,6 +176,7 @@ export default {
if (res.id) { if (res.id) {
this.checkedSsh.push(`${ this.namespace }/${ this.sshName }`); this.checkedSsh.push(`${ this.namespace }/${ this.sshName }`);
this.update();
} }
}, },
@ -232,7 +234,9 @@ export default {
}, },
update() { update() {
this.$emit('update:sshKey', clone(this.checkedSsh)); const sshKeys = this.checkedSsh.filter((key) => key !== _NEW);
this.$emit('update:sshKey', sshKeys);
}, },
} }
}; };
@ -243,13 +247,13 @@ export default {
<LabeledSelect <LabeledSelect
v-model:value="checkedSsh" v-model:value="checkedSsh"
:label="t('harvester.virtualMachine.input.sshKey')" :label="t('harvester.virtualMachine.input.sshKey')"
:taggable="true" :taggable="!disabled"
:mode="mode" :mode="mode"
:multiple="true" :multiple="true"
:searchable="searchable" :searchable="searchable"
:disabled="disabled" :disabled="disabled"
:options="sshOption" :options="sshOption"
@input="update" @update:value="update"
/> />
<ModalWithCard <ModalWithCard

View File

@ -579,7 +579,7 @@ export default {
:create-namespace="true" :create-namespace="true"
:namespace="value.metadata.namespace" :namespace="value.metadata.namespace"
:mode="mode" :mode="mode"
:disabled="isWindows" :disabled="isWindows || isEdit"
@update:sshKey="updateSSHKey" @update:sshKey="updateSSHKey"
@register-after-hook="registerAfterHook" @register-after-hook="registerAfterHook"
/> />

View File

@ -900,8 +900,8 @@ export default {
}, },
/** /**
* Generate user data yaml which is decide by the "Install guest agent", * Generate user data yaml which is decided by the
* "OS type", "SSH Keys" and user input. * "Install guest agent", "OS type", "SSH keys" and user input.
* @param config * @param config
*/ */
getUserData(config) { getUserData(config) {
@ -1218,7 +1218,6 @@ export default {
let secret = this.getSecret(vm.spec); let secret = this.getSecret(vm.spec);
// const userData = this.getUserData({ osType: this.osType, installAgent: this.installAgent });
if (!secret && this.isEdit && this.secretRef) { if (!secret && this.isEdit && this.secretRef) {
// When editing the vm, if the userData and networkData are deleted, we also need to clean up the secret values // When editing the vm, if the userData and networkData are deleted, we also need to clean up the secret values
secret = this.secretRef; secret = this.secretRef;
@ -1620,9 +1619,13 @@ export default {
}, },
sshKey(neu, old) { sshKey(neu, old) {
// refresh yaml editor to get the latest userScript
this.userScript = this.getUserData({ installAgent: this.installAgent, osType: this.osType });
this.refreshYamlEditor();
const _diff = difference(old, neu); const _diff = difference(old, neu);
if (_diff.length && this.isEdit) { if (_diff.length > 0 && this.isCreate) {
this.deleteSSHFromUserData(_diff); this.deleteSSHFromUserData(_diff);
} }
} }