mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-08-16 04:39:15 +00:00
fix: prevent duplicated cloud-config for empty user data (#1109)
* fix: prevent duplicated cloud-config for empty user data Signed-off-by: Andy Lee <andy.lee@suse.com> * refactor: AI review Signed-off-by: Andy Lee <andy.lee@suse.com> --------- Signed-off-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
parent
ed2b6f2551
commit
fabc1cec21
@ -38,6 +38,10 @@ export const SSH_EXISTING_TYPE = {
|
||||
export default {
|
||||
methods: {
|
||||
hasCloudConfigComment(userScript) {
|
||||
if (typeof userScript === 'string' && /^\s*#cloud-config(\s|$)/.test(userScript)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check that userData contains: #cloud-config
|
||||
const userDataDoc = userScript ? YAML.parseDocument(userScript) : YAML.parseDocument({});
|
||||
const items = userDataDoc?.contents?.items || [];
|
||||
@ -52,6 +56,14 @@ export default {
|
||||
exist = true;
|
||||
}
|
||||
|
||||
if (userDataDoc?.contents?.commentBefore === 'cloud-config' || userDataDoc?.contents?.commentBefore?.includes('cloud-config\n')) {
|
||||
exist = true;
|
||||
}
|
||||
|
||||
if (userDataDoc?.contents?.comment === 'cloud-config' || userDataDoc?.contents?.comment?.includes('cloud-config\n')) {
|
||||
exist = true;
|
||||
}
|
||||
|
||||
items.map((item) => {
|
||||
const key = item.key;
|
||||
|
||||
|
||||
@ -1211,9 +1211,10 @@ export default {
|
||||
|
||||
userDataDoc = config.installAgent ? this.mergeQGA({ userDataDoc, ...config }) : this.deleteQGA({ userDataDoc, ...config });
|
||||
const userDataYaml = userDataDoc.toString();
|
||||
const userDataValue = userDataDoc.toJSON();
|
||||
|
||||
if (userDataYaml === '{}\n') {
|
||||
// When the YAML parsed value is '{}\n', it means that the userData is empty, then undefined is returned.
|
||||
if (userDataValue === null || (typeof userDataValue === 'object' && !Array.isArray(userDataValue) && isEmpty(userDataValue))) {
|
||||
// Empty userData should not create cloud-init content like `null`.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user