Implement Machine Pool Yaml Validation

Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
Francesco Torchia 2024-01-02 12:12:34 +01:00
parent ab6cdfa482
commit f65c4ce2c9
No known key found for this signature in database
GPG Key ID: E6D011B7415D4393
1 changed files with 40 additions and 31 deletions

View File

@ -1141,8 +1141,14 @@ export default {
title: this.t('cluster.rke2.modal.editYamlMachinePool.title'),
body: this.t('cluster.rke2.modal.editYamlMachinePool.body'),
applyMode: 'editAndContinue',
confirm: (confirmed) => {
confirm: async(confirmed) => {
if (confirmed) {
await this.validateMachinePool();
if (this.errors.length) {
reject(new Error('Machine Pool validation errors'));
}
resolve();
} else {
reject(new Error('User Cancelled'));
@ -1290,10 +1296,6 @@ export default {
// We cannot use the hook, because it is triggered on YAML toggle without restore initialized data
this.agentConfigurationCleanup();
if ( this.errors ) {
clear(this.errors);
}
const isEditVersion = this.isEdit && this.liveValue?.spec?.kubernetesVersion !== this.value?.spec?.kubernetesVersion;
if (isEditVersion) {
@ -1304,31 +1306,7 @@ export default {
}
}
if (this.value.cloudProvider === 'aws') {
const missingProfileName = this.machinePools.some((mp) => !mp.config.iamInstanceProfile);
if (missingProfileName) {
this.errors.push(this.t('cluster.validation.iamInstanceProfileName', {}, true));
}
}
for (const [index] of this.machinePools.entries()) { // validator machine config
if ( typeof this.$refs.pool[index]?.test === 'function' ) {
try {
const res = await this.$refs.pool[index].test();
if (Array.isArray(res) && res.length > 0) {
this.errors.push(...res);
}
} catch (e) {
this.errors.push(e);
}
}
}
if (!this.value.metadata.name && this.agentConfig['cloud-provider-name'] === HARVESTER) {
this.errors.push(this.t('validation.required', { key: this.t('cluster.name.label') }, true));
}
await this.validateMachinePool();
if (this.errors.length) {
btnCb(false);
@ -1995,8 +1973,39 @@ export default {
},
handleRegistrySecretChanged(neu) {
this.registrySecret = neu;
}
},
async validateMachinePool() {
if (this.errors) {
clear(this.errors);
}
if (this.value.cloudProvider === 'aws') {
const missingProfileName = this.machinePools.some((mp) => !mp.config.iamInstanceProfile);
if (missingProfileName) {
this.errors.push(this.t('cluster.validation.iamInstanceProfileName', {}, true));
}
}
for (const [index] of this.machinePools.entries()) { // validator machine config
if ( typeof this.$refs.pool[index]?.test === 'function' ) {
try {
const res = await this.$refs.pool[index].test();
if (Array.isArray(res) && res.length > 0) {
this.errors.push(...res);
}
} catch (e) {
this.errors.push(e);
}
}
}
if (!this.value.metadata.name && this.agentConfig['cloud-provider-name'] === HARVESTER) {
this.errors.push(this.t('validation.required', { key: this.t('cluster.name.label') }, true));
}
}
}
};
</script>