From e1f2fd3764025a812d228dbfad12a7bacc2a7e23 Mon Sep 17 00:00:00 2001 From: Waseem Abbas Date: Mon, 16 Dec 2024 13:01:22 +0500 Subject: [PATCH] Make `Domain` field optional when using application credentials for Openstack provider (#7044) --- .../settings/provider/openstack/component.ts | 2 +- .../provider/basic/openstack/component.ts | 18 ++++++++++++++++-- .../provider/basic/openstack/template.html | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/web/src/app/settings/admin/presets/dialog/steps/settings/provider/openstack/component.ts b/modules/web/src/app/settings/admin/presets/dialog/steps/settings/provider/openstack/component.ts index 6d457f05eb..c6daafa548 100644 --- a/modules/web/src/app/settings/admin/presets/dialog/steps/settings/provider/openstack/component.ts +++ b/modules/web/src/app/settings/admin/presets/dialog/steps/settings/provider/openstack/component.ts @@ -115,7 +115,7 @@ export class OpenstackSettingsComponent extends BaseFormValidator implements OnI private _update(): void { this._presetDialogService.preset.spec.openstack = { ...this._presetDialogService.preset.spec.openstack, - domain: this.form.get(Controls.Domain).value, + domain: this.form.get(Controls.Domain).value || null, network: this.form.get(Controls.Network).value, securityGroups: this.form.get(Controls.SecurityGroups).value, floatingIPPool: this.form.get(Controls.FloatingIPPool).value, diff --git a/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/component.ts b/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/component.ts index 914e75ffae..dd44cb461b 100644 --- a/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/component.ts +++ b/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/component.ts @@ -22,7 +22,10 @@ import { ViewChild, } from '@angular/core'; import {FormBuilder, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validators} from '@angular/forms'; -import {OpenstackCredentialsTypeService} from '@app/wizard/step/provider-settings/provider/extended/openstack/service'; +import { + CredentialsType, + OpenstackCredentialsTypeService, +} from '@app/wizard/step/provider-settings/provider/extended/openstack/service'; import {ClusterSpecService} from '@core/services/cluster-spec'; import {DatacenterService} from '@core/services/datacenter'; import {PresetsService} from '@core/services/wizard/presets'; @@ -91,7 +94,7 @@ export class OpenstackProviderBasicComponent extends BaseFormValidator implement ngOnInit(): void { this.form = this._builder.group({ - [Controls.Domain]: this._builder.control('', Validators.required), + [Controls.Domain]: this._builder.control(''), [Controls.Credentials]: this._builder.control(''), [Controls.FloatingIPPool]: this._builder.control('', Validators.required), }); @@ -139,6 +142,15 @@ export class OpenstackProviderBasicComponent extends BaseFormValidator implement .pipe(filter(_ => this._clusterSpecService.provider === NodeProvider.OPENSTACK)) .pipe(switchMap(_ => this._datacenterService.getDatacenter(this._clusterSpecService.datacenter).pipe(take(1)))) .pipe(tap(dc => (this._isFloatingPoolIPEnforced = dc?.spec.openstack.enforceFloatingIP))) + .pipe( + tap(_ => { + if (this._credentialsTypeService.credentialsType === CredentialsType.Default) { + this.form.get(Controls.Domain).setValidators(Validators.required); + } else { + this.form.get(Controls.Domain).clearValidators(); + } + }) + ) .pipe(takeUntil(this._unsubscribe)) .subscribe(_ => this.form.reset()); } @@ -150,6 +162,8 @@ export class OpenstackProviderBasicComponent extends BaseFormValidator implement isRequired(control: Controls): boolean { switch (control) { + case Controls.Domain: + return this.form.get(Controls.Domain).hasValidator(Validators.required); case Controls.FloatingIPPool: return this._isFloatingPoolIPEnforced; default: diff --git a/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/template.html b/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/template.html index 2191db0480..618a5c2fe9 100644 --- a/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/template.html +++ b/modules/web/src/app/wizard/step/provider-settings/provider/basic/openstack/template.html @@ -23,7 +23,7 @@ [formControlName]="Controls.Domain" [name]="Controls.Domain" [matAutocomplete]="autoDomain" - required> + [required]="isRequired(Controls.Domain)">